File size: 3,110 Bytes
aec3094 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | import { GlobalConfig } from '@n8n/config';
import { ActivationErrorsService } from '@/activation-errors.service';
import { CacheService } from '@/services/cache/cache.service';
import { mockInstance } from '@test/mocking';
describe('ActivationErrorsService', () => {
const globalConfig = mockInstance(GlobalConfig, {
cache: { backend: 'memory', memory: { maxSize: 3 * 1024 * 1024, ttl: 3600 * 1000 } },
});
const cacheService = new CacheService(globalConfig);
const activationErrorsService = new ActivationErrorsService(cacheService);
const firstWorkflowId = 'GSG0etbfTA2CNPDX';
const secondWorkflowId = 'k2ORscMPO66K0Jk3';
const firstErrorMsg = 'Failed to activate';
const secondErrorMsg = 'Also failed to activate';
afterEach(async () => {
await activationErrorsService.clearAll();
});
describe('register', () => {
test('should register an activation error for a workflow', async () => {
await activationErrorsService.register(firstWorkflowId, firstErrorMsg);
const activationError = await activationErrorsService.get(firstWorkflowId);
expect(activationError).toBe(firstErrorMsg);
});
});
describe('deregister', () => {
test('should deregister an activation error for a workflow', async () => {
await activationErrorsService.register(firstWorkflowId, firstErrorMsg);
await activationErrorsService.deregister(firstWorkflowId);
const activationError = await activationErrorsService.get(firstWorkflowId);
expect(activationError).toBeNull();
});
});
describe('get', () => {
test('should retrieve an activation error for a workflow', async () => {
await activationErrorsService.register(firstWorkflowId, firstErrorMsg);
const activationError = await activationErrorsService.get(firstWorkflowId);
expect(activationError).toBe(firstErrorMsg);
});
test('should return `null` if no activation error found for a workflow', async () => {
const activationError = await activationErrorsService.get(firstWorkflowId);
expect(activationError).toBeNull();
});
});
describe('getAll', () => {
test('should retrieve all activation errors', async () => {
await activationErrorsService.register(firstWorkflowId, firstErrorMsg);
await activationErrorsService.register(secondWorkflowId, secondErrorMsg);
const allActivationErrors = await activationErrorsService.getAll();
expect(allActivationErrors).toEqual({
[firstWorkflowId]: firstErrorMsg,
[secondWorkflowId]: secondErrorMsg,
});
});
test('should return an empty object if no activation errors', async () => {
const allActivationErrors = await activationErrorsService.getAll();
expect(allActivationErrors).toEqual({});
});
});
describe('clearAll()', () => {
test('should clear activation errors', async () => {
await activationErrorsService.register(firstWorkflowId, firstErrorMsg);
await activationErrorsService.register(secondWorkflowId, secondErrorMsg);
await activationErrorsService.clearAll();
const allActivationErrors = await activationErrorsService.getAll();
expect(allActivationErrors).toEqual({});
});
});
});
|