mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 05:04:05 -08:00
f69ddcd796
## Review / Merge checklist - [x] PR title and summary are descriptive
41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import { mock } from 'jest-mock-extended';
|
|
import type { ICredentialTypes } from 'n8n-workflow';
|
|
import config from '@/config';
|
|
import type { TranslationRequest } from '@/controllers/translation.controller';
|
|
import {
|
|
TranslationController,
|
|
CREDENTIAL_TRANSLATIONS_DIR,
|
|
} from '@/controllers/translation.controller';
|
|
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
|
|
|
|
describe('TranslationController', () => {
|
|
const configGetSpy = jest.spyOn(config, 'getEnv');
|
|
const credentialTypes = mock<ICredentialTypes>();
|
|
const controller = new TranslationController(credentialTypes);
|
|
|
|
describe('getCredentialTranslation', () => {
|
|
it('should throw 400 on invalid credential types', async () => {
|
|
const credentialType = 'not-a-valid-credential-type';
|
|
const req = mock<TranslationRequest.Credential>({ query: { credentialType } });
|
|
credentialTypes.recognizes.calledWith(credentialType).mockReturnValue(false);
|
|
|
|
await expect(controller.getCredentialTranslation(req)).rejects.toThrowError(
|
|
new BadRequestError(`Invalid Credential type: "${credentialType}"`),
|
|
);
|
|
});
|
|
|
|
it('should return translation json on valid credential types', async () => {
|
|
const credentialType = 'credential-type';
|
|
const req = mock<TranslationRequest.Credential>({ query: { credentialType } });
|
|
configGetSpy.mockReturnValue('de');
|
|
credentialTypes.recognizes.calledWith(credentialType).mockReturnValue(true);
|
|
const response = { translation: 'string' };
|
|
jest.mock(`${CREDENTIAL_TRANSLATIONS_DIR}/de/credential-type.json`, () => response, {
|
|
virtual: true,
|
|
});
|
|
|
|
expect(await controller.getCredentialTranslation(req)).toEqual(response);
|
|
});
|
|
});
|
|
});
|