@friggframework/core 2.0.0-next.45 → 2.0.0-next.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -0
- package/application/commands/integration-commands.js +19 -0
- package/core/Worker.js +8 -21
- package/credential/repositories/credential-repository-mongo.js +14 -8
- package/credential/repositories/credential-repository-postgres.js +14 -8
- package/credential/repositories/credential-repository.js +3 -8
- package/database/MONGODB_TRANSACTION_FIX.md +198 -0
- package/database/adapters/lambda-invoker.js +97 -0
- package/database/config.js +11 -2
- package/database/models/WebsocketConnection.js +11 -10
- package/database/prisma.js +63 -3
- package/database/repositories/health-check-repository-mongodb.js +3 -0
- package/database/repositories/migration-status-repository-s3.js +137 -0
- package/database/use-cases/check-database-state-use-case.js +81 -0
- package/database/use-cases/check-encryption-health-use-case.js +3 -2
- package/database/use-cases/get-database-state-via-worker-use-case.js +61 -0
- package/database/use-cases/get-migration-status-use-case.js +93 -0
- package/database/use-cases/run-database-migration-use-case.js +137 -0
- package/database/use-cases/trigger-database-migration-use-case.js +157 -0
- package/database/utils/mongodb-collection-utils.js +91 -0
- package/database/utils/mongodb-schema-init.js +106 -0
- package/database/utils/prisma-runner.js +400 -0
- package/database/utils/prisma-schema-parser.js +182 -0
- package/encrypt/Cryptor.js +14 -16
- package/generated/prisma-mongodb/client.d.ts +1 -0
- package/generated/prisma-mongodb/client.js +4 -0
- package/generated/prisma-mongodb/default.d.ts +1 -0
- package/generated/prisma-mongodb/default.js +4 -0
- package/generated/prisma-mongodb/edge.d.ts +1 -0
- package/generated/prisma-mongodb/edge.js +334 -0
- package/generated/prisma-mongodb/index-browser.js +316 -0
- package/generated/prisma-mongodb/index.d.ts +22897 -0
- package/generated/prisma-mongodb/index.js +359 -0
- package/generated/prisma-mongodb/package.json +183 -0
- package/generated/prisma-mongodb/query-engine-debian-openssl-3.0.x +0 -0
- package/generated/prisma-mongodb/query-engine-rhel-openssl-3.0.x +0 -0
- package/generated/prisma-mongodb/runtime/binary.d.ts +1 -0
- package/generated/prisma-mongodb/runtime/binary.js +289 -0
- package/generated/prisma-mongodb/runtime/edge-esm.js +34 -0
- package/generated/prisma-mongodb/runtime/edge.js +34 -0
- package/generated/prisma-mongodb/runtime/index-browser.d.ts +370 -0
- package/generated/prisma-mongodb/runtime/index-browser.js +16 -0
- package/generated/prisma-mongodb/runtime/library.d.ts +3977 -0
- package/generated/prisma-mongodb/runtime/react-native.js +83 -0
- package/generated/prisma-mongodb/runtime/wasm-compiler-edge.js +84 -0
- package/generated/prisma-mongodb/runtime/wasm-engine-edge.js +36 -0
- package/generated/prisma-mongodb/schema.prisma +362 -0
- package/generated/prisma-mongodb/wasm-edge-light-loader.mjs +4 -0
- package/generated/prisma-mongodb/wasm-worker-loader.mjs +4 -0
- package/generated/prisma-mongodb/wasm.d.ts +1 -0
- package/generated/prisma-mongodb/wasm.js +341 -0
- package/generated/prisma-postgresql/client.d.ts +1 -0
- package/generated/prisma-postgresql/client.js +4 -0
- package/generated/prisma-postgresql/default.d.ts +1 -0
- package/generated/prisma-postgresql/default.js +4 -0
- package/generated/prisma-postgresql/edge.d.ts +1 -0
- package/generated/prisma-postgresql/edge.js +356 -0
- package/generated/prisma-postgresql/index-browser.js +338 -0
- package/generated/prisma-postgresql/index.d.ts +25071 -0
- package/generated/prisma-postgresql/index.js +381 -0
- package/generated/prisma-postgresql/package.json +183 -0
- package/generated/prisma-postgresql/query-engine-debian-openssl-3.0.x +0 -0
- package/generated/prisma-postgresql/query-engine-rhel-openssl-3.0.x +0 -0
- package/generated/prisma-postgresql/query_engine_bg.js +2 -0
- package/generated/prisma-postgresql/query_engine_bg.wasm +0 -0
- package/generated/prisma-postgresql/runtime/binary.d.ts +1 -0
- package/generated/prisma-postgresql/runtime/binary.js +289 -0
- package/generated/prisma-postgresql/runtime/edge-esm.js +34 -0
- package/generated/prisma-postgresql/runtime/edge.js +34 -0
- package/generated/prisma-postgresql/runtime/index-browser.d.ts +370 -0
- package/generated/prisma-postgresql/runtime/index-browser.js +16 -0
- package/generated/prisma-postgresql/runtime/library.d.ts +3977 -0
- package/generated/prisma-postgresql/runtime/react-native.js +83 -0
- package/generated/prisma-postgresql/runtime/wasm-compiler-edge.js +84 -0
- package/generated/prisma-postgresql/runtime/wasm-engine-edge.js +36 -0
- package/generated/prisma-postgresql/schema.prisma +345 -0
- package/generated/prisma-postgresql/wasm-edge-light-loader.mjs +4 -0
- package/generated/prisma-postgresql/wasm-worker-loader.mjs +4 -0
- package/generated/prisma-postgresql/wasm.d.ts +1 -0
- package/generated/prisma-postgresql/wasm.js +363 -0
- package/handlers/database-migration-handler.js +227 -0
- package/handlers/routers/auth.js +1 -1
- package/handlers/routers/db-migration.handler.js +29 -0
- package/handlers/routers/db-migration.js +256 -0
- package/handlers/routers/health.js +41 -6
- package/handlers/routers/integration-webhook-routers.js +2 -2
- package/handlers/use-cases/check-integrations-health-use-case.js +22 -10
- package/handlers/workers/db-migration.js +352 -0
- package/index.js +12 -0
- package/integrations/integration-router.js +60 -70
- package/integrations/repositories/integration-repository-interface.js +12 -0
- package/integrations/repositories/integration-repository-mongo.js +32 -0
- package/integrations/repositories/integration-repository-postgres.js +33 -0
- package/integrations/repositories/process-repository-postgres.js +2 -2
- package/integrations/tests/doubles/test-integration-repository.js +2 -2
- package/logs/logger.js +0 -4
- package/modules/entity.js +0 -1
- package/modules/repositories/module-repository-mongo.js +3 -12
- package/modules/repositories/module-repository-postgres.js +0 -11
- package/modules/repositories/module-repository.js +1 -12
- package/modules/use-cases/get-entity-options-by-id.js +1 -1
- package/modules/use-cases/get-module.js +1 -2
- package/modules/use-cases/refresh-entity-options.js +1 -1
- package/modules/use-cases/test-module-auth.js +1 -1
- package/package.json +82 -66
- package/prisma-mongodb/schema.prisma +21 -21
- package/prisma-postgresql/schema.prisma +15 -15
- package/queues/queuer-util.js +24 -21
- package/types/core/index.d.ts +2 -2
- package/types/module-plugin/index.d.ts +0 -2
- package/user/use-cases/authenticate-user.js +127 -0
- package/user/use-cases/authenticate-with-shared-secret.js +48 -0
- package/user/use-cases/get-user-from-adopter-jwt.js +149 -0
- package/user/use-cases/get-user-from-x-frigg-headers.js +106 -0
- package/user/user.js +16 -0
- package/websocket/repositories/websocket-connection-repository-mongo.js +11 -10
- package/websocket/repositories/websocket-connection-repository-postgres.js +11 -10
- package/websocket/repositories/websocket-connection-repository.js +11 -10
- package/application/commands/integration-commands.test.js +0 -123
- package/database/encryption/encryption-integration.test.js +0 -553
- package/database/encryption/encryption-schema-registry.test.js +0 -392
- package/database/encryption/field-encryption-service.test.js +0 -525
- package/database/encryption/mongo-decryption-fix-verification.test.js +0 -348
- package/database/encryption/postgres-decryption-fix-verification.test.js +0 -371
- package/database/encryption/postgres-relation-decryption.test.js +0 -245
- package/database/encryption/prisma-encryption-extension.test.js +0 -439
- package/errors/base-error.test.js +0 -32
- package/errors/fetch-error.test.js +0 -79
- package/errors/halt-error.test.js +0 -11
- package/errors/validation-errors.test.js +0 -120
- package/handlers/auth-flow.integration.test.js +0 -147
- package/handlers/integration-event-dispatcher.test.js +0 -209
- package/handlers/routers/health.test.js +0 -210
- package/handlers/routers/integration-webhook-routers.test.js +0 -126
- package/handlers/webhook-flow.integration.test.js +0 -356
- package/handlers/workers/integration-defined-workers.test.js +0 -184
- package/integrations/tests/use-cases/create-integration.test.js +0 -131
- package/integrations/tests/use-cases/delete-integration-for-user.test.js +0 -150
- package/integrations/tests/use-cases/find-integration-context-by-external-entity-id.test.js +0 -92
- package/integrations/tests/use-cases/get-integration-for-user.test.js +0 -150
- package/integrations/tests/use-cases/get-integration-instance.test.js +0 -176
- package/integrations/tests/use-cases/get-integrations-for-user.test.js +0 -176
- package/integrations/tests/use-cases/get-possible-integrations.test.js +0 -188
- package/integrations/tests/use-cases/update-integration-messages.test.js +0 -142
- package/integrations/tests/use-cases/update-integration-status.test.js +0 -103
- package/integrations/tests/use-cases/update-integration.test.js +0 -141
- package/integrations/use-cases/create-process.test.js +0 -178
- package/integrations/use-cases/get-process.test.js +0 -190
- package/integrations/use-cases/load-integration-context-full.test.js +0 -329
- package/integrations/use-cases/load-integration-context.test.js +0 -114
- package/integrations/use-cases/update-process-metrics.test.js +0 -308
- package/integrations/use-cases/update-process-state.test.js +0 -256
- package/lambda/TimeoutCatcher.test.js +0 -68
- package/logs/logger.test.js +0 -76
- package/modules/module-hydration.test.js +0 -205
- package/modules/requester/requester.test.js +0 -28
- package/user/tests/use-cases/create-individual-user.test.js +0 -24
- package/user/tests/use-cases/create-organization-user.test.js +0 -28
- package/user/tests/use-cases/create-token-for-user-id.test.js +0 -19
- package/user/tests/use-cases/get-user-from-bearer-token.test.js +0 -64
- package/user/tests/use-cases/login-user.test.js +0 -220
- package/user/tests/user-password-encryption-isolation.test.js +0 -237
- package/user/tests/user-password-hashing.test.js +0 -235
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
jest.mock('../../../database/config', () => ({
|
|
2
|
-
DB_TYPE: 'mongodb',
|
|
3
|
-
getDatabaseType: jest.fn(() => 'mongodb'),
|
|
4
|
-
PRISMA_LOG_LEVEL: 'error,warn',
|
|
5
|
-
PRISMA_QUERY_LOGGING: false,
|
|
6
|
-
}));
|
|
7
|
-
|
|
8
|
-
const { UpdateIntegration } = require('../../use-cases/update-integration');
|
|
9
|
-
const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
|
|
10
|
-
const { TestModuleFactory } = require('../../../modules/tests/doubles/test-module-factory');
|
|
11
|
-
const { DummyIntegration } = require('../doubles/dummy-integration-class');
|
|
12
|
-
|
|
13
|
-
describe('UpdateIntegration Use-Case', () => {
|
|
14
|
-
let integrationRepository;
|
|
15
|
-
let moduleFactory;
|
|
16
|
-
let useCase;
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
integrationRepository = new TestIntegrationRepository();
|
|
20
|
-
moduleFactory = new TestModuleFactory();
|
|
21
|
-
useCase = new UpdateIntegration({
|
|
22
|
-
integrationRepository,
|
|
23
|
-
integrationClasses: [DummyIntegration],
|
|
24
|
-
moduleFactory,
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('happy path', () => {
|
|
29
|
-
it('calls on update and returns dto', async () => {
|
|
30
|
-
const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy', foo: 'bar' });
|
|
31
|
-
|
|
32
|
-
const newConfig = { type: 'dummy', foo: 'baz' };
|
|
33
|
-
const dto = await useCase.execute(record.id, 'user-1', newConfig);
|
|
34
|
-
|
|
35
|
-
expect(dto.config.foo).toBe('baz');
|
|
36
|
-
expect(dto.id).toBe(record.id);
|
|
37
|
-
expect(dto.userId).toBe('user-1');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('triggers ON_UPDATE event with correct payload', async () => {
|
|
41
|
-
const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy', foo: 'bar' });
|
|
42
|
-
integrationRepository.clearHistory();
|
|
43
|
-
|
|
44
|
-
const newConfig = { type: 'dummy', foo: 'updated' };
|
|
45
|
-
await useCase.execute(record.id, 'user-1', newConfig);
|
|
46
|
-
|
|
47
|
-
const history = integrationRepository.getOperationHistory();
|
|
48
|
-
const findOperation = history.find(op => op.operation === 'findById');
|
|
49
|
-
expect(findOperation).toEqual({
|
|
50
|
-
operation: 'findById',
|
|
51
|
-
id: record.id,
|
|
52
|
-
found: true
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('updates integration with multiple entities', async () => {
|
|
57
|
-
const record = await integrationRepository.createIntegration(['e1', 'e2'], 'user-1', { type: 'dummy' });
|
|
58
|
-
|
|
59
|
-
const newConfig = { type: 'dummy', updated: true };
|
|
60
|
-
const dto = await useCase.execute(record.id, 'user-1', newConfig);
|
|
61
|
-
|
|
62
|
-
expect(dto.entities).toEqual(['e1', 'e2']);
|
|
63
|
-
expect(dto.config.updated).toBe(true);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('error cases', () => {
|
|
68
|
-
it('throws error when integration not found', async () => {
|
|
69
|
-
const nonExistentId = 'non-existent-id';
|
|
70
|
-
const newConfig = { type: 'dummy', foo: 'baz' };
|
|
71
|
-
|
|
72
|
-
await expect(useCase.execute(nonExistentId, 'user-1', newConfig))
|
|
73
|
-
.rejects
|
|
74
|
-
.toThrow(`No integration found by the ID of ${nonExistentId}`);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('throws error when integration class not found', async () => {
|
|
78
|
-
const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'unknown-type' });
|
|
79
|
-
|
|
80
|
-
const newConfig = { type: 'unknown-type', foo: 'baz' };
|
|
81
|
-
|
|
82
|
-
await expect(useCase.execute(record.id, 'user-1', newConfig))
|
|
83
|
-
.rejects
|
|
84
|
-
.toThrow('No integration class found for type: unknown-type');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('throws error when user does not own integration', async () => {
|
|
88
|
-
const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy' });
|
|
89
|
-
|
|
90
|
-
const newConfig = { type: 'dummy', foo: 'baz' };
|
|
91
|
-
|
|
92
|
-
await expect(useCase.execute(record.id, 'different-user', newConfig))
|
|
93
|
-
.rejects
|
|
94
|
-
.toThrow(`Integration ${record.id} does not belong to User different-user`);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('throws error when no integration classes provided', async () => {
|
|
98
|
-
const useCaseWithoutClasses = new UpdateIntegration({
|
|
99
|
-
integrationRepository,
|
|
100
|
-
integrationClasses: [],
|
|
101
|
-
moduleFactory,
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy' });
|
|
105
|
-
const newConfig = { type: 'dummy', foo: 'baz' };
|
|
106
|
-
|
|
107
|
-
await expect(useCaseWithoutClasses.execute(record.id, 'user-1', newConfig))
|
|
108
|
-
.rejects
|
|
109
|
-
.toThrow('No integration class found for type: dummy');
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe('edge cases', () => {
|
|
114
|
-
it('handles config with null values', async () => {
|
|
115
|
-
const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy', foo: 'bar' });
|
|
116
|
-
|
|
117
|
-
const newConfig = { type: 'dummy', foo: null, bar: undefined };
|
|
118
|
-
const dto = await useCase.execute(record.id, 'user-1', newConfig);
|
|
119
|
-
|
|
120
|
-
expect(dto.config.foo).toBeNull();
|
|
121
|
-
expect(dto.config.bar).toBeUndefined();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('handles deeply nested config updates', async () => {
|
|
125
|
-
const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy', nested: { old: 'value' } });
|
|
126
|
-
|
|
127
|
-
const newConfig = {
|
|
128
|
-
type: 'dummy',
|
|
129
|
-
nested: {
|
|
130
|
-
new: 'value',
|
|
131
|
-
deep: { level: 'test' }
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
const dto = await useCase.execute(record.id, 'user-1', newConfig);
|
|
135
|
-
|
|
136
|
-
expect(dto.config.nested.new).toBe('value');
|
|
137
|
-
expect(dto.config.nested.deep.level).toBe('test');
|
|
138
|
-
expect(dto.config.nested.old).toBeUndefined();
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CreateProcess Use Case Tests
|
|
3
|
-
*
|
|
4
|
-
* Tests process creation with validation and error handling.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { CreateProcess } = require('./create-process');
|
|
8
|
-
|
|
9
|
-
describe('CreateProcess', () => {
|
|
10
|
-
let createProcessUseCase;
|
|
11
|
-
let mockProcessRepository;
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
mockProcessRepository = {
|
|
15
|
-
create: jest.fn(),
|
|
16
|
-
};
|
|
17
|
-
createProcessUseCase = new CreateProcess({
|
|
18
|
-
processRepository: mockProcessRepository,
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('constructor', () => {
|
|
23
|
-
it('should require processRepository', () => {
|
|
24
|
-
expect(() => new CreateProcess({})).toThrow('processRepository is required');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should initialize with processRepository', () => {
|
|
28
|
-
expect(createProcessUseCase.processRepository).toBe(mockProcessRepository);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('execute', () => {
|
|
33
|
-
const validProcessData = {
|
|
34
|
-
userId: 'user-123',
|
|
35
|
-
integrationId: 'integration-456',
|
|
36
|
-
name: 'test-crm-contact-sync',
|
|
37
|
-
type: 'CRM_SYNC',
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
it('should create a process with minimal required data', async () => {
|
|
41
|
-
const mockCreatedProcess = { id: 'process-789', ...validProcessData };
|
|
42
|
-
mockProcessRepository.create.mockResolvedValue(mockCreatedProcess);
|
|
43
|
-
|
|
44
|
-
const result = await createProcessUseCase.execute(validProcessData);
|
|
45
|
-
|
|
46
|
-
expect(mockProcessRepository.create).toHaveBeenCalledWith({
|
|
47
|
-
userId: 'user-123',
|
|
48
|
-
integrationId: 'integration-456',
|
|
49
|
-
name: 'test-crm-contact-sync',
|
|
50
|
-
type: 'CRM_SYNC',
|
|
51
|
-
state: 'INITIALIZING',
|
|
52
|
-
context: {},
|
|
53
|
-
results: {},
|
|
54
|
-
childProcesses: [],
|
|
55
|
-
parentProcessId: null,
|
|
56
|
-
});
|
|
57
|
-
expect(result).toEqual(mockCreatedProcess);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should create a process with all optional data', async () => {
|
|
61
|
-
const processDataWithOptions = {
|
|
62
|
-
...validProcessData,
|
|
63
|
-
state: 'FETCHING_TOTAL',
|
|
64
|
-
context: { syncType: 'INITIAL', totalRecords: 100 },
|
|
65
|
-
results: { aggregateData: { totalSynced: 0 } },
|
|
66
|
-
childProcesses: ['child-1', 'child-2'],
|
|
67
|
-
parentProcessId: 'parent-123',
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const mockCreatedProcess = { id: 'process-789', ...processDataWithOptions };
|
|
71
|
-
mockProcessRepository.create.mockResolvedValue(mockCreatedProcess);
|
|
72
|
-
|
|
73
|
-
const result = await createProcessUseCase.execute(processDataWithOptions);
|
|
74
|
-
|
|
75
|
-
expect(mockProcessRepository.create).toHaveBeenCalledWith(processDataWithOptions);
|
|
76
|
-
expect(result).toEqual(mockCreatedProcess);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should throw error if userId is missing', async () => {
|
|
80
|
-
const invalidData = { integrationId: 'int-123', name: 'test', type: 'CRM_SYNC' };
|
|
81
|
-
|
|
82
|
-
await expect(createProcessUseCase.execute(invalidData))
|
|
83
|
-
.rejects.toThrow('Missing required fields for process creation: userId');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('should throw error if integrationId is missing', async () => {
|
|
87
|
-
const invalidData = { userId: 'user-123', name: 'test', type: 'CRM_SYNC' };
|
|
88
|
-
|
|
89
|
-
await expect(createProcessUseCase.execute(invalidData))
|
|
90
|
-
.rejects.toThrow('Missing required fields for process creation: integrationId');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should throw error if name is missing', async () => {
|
|
94
|
-
const invalidData = { userId: 'user-123', integrationId: 'int-123', type: 'CRM_SYNC' };
|
|
95
|
-
|
|
96
|
-
await expect(createProcessUseCase.execute(invalidData))
|
|
97
|
-
.rejects.toThrow('Missing required fields for process creation: name');
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('should throw error if type is missing', async () => {
|
|
101
|
-
const invalidData = { userId: 'user-123', integrationId: 'int-123', name: 'test' };
|
|
102
|
-
|
|
103
|
-
await expect(createProcessUseCase.execute(invalidData))
|
|
104
|
-
.rejects.toThrow('Missing required fields for process creation: type');
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('should throw error if userId is not a string', async () => {
|
|
108
|
-
const invalidData = { ...validProcessData, userId: 123 };
|
|
109
|
-
|
|
110
|
-
await expect(createProcessUseCase.execute(invalidData))
|
|
111
|
-
.rejects.toThrow('userId must be a string');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should throw error if integrationId is not a string', async () => {
|
|
115
|
-
const invalidData = { ...validProcessData, integrationId: 456 };
|
|
116
|
-
|
|
117
|
-
await expect(createProcessUseCase.execute(invalidData))
|
|
118
|
-
.rejects.toThrow('integrationId must be a string');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('should throw error if name is not a string', async () => {
|
|
122
|
-
const invalidData = { ...validProcessData, name: 789 };
|
|
123
|
-
|
|
124
|
-
await expect(createProcessUseCase.execute(invalidData))
|
|
125
|
-
.rejects.toThrow('name must be a string');
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('should throw error if type is not a string', async () => {
|
|
129
|
-
const invalidData = { ...validProcessData, type: 999 };
|
|
130
|
-
|
|
131
|
-
await expect(createProcessUseCase.execute(invalidData))
|
|
132
|
-
.rejects.toThrow('type must be a string');
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should throw error if state is provided but not a string', async () => {
|
|
136
|
-
const invalidData = { ...validProcessData, state: 123 };
|
|
137
|
-
|
|
138
|
-
await expect(createProcessUseCase.execute(invalidData))
|
|
139
|
-
.rejects.toThrow('state must be a string');
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should throw error if context is provided but not an object', async () => {
|
|
143
|
-
const invalidData = { ...validProcessData, context: 'invalid' };
|
|
144
|
-
|
|
145
|
-
await expect(createProcessUseCase.execute(invalidData))
|
|
146
|
-
.rejects.toThrow('context must be an object');
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('should throw error if results is provided but not an object', async () => {
|
|
150
|
-
const invalidData = { ...validProcessData, results: 'invalid' };
|
|
151
|
-
|
|
152
|
-
await expect(createProcessUseCase.execute(invalidData))
|
|
153
|
-
.rejects.toThrow('results must be an object');
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('should throw error if childProcesses is provided but not an array', async () => {
|
|
157
|
-
const invalidData = { ...validProcessData, childProcesses: 'invalid' };
|
|
158
|
-
|
|
159
|
-
await expect(createProcessUseCase.execute(invalidData))
|
|
160
|
-
.rejects.toThrow('childProcesses must be an array');
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('should throw error if parentProcessId is provided but not a string', async () => {
|
|
164
|
-
const invalidData = { ...validProcessData, parentProcessId: 123 };
|
|
165
|
-
|
|
166
|
-
await expect(createProcessUseCase.execute(invalidData))
|
|
167
|
-
.rejects.toThrow('parentProcessId must be a string');
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('should handle repository errors', async () => {
|
|
171
|
-
const repositoryError = new Error('Database connection failed');
|
|
172
|
-
mockProcessRepository.create.mockRejectedValue(repositoryError);
|
|
173
|
-
|
|
174
|
-
await expect(createProcessUseCase.execute(validProcessData))
|
|
175
|
-
.rejects.toThrow('Failed to create process: Database connection failed');
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
});
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GetProcess Use Case Tests
|
|
3
|
-
*
|
|
4
|
-
* Tests process retrieval with error handling.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { GetProcess } = require('./get-process');
|
|
8
|
-
|
|
9
|
-
describe('GetProcess', () => {
|
|
10
|
-
let getProcessUseCase;
|
|
11
|
-
let mockProcessRepository;
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
mockProcessRepository = {
|
|
15
|
-
findById: jest.fn(),
|
|
16
|
-
};
|
|
17
|
-
getProcessUseCase = new GetProcess({
|
|
18
|
-
processRepository: mockProcessRepository,
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('constructor', () => {
|
|
23
|
-
it('should require processRepository', () => {
|
|
24
|
-
expect(() => new GetProcess({})).toThrow('processRepository is required');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should initialize with processRepository', () => {
|
|
28
|
-
expect(getProcessUseCase.processRepository).toBe(mockProcessRepository);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('execute', () => {
|
|
33
|
-
const processId = 'process-123';
|
|
34
|
-
const mockProcess = {
|
|
35
|
-
id: processId,
|
|
36
|
-
userId: 'user-456',
|
|
37
|
-
integrationId: 'integration-789',
|
|
38
|
-
name: 'test-sync',
|
|
39
|
-
type: 'CRM_SYNC',
|
|
40
|
-
state: 'PROCESSING_BATCHES',
|
|
41
|
-
context: {
|
|
42
|
-
syncType: 'INITIAL',
|
|
43
|
-
totalRecords: 1000,
|
|
44
|
-
processedRecords: 500,
|
|
45
|
-
},
|
|
46
|
-
results: {
|
|
47
|
-
aggregateData: {
|
|
48
|
-
totalSynced: 480,
|
|
49
|
-
totalFailed: 20,
|
|
50
|
-
duration: 120000,
|
|
51
|
-
recordsPerSecond: 4.17,
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
createdAt: new Date('2024-01-01T10:00:00Z'),
|
|
55
|
-
updatedAt: new Date('2024-01-01T10:02:00Z'),
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
it('should retrieve a process by ID', async () => {
|
|
59
|
-
mockProcessRepository.findById.mockResolvedValue(mockProcess);
|
|
60
|
-
|
|
61
|
-
const result = await getProcessUseCase.execute(processId);
|
|
62
|
-
|
|
63
|
-
expect(mockProcessRepository.findById).toHaveBeenCalledWith(processId);
|
|
64
|
-
expect(result).toEqual(mockProcess);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should return null if process not found', async () => {
|
|
68
|
-
mockProcessRepository.findById.mockResolvedValue(null);
|
|
69
|
-
|
|
70
|
-
const result = await getProcessUseCase.execute(processId);
|
|
71
|
-
|
|
72
|
-
expect(mockProcessRepository.findById).toHaveBeenCalledWith(processId);
|
|
73
|
-
expect(result).toBeNull();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should throw error if processId is missing', async () => {
|
|
77
|
-
await expect(getProcessUseCase.execute(''))
|
|
78
|
-
.rejects.toThrow('processId must be a non-empty string');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should throw error if processId is not a string', async () => {
|
|
82
|
-
await expect(getProcessUseCase.execute(123))
|
|
83
|
-
.rejects.toThrow('processId must be a non-empty string');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('should handle repository errors', async () => {
|
|
87
|
-
const repositoryError = new Error('Database connection failed');
|
|
88
|
-
mockProcessRepository.findById.mockRejectedValue(repositoryError);
|
|
89
|
-
|
|
90
|
-
await expect(getProcessUseCase.execute(processId))
|
|
91
|
-
.rejects.toThrow('Failed to retrieve process: Database connection failed');
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('executeOrThrow', () => {
|
|
96
|
-
const processId = 'process-123';
|
|
97
|
-
const mockProcess = {
|
|
98
|
-
id: processId,
|
|
99
|
-
userId: 'user-456',
|
|
100
|
-
integrationId: 'integration-789',
|
|
101
|
-
name: 'test-sync',
|
|
102
|
-
type: 'CRM_SYNC',
|
|
103
|
-
state: 'COMPLETED',
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
it('should return process if found', async () => {
|
|
107
|
-
mockProcessRepository.findById.mockResolvedValue(mockProcess);
|
|
108
|
-
|
|
109
|
-
const result = await getProcessUseCase.executeOrThrow(processId);
|
|
110
|
-
|
|
111
|
-
expect(result).toEqual(mockProcess);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should throw error if process not found', async () => {
|
|
115
|
-
mockProcessRepository.findById.mockResolvedValue(null);
|
|
116
|
-
|
|
117
|
-
await expect(getProcessUseCase.executeOrThrow(processId))
|
|
118
|
-
.rejects.toThrow('Process not found: process-123');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('should propagate repository errors', async () => {
|
|
122
|
-
const repositoryError = new Error('Database connection failed');
|
|
123
|
-
mockProcessRepository.findById.mockRejectedValue(repositoryError);
|
|
124
|
-
|
|
125
|
-
await expect(getProcessUseCase.executeOrThrow(processId))
|
|
126
|
-
.rejects.toThrow('Failed to retrieve process: Database connection failed');
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe('executeMany', () => {
|
|
131
|
-
const processIds = ['process-1', 'process-2', 'process-3'];
|
|
132
|
-
const mockProcesses = [
|
|
133
|
-
{ id: 'process-1', name: 'sync-1', state: 'COMPLETED' },
|
|
134
|
-
{ id: 'process-2', name: 'sync-2', state: 'PROCESSING' },
|
|
135
|
-
// process-3 will not be found
|
|
136
|
-
];
|
|
137
|
-
|
|
138
|
-
it('should retrieve multiple processes', async () => {
|
|
139
|
-
mockProcessRepository.findById
|
|
140
|
-
.mockResolvedValueOnce(mockProcesses[0]) // process-1 found
|
|
141
|
-
.mockResolvedValueOnce(mockProcesses[1]) // process-2 found
|
|
142
|
-
.mockResolvedValueOnce(null); // process-3 not found
|
|
143
|
-
|
|
144
|
-
const result = await getProcessUseCase.executeMany(processIds);
|
|
145
|
-
|
|
146
|
-
expect(mockProcessRepository.findById).toHaveBeenCalledTimes(3);
|
|
147
|
-
expect(mockProcessRepository.findById).toHaveBeenCalledWith('process-1');
|
|
148
|
-
expect(mockProcessRepository.findById).toHaveBeenCalledWith('process-2');
|
|
149
|
-
expect(mockProcessRepository.findById).toHaveBeenCalledWith('process-3');
|
|
150
|
-
|
|
151
|
-
// Should return only found processes
|
|
152
|
-
expect(result).toEqual([mockProcesses[0], mockProcesses[1]]);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('should return empty array if no processes found', async () => {
|
|
156
|
-
mockProcessRepository.findById
|
|
157
|
-
.mockResolvedValueOnce(null)
|
|
158
|
-
.mockResolvedValueOnce(null)
|
|
159
|
-
.mockResolvedValueOnce(null);
|
|
160
|
-
|
|
161
|
-
const result = await getProcessUseCase.executeMany(processIds);
|
|
162
|
-
|
|
163
|
-
expect(result).toEqual([]);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('should throw error if processIds is not an array', async () => {
|
|
167
|
-
await expect(getProcessUseCase.executeMany('not-an-array'))
|
|
168
|
-
.rejects.toThrow('processIds must be an array');
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('should handle mixed success and failure', async () => {
|
|
172
|
-
const repositoryError = new Error('Database error');
|
|
173
|
-
mockProcessRepository.findById
|
|
174
|
-
.mockResolvedValueOnce(mockProcesses[0]) // process-1 found
|
|
175
|
-
.mockRejectedValueOnce(repositoryError) // process-2 error
|
|
176
|
-
.mockResolvedValueOnce(null); // process-3 not found
|
|
177
|
-
|
|
178
|
-
// Should propagate the repository error
|
|
179
|
-
await expect(getProcessUseCase.executeMany(processIds))
|
|
180
|
-
.rejects.toThrow('Failed to retrieve process: Database error');
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('should handle empty array', async () => {
|
|
184
|
-
const result = await getProcessUseCase.executeMany([]);
|
|
185
|
-
|
|
186
|
-
expect(mockProcessRepository.findById).not.toHaveBeenCalled();
|
|
187
|
-
expect(result).toEqual([]);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
});
|