mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
test: clean up settings respository mocking
This commit is contained in:
parent
cf0a23838e
commit
a8eaf4b8af
|
@ -91,10 +91,14 @@ describe('LdapService', () => {
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
const createDefaultLdapService = (config: LdapConfig) => {
|
const mockSettingsRespositoryFindOneByOrFail = (config: LdapConfig) => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
||||||
value: JSON.stringify(config),
|
value: JSON.stringify(config),
|
||||||
} as Settings);
|
} as Settings);
|
||||||
|
};
|
||||||
|
|
||||||
|
const createDefaultLdapService = (config: LdapConfig) => {
|
||||||
|
mockSettingsRespositoryFindOneByOrFail(config);
|
||||||
|
|
||||||
return new LdapService(mockLogger(), settingsRepository, mock(), mock());
|
return new LdapService(mockLogger(), settingsRepository, mock(), mock());
|
||||||
};
|
};
|
||||||
|
@ -145,9 +149,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show logger warning if authentication method is not ldap or email', async () => {
|
it('should show logger warning if authentication method is not ldap or email', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const logger = mockLogger();
|
const logger = mockLogger();
|
||||||
|
|
||||||
|
@ -218,9 +220,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should decipher the LDAP configuration admin password', async () => {
|
it('should decipher the LDAP configuration admin password', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const cipherMock = mock<Cipher>({
|
const cipherMock = mock<Cipher>({
|
||||||
decrypt: jest.fn(),
|
decrypt: jest.fn(),
|
||||||
|
@ -235,9 +235,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the expected LDAP configuration', async () => {
|
it('should return the expected LDAP configuration', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const cipherMock = mock<Cipher>({
|
const cipherMock = mock<Cipher>({
|
||||||
decrypt: jest.fn().mockReturnValue('decryptedPassword'),
|
decrypt: jest.fn().mockReturnValue('decryptedPassword'),
|
||||||
|
@ -273,9 +271,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should encrypt the binding admin password', async () => {
|
it('should encrypt the binding admin password', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const cipherMock = mock<Cipher>({
|
const cipherMock = mock<Cipher>({
|
||||||
encrypt: jest.fn().mockReturnValue('encryptedPassword'),
|
encrypt: jest.fn().mockReturnValue('encryptedPassword'),
|
||||||
|
@ -293,9 +289,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should delete all ldap identities if login is disabled and ldap users exist', async () => {
|
it('should delete all ldap identities if login is disabled and ldap users exist', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const authIdentityRepository = mockInstance(AuthIdentityRepository, {
|
const authIdentityRepository = mockInstance(AuthIdentityRepository, {
|
||||||
find: jest.fn().mockResolvedValue([{ user: { id: 'userId' } }]),
|
find: jest.fn().mockResolvedValue([{ user: { id: 'userId' } }]),
|
||||||
|
@ -318,9 +312,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not delete ldap identities if login is disabled and there are no ldap identities', async () => {
|
it('should not delete ldap identities if login is disabled and there are no ldap identities', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const authIdentityRepository = mockInstance(AuthIdentityRepository, {
|
const authIdentityRepository = mockInstance(AuthIdentityRepository, {
|
||||||
find: jest.fn().mockResolvedValue([]),
|
find: jest.fn().mockResolvedValue([]),
|
||||||
|
@ -343,9 +335,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update the LDAP configuration in the settings repository', async () => {
|
it('should update the LDAP configuration in the settings repository', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
mockInstance(AuthIdentityRepository, {
|
mockInstance(AuthIdentityRepository, {
|
||||||
find: jest.fn().mockResolvedValue([{ user: { id: 'userId' } }]),
|
find: jest.fn().mockResolvedValue([{ user: { id: 'userId' } }]),
|
||||||
|
@ -370,9 +360,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update the LDAP login label in the config', async () => {
|
it('should update the LDAP login label in the config', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
mockInstance(AuthIdentityRepository, {
|
mockInstance(AuthIdentityRepository, {
|
||||||
find: jest.fn().mockResolvedValue([{ user: { id: 'userId' } }]),
|
find: jest.fn().mockResolvedValue([{ user: { id: 'userId' } }]),
|
||||||
|
@ -486,9 +474,7 @@ describe('LdapService', () => {
|
||||||
|
|
||||||
describe('searchWithAdminBinding()', () => {
|
describe('searchWithAdminBinding()', () => {
|
||||||
it('should bind admin client', async () => {
|
it('should bind admin client', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const cipherMock = mock<Cipher>({
|
const cipherMock = mock<Cipher>({
|
||||||
decrypt: jest.fn().mockReturnValue('decryptedPassword'),
|
decrypt: jest.fn().mockReturnValue('decryptedPassword'),
|
||||||
|
@ -511,9 +497,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call client search with expected parameters', async () => {
|
it('should call client search with expected parameters', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const cipherMock = mock<Cipher>({
|
const cipherMock = mock<Cipher>({
|
||||||
decrypt: jest.fn().mockReturnValue('decryptedPassword'),
|
decrypt: jest.fn().mockReturnValue('decryptedPassword'),
|
||||||
|
@ -545,9 +529,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call client search with expected parameters when searchPageSize is 0', async () => {
|
it('should call client search with expected parameters when searchPageSize is 0', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail({ ...ldapConfig, searchPageSize: 0 });
|
||||||
value: JSON.stringify({ ...ldapConfig, searchPageSize: 0 }),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const cipherMock = mock<Cipher>({
|
const cipherMock = mock<Cipher>({
|
||||||
decrypt: jest.fn().mockReturnValue('decryptedPassword'),
|
decrypt: jest.fn().mockReturnValue('decryptedPassword'),
|
||||||
|
@ -579,9 +561,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should unbind client after search', async () => {
|
it('should unbind client after search', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const cipherMock = mock<Cipher>({
|
const cipherMock = mock<Cipher>({
|
||||||
decrypt: jest.fn().mockReturnValue('decryptedPassword'),
|
decrypt: jest.fn().mockReturnValue('decryptedPassword'),
|
||||||
|
@ -600,9 +580,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return expected search entries', async () => {
|
it('should return expected search entries', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const cipherMock = mock<Cipher>({
|
const cipherMock = mock<Cipher>({
|
||||||
decrypt: jest.fn().mockReturnValue('decryptedPassword'),
|
decrypt: jest.fn().mockReturnValue('decryptedPassword'),
|
||||||
|
@ -719,9 +697,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit expected error if admin search fails', async () => {
|
it('should emit expected error if admin search fails', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const eventServiceMock = mock<EventService>({
|
const eventServiceMock = mock<EventService>({
|
||||||
emit: jest.fn(),
|
emit: jest.fn(),
|
||||||
|
@ -1283,9 +1259,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit expected event if synchronization is enabled', async () => {
|
it('should emit expected event if synchronization is enabled', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const eventServiceMock = mock<EventService>({
|
const eventServiceMock = mock<EventService>({
|
||||||
emit: jest.fn(),
|
emit: jest.fn(),
|
||||||
|
@ -1315,9 +1289,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit expected event if synchronization is disabled', async () => {
|
it('should emit expected event if synchronization is disabled', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const eventServiceMock = mock<EventService>({
|
const eventServiceMock = mock<EventService>({
|
||||||
emit: jest.fn(),
|
emit: jest.fn(),
|
||||||
|
@ -1348,9 +1320,7 @@ describe('LdapService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit expected event with error message if processUsers fails', async () => {
|
it('should emit expected event with error message if processUsers fails', async () => {
|
||||||
settingsRepository.findOneByOrFail.mockResolvedValueOnce({
|
mockSettingsRespositoryFindOneByOrFail(ldapConfig);
|
||||||
value: JSON.stringify(ldapConfig),
|
|
||||||
} as Settings);
|
|
||||||
|
|
||||||
const eventServiceMock = mock<EventService>({
|
const eventServiceMock = mock<EventService>({
|
||||||
emit: jest.fn(),
|
emit: jest.fn(),
|
||||||
|
|
Loading…
Reference in a new issue