test: Add tests for Credential Types (#4078)

* test: Add tests for Credential Types
This commit is contained in:
Omar Ajoue 2022-09-12 12:53:03 +02:00 committed by GitHub
parent 69eb97999d
commit beb6c38a1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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: '',
},
};
}