From 882088e240f62043643e5938d065926fe65ed048 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Tue, 26 Nov 2024 16:47:34 +1100 Subject: [PATCH] Remove unused credentialManager class --- src/__tests__/credentialManager.test.ts | 88 ------------------------- src/components/credentialManager.ts | 83 ----------------------- 2 files changed, 171 deletions(-) delete mode 100644 src/__tests__/credentialManager.test.ts delete mode 100644 src/components/credentialManager.ts diff --git a/src/__tests__/credentialManager.test.ts b/src/__tests__/credentialManager.test.ts deleted file mode 100644 index 471ca38e..00000000 --- a/src/__tests__/credentialManager.test.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { describe, beforeEach, test, expect } from 'vitest'; - -import { - credentialManager, - type ServerCredential -} from '../components/credentialManager'; - -const serverId1 = 'f4486b851af24255b3305fe614b81f01'; -const serverConfig1: ServerCredential = { - apiKey: 'b49268e51af24255b3305fe614b81f01' -}; - -const serverId2 = 'af72hb851af24255b3305fe614b81f01'; -const serverConfig2: ServerCredential = { - apiKey: 'd4286b8119f24a55b3305fe614b81f01' -}; - -describe('getting servers from credentialManager', () => { - let credentialMgr: credentialManager; - - beforeEach(() => { - credentialMgr = new credentialManager({ - [serverId1]: serverConfig1 - }); - }); - - test('get existing server from store', () => { - expect(credentialMgr.get(serverId1)).toEqual(serverConfig1); - }); - - test('get non-existant server from store', () => { - expect(credentialMgr.get(serverId2)).toBeUndefined(); - }); -}); - -describe('updating servers in credentialManager', () => { - let credentialMgr: credentialManager; - - beforeEach(() => { - credentialMgr = new credentialManager({ - [serverId1]: serverConfig1 - }); - }); - - test('update existing server in store', () => { - expect(credentialMgr.update(serverId1, serverConfig1)).toBeTruthy(); - }); - - test('update non-existant server in store', () => { - expect(credentialMgr.update(serverId2, serverConfig2)).toBeFalsy(); - }); -}); - -describe('adding servers to credentialManager', () => { - let credentialMgr: credentialManager; - - beforeEach(() => { - credentialMgr = new credentialManager({ - [serverId1]: serverConfig1 - }); - }); - - test('add server id to store', () => { - expect(credentialMgr.add(serverId2, serverConfig2)).toBeTruthy(); - }); - - test('add existing server configuration to store', () => { - expect(credentialMgr.add(serverId1, serverConfig1)).toBeFalsy(); - }); -}); - -describe('removing server from credentialManager', () => { - let credentialMgr: credentialManager; - - beforeEach(() => { - credentialMgr = new credentialManager({ - [serverId1]: serverConfig1 - }); - }); - - test('remove existing server from store', () => { - expect(credentialMgr.remove(serverId1)).toBeTruthy(); - }); - - test('remove non-existant server from store', () => { - expect(credentialMgr.remove(serverId2)).toBeFalsy(); - }); -}); diff --git a/src/components/credentialManager.ts b/src/components/credentialManager.ts deleted file mode 100644 index 75b18042..00000000 --- a/src/components/credentialManager.ts +++ /dev/null @@ -1,83 +0,0 @@ -export interface ServerCredential { - apiKey?: string; - accessToken?: string; - serverBasePath?: string; -} - -type CredentialStore = Record; - -export class credentialManager { - /** - * Store for credentials - * @private - */ - private credentialStore: CredentialStore; - - /** - * Default constructor for credentialManager. - * @param initialStore - Existing CredentialStore to initialize private store with. - */ - constructor(initialStore: CredentialStore = {}) { - this.credentialStore = initialStore; - } - - /** - * Get credentials for the provided server ID. - * @param serverId - ID of the server the credentials belong to. - * @returns Credentials for the provided server ID. - * or undefined if the store has no server with that ID. - */ - get(serverId: string): ServerCredential | undefined { - if (serverId in this.credentialStore) { - return this.credentialStore[serverId]; - } - } - - /** - * Update credentials for the provided server ID. - * @param serverId - ID of the server to update. - * @param newCredentials - Updated Credentials. - * @returns True if the value was updated, false if it wasn't. - */ - update(serverId: string, newCredentials: ServerCredential): boolean { - if (serverId in this.credentialStore) { - this.credentialStore[serverId] = newCredentials; - - return true; - } - - return false; - } - - /** - * Add a new credential to store. Only accepts new entries. - * @param serverId - ID of the server the credentials belong to. - * @param credentials - Credentials of the server. - * @returns True if server was added, false if it wasn't. - */ - add(serverId: string, credentials: ServerCredential): boolean { - if (serverId in this.credentialStore) { - return false; - } - - this.credentialStore[serverId] = credentials; - - return true; - } - - /** - * Remove a credential from store. - * @param serverId - ID of the server the credentials belong to. - * @returns True if server was removed, false if it wasn't. - */ - remove(serverId: string): boolean { - if (serverId in this.credentialStore) { - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete - delete this.credentialStore[serverId]; - - return true; - } - - return false; - } -}