diff --git a/packages/cli/test/unit/CredentialTypes.test.ts b/packages/cli/test/unit/CredentialTypes.test.ts new file mode 100644 index 0000000000..e074504676 --- /dev/null +++ b/packages/cli/test/unit/CredentialTypes.test.ts @@ -0,0 +1,61 @@ +import { CredentialTypes } from '../../src'; +import type { ICredentialTypeData, ICredentialTypes } from 'n8n-workflow'; + +describe('ActiveExecutions', () => { + + let credentialTypes: ICredentialTypes; + + beforeEach(() => { + credentialTypes = CredentialTypes(); + }); + + test('Should start with empty credential list', () => { + expect(credentialTypes.getAll()).toEqual([]); + }); + + test('Should initialize credential types', () => { + credentialTypes.init(mockCredentialTypes()); + expect(credentialTypes.getAll()).toHaveLength(2); + }); + + test('Should return all credential types', () => { + credentialTypes.init(mockCredentialTypes()); + const mockedCredentialTypes = mockCredentialTypes(); + expect(credentialTypes.getAll()).toStrictEqual([ + mockedCredentialTypes.fakeFirstCredential.type, + mockedCredentialTypes.fakeSecondCredential.type, + ]); + }); + + test('Should throw error when calling invalid credential name', () => { + credentialTypes.init(mockCredentialTypes()); + expect(() => credentialTypes.getByName('fakeThirdCredential')).toThrowError(); + }); + + test('Should return correct credential type for valid name', () => { + credentialTypes.init(mockCredentialTypes()); + const mockedCredentialTypes = mockCredentialTypes(); + expect(credentialTypes.getByName('fakeFirstCredential')).toStrictEqual(mockedCredentialTypes.fakeFirstCredential.type); + }); +}); + +function mockCredentialTypes(): ICredentialTypeData { + return { + fakeFirstCredential: { + type: { + name: 'fakeFirstCredential', + displayName: 'Fake First Credential', + properties: [], + }, + sourcePath: '', + }, + fakeSecondCredential: { + type: { + name: 'fakeSecondCredential', + displayName: 'Fake Second Credential', + properties: [], + }, + sourcePath: '', + }, + }; +}