All files / commands delete-sparql-connection.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 1/1
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31              1x     3x           3x 1x     2x 2x   2x 2x   2x   2x    
import * as vscode from 'vscode';
import { container } from 'tsyringe';
import { ServiceToken } from '@src/services/tokens';
import { ICredentialStorageService } from '@src/services/core';
import { ISparqlConnectionService } from '@src/languages/sparql/services';
import { SparqlConnection } from '@src/languages/sparql/services/sparql-connection';
 
export const deleteSparqlConnection = {
	id: 'mentor.command.deleteSparqlConnection',
	handler: async (connection: SparqlConnection) => {
		const confirm = await vscode.window.showWarningMessage(
			'Are you sure you want to delete this SPARQL connection?',
			{ modal: true },
			'Delete'
		);
 
		if (confirm !== 'Delete') {
			return;
		}
 
		const connectionService = container.resolve<ISparqlConnectionService>(ServiceToken.SparqlConnectionService);
		const credentialService = container.resolve<ICredentialStorageService>(ServiceToken.CredentialStorageService);
 
		await connectionService.deleteConnection(connection.id);
		await connectionService.saveConfiguration();
 
		await credentialService.deleteCredential(connection.id);
 
		vscode.window.showInformationMessage('SPARQL connection deleted.');
	}
};