@friggframework/core 2.0.0--canary.461.61382d8.0 → 2.0.0--canary.461.5767fa4.0

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.
Files changed (118) hide show
  1. package/generated/prisma-mongodb/client.d.ts +1 -0
  2. package/generated/prisma-mongodb/client.js +4 -0
  3. package/generated/prisma-mongodb/default.d.ts +1 -0
  4. package/generated/prisma-mongodb/default.js +4 -0
  5. package/generated/prisma-mongodb/edge.d.ts +1 -0
  6. package/generated/prisma-mongodb/edge.js +336 -0
  7. package/generated/prisma-mongodb/index-browser.js +318 -0
  8. package/generated/prisma-mongodb/index.d.ts +22993 -0
  9. package/generated/prisma-mongodb/index.js +361 -0
  10. package/generated/prisma-mongodb/package.json +183 -0
  11. package/generated/prisma-mongodb/query-engine-debian-openssl-3.0.x +0 -0
  12. package/generated/prisma-mongodb/query-engine-rhel-openssl-3.0.x +0 -0
  13. package/generated/prisma-mongodb/runtime/binary.d.ts +1 -0
  14. package/generated/prisma-mongodb/runtime/binary.js +289 -0
  15. package/generated/prisma-mongodb/runtime/edge-esm.js +34 -0
  16. package/generated/prisma-mongodb/runtime/edge.js +34 -0
  17. package/generated/prisma-mongodb/runtime/index-browser.d.ts +370 -0
  18. package/generated/prisma-mongodb/runtime/index-browser.js +16 -0
  19. package/generated/prisma-mongodb/runtime/library.d.ts +3977 -0
  20. package/generated/prisma-mongodb/runtime/react-native.js +83 -0
  21. package/generated/prisma-mongodb/runtime/wasm-compiler-edge.js +84 -0
  22. package/generated/prisma-mongodb/runtime/wasm-engine-edge.js +36 -0
  23. package/generated/prisma-mongodb/schema.prisma +364 -0
  24. package/generated/prisma-mongodb/wasm-edge-light-loader.mjs +4 -0
  25. package/generated/prisma-mongodb/wasm-worker-loader.mjs +4 -0
  26. package/generated/prisma-mongodb/wasm.d.ts +1 -0
  27. package/generated/prisma-mongodb/wasm.js +343 -0
  28. package/generated/prisma-postgresql/client.d.ts +1 -0
  29. package/generated/prisma-postgresql/client.js +4 -0
  30. package/generated/prisma-postgresql/default.d.ts +1 -0
  31. package/generated/prisma-postgresql/default.js +4 -0
  32. package/generated/prisma-postgresql/edge.d.ts +1 -0
  33. package/generated/prisma-postgresql/edge.js +358 -0
  34. package/generated/prisma-postgresql/index-browser.js +340 -0
  35. package/generated/prisma-postgresql/index.d.ts +25171 -0
  36. package/generated/prisma-postgresql/index.js +383 -0
  37. package/generated/prisma-postgresql/package.json +183 -0
  38. package/generated/prisma-postgresql/query-engine-debian-openssl-3.0.x +0 -0
  39. package/generated/prisma-postgresql/query-engine-rhel-openssl-3.0.x +0 -0
  40. package/generated/prisma-postgresql/query_engine_bg.js +2 -0
  41. package/generated/prisma-postgresql/query_engine_bg.wasm +0 -0
  42. package/generated/prisma-postgresql/runtime/binary.d.ts +1 -0
  43. package/generated/prisma-postgresql/runtime/binary.js +289 -0
  44. package/generated/prisma-postgresql/runtime/edge-esm.js +34 -0
  45. package/generated/prisma-postgresql/runtime/edge.js +34 -0
  46. package/generated/prisma-postgresql/runtime/index-browser.d.ts +370 -0
  47. package/generated/prisma-postgresql/runtime/index-browser.js +16 -0
  48. package/generated/prisma-postgresql/runtime/library.d.ts +3977 -0
  49. package/generated/prisma-postgresql/runtime/react-native.js +83 -0
  50. package/generated/prisma-postgresql/runtime/wasm-compiler-edge.js +84 -0
  51. package/generated/prisma-postgresql/runtime/wasm-engine-edge.js +36 -0
  52. package/generated/prisma-postgresql/schema.prisma +347 -0
  53. package/generated/prisma-postgresql/wasm-edge-light-loader.mjs +4 -0
  54. package/generated/prisma-postgresql/wasm-worker-loader.mjs +4 -0
  55. package/generated/prisma-postgresql/wasm.d.ts +1 -0
  56. package/generated/prisma-postgresql/wasm.js +365 -0
  57. package/package.json +5 -5
  58. package/application/commands/integration-commands.test.js +0 -123
  59. package/core/Worker.test.js +0 -159
  60. package/database/encryption/encryption-integration.test.js +0 -553
  61. package/database/encryption/encryption-schema-registry.test.js +0 -392
  62. package/database/encryption/field-encryption-service.test.js +0 -525
  63. package/database/encryption/mongo-decryption-fix-verification.test.js +0 -348
  64. package/database/encryption/postgres-decryption-fix-verification.test.js +0 -371
  65. package/database/encryption/postgres-relation-decryption.test.js +0 -245
  66. package/database/encryption/prisma-encryption-extension.test.js +0 -439
  67. package/database/repositories/migration-status-repository-s3.test.js +0 -158
  68. package/database/use-cases/check-encryption-health-use-case.test.js +0 -192
  69. package/database/use-cases/get-migration-status-use-case.test.js +0 -171
  70. package/database/use-cases/run-database-migration-use-case.test.js +0 -310
  71. package/database/use-cases/trigger-database-migration-use-case.test.js +0 -250
  72. package/database/utils/prisma-runner.test.js +0 -486
  73. package/encrypt/Cryptor.test.js +0 -144
  74. package/errors/base-error.test.js +0 -32
  75. package/errors/fetch-error.test.js +0 -79
  76. package/errors/halt-error.test.js +0 -11
  77. package/errors/validation-errors.test.js +0 -120
  78. package/handlers/auth-flow.integration.test.js +0 -147
  79. package/handlers/integration-event-dispatcher.test.js +0 -209
  80. package/handlers/routers/db-migration.test.js +0 -51
  81. package/handlers/routers/health.test.js +0 -210
  82. package/handlers/routers/integration-webhook-routers.test.js +0 -126
  83. package/handlers/use-cases/check-integrations-health-use-case.test.js +0 -125
  84. package/handlers/webhook-flow.integration.test.js +0 -356
  85. package/handlers/workers/db-migration.test.js +0 -50
  86. package/handlers/workers/integration-defined-workers.test.js +0 -184
  87. package/integrations/tests/integration-router-multi-auth.test.js +0 -369
  88. package/integrations/tests/use-cases/create-integration.test.js +0 -131
  89. package/integrations/tests/use-cases/delete-integration-for-user.test.js +0 -150
  90. package/integrations/tests/use-cases/find-integration-context-by-external-entity-id.test.js +0 -92
  91. package/integrations/tests/use-cases/get-integration-for-user.test.js +0 -150
  92. package/integrations/tests/use-cases/get-integration-instance.test.js +0 -176
  93. package/integrations/tests/use-cases/get-integrations-for-user.test.js +0 -176
  94. package/integrations/tests/use-cases/get-possible-integrations.test.js +0 -188
  95. package/integrations/tests/use-cases/update-integration-messages.test.js +0 -142
  96. package/integrations/tests/use-cases/update-integration-status.test.js +0 -103
  97. package/integrations/tests/use-cases/update-integration.test.js +0 -141
  98. package/integrations/use-cases/create-process.test.js +0 -178
  99. package/integrations/use-cases/get-process.test.js +0 -190
  100. package/integrations/use-cases/load-integration-context-full.test.js +0 -329
  101. package/integrations/use-cases/load-integration-context.test.js +0 -114
  102. package/integrations/use-cases/update-process-metrics.test.js +0 -308
  103. package/integrations/use-cases/update-process-state.test.js +0 -256
  104. package/lambda/TimeoutCatcher.test.js +0 -68
  105. package/logs/logger.test.js +0 -76
  106. package/modules/module-hydration.test.js +0 -205
  107. package/modules/requester/requester.test.js +0 -28
  108. package/queues/queuer-util.test.js +0 -132
  109. package/user/tests/use-cases/create-individual-user.test.js +0 -24
  110. package/user/tests/use-cases/create-organization-user.test.js +0 -28
  111. package/user/tests/use-cases/create-token-for-user-id.test.js +0 -19
  112. package/user/tests/use-cases/get-user-from-adopter-jwt.test.js +0 -113
  113. package/user/tests/use-cases/get-user-from-bearer-token.test.js +0 -64
  114. package/user/tests/use-cases/get-user-from-x-frigg-headers.test.js +0 -346
  115. package/user/tests/use-cases/login-user.test.js +0 -220
  116. package/user/tests/user-password-encryption-isolation.test.js +0 -237
  117. package/user/tests/user-password-hashing.test.js +0 -235
  118. package/websocket/repositories/websocket-connection-repository.test.js +0 -227
@@ -1,92 +0,0 @@
1
- const { FindIntegrationContextByExternalEntityIdUseCase } = require('../../use-cases/find-integration-context-by-external-entity-id');
2
- const { TestModuleRepository } = require('../../../modules/tests/doubles/test-module-repository');
3
- const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
4
- const { DummyIntegration } = require('../doubles/dummy-integration-class');
5
-
6
- describe('FindIntegrationContextByExternalEntityIdUseCase', () => {
7
- let moduleRepository;
8
- let integrationRepository;
9
- let loadIntegrationContextUseCase;
10
- let useCase;
11
-
12
- beforeEach(() => {
13
- moduleRepository = new TestModuleRepository();
14
- integrationRepository = new TestIntegrationRepository();
15
- loadIntegrationContextUseCase = {
16
- execute: jest.fn(),
17
- };
18
- useCase = new FindIntegrationContextByExternalEntityIdUseCase({
19
- moduleRepository,
20
- integrationRepository,
21
- loadIntegrationContextUseCase,
22
- });
23
- });
24
-
25
- it('throws when externalEntityId is missing', async () => {
26
- await expect(useCase.execute({})).rejects.toHaveProperty(
27
- 'code',
28
- 'EXTERNAL_ENTITY_ID_REQUIRED',
29
- );
30
- });
31
-
32
- it('throws when entity is not found', async () => {
33
- await expect(
34
- useCase.execute({ externalEntityId: 'abc' }),
35
- ).rejects.toHaveProperty('code', 'ENTITY_NOT_FOUND');
36
- });
37
-
38
- it('throws when entity user is missing', async () => {
39
- moduleRepository.addEntity({
40
- id: 'entity-1',
41
- externalId: 'ext-1',
42
- });
43
-
44
- await expect(
45
- useCase.execute({ externalEntityId: 'ext-1' }),
46
- ).rejects.toHaveProperty('code', 'ENTITY_USER_NOT_FOUND');
47
- });
48
-
49
- it('throws when integration is not found for user', async () => {
50
- moduleRepository.addEntity({
51
- id: 'entity-1',
52
- externalId: 'ext-1',
53
- userId: 'user-1',
54
- });
55
-
56
- await expect(
57
- useCase.execute({ externalEntityId: 'ext-1' }),
58
- ).rejects.toHaveProperty('code', 'INTEGRATION_NOT_FOUND');
59
- });
60
-
61
- it('returns context, entity, and record on success', async () => {
62
- const entity = {
63
- id: 'entity-1',
64
- externalId: 'ext-1',
65
- userId: 'user-1',
66
- };
67
- moduleRepository.addEntity(entity);
68
-
69
- const integrationRecord = await integrationRepository.createIntegration(
70
- [entity.id],
71
- entity.userId,
72
- { type: 'dummy' },
73
- );
74
-
75
- const expectedContext = {
76
- record: integrationRecord,
77
- modules: [{ id: 'module-1' }],
78
- };
79
- loadIntegrationContextUseCase.execute.mockResolvedValue(
80
- expectedContext,
81
- );
82
-
83
- const result = await useCase.execute({ externalEntityId: 'ext-1' });
84
-
85
- expect(loadIntegrationContextUseCase.execute).toHaveBeenCalledWith({
86
- integrationRecord,
87
- });
88
- expect(result.context).toEqual(expectedContext);
89
- expect(result.entity).toEqual(entity);
90
- expect(result.record).toEqual(integrationRecord);
91
- });
92
- });
@@ -1,150 +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 { GetIntegrationForUser } = require('../../use-cases/get-integration-for-user');
9
- const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
10
- const { TestModuleFactory } = require('../../../modules/tests/doubles/test-module-factory');
11
- const { TestModuleRepository } = require('../../../modules/tests/doubles/test-module-repository');
12
- const { DummyIntegration } = require('../doubles/dummy-integration-class');
13
-
14
- describe('GetIntegrationForUser Use-Case', () => {
15
- let integrationRepository;
16
- let moduleRepository;
17
- let moduleFactory;
18
- let useCase;
19
-
20
- beforeEach(() => {
21
- integrationRepository = new TestIntegrationRepository();
22
- moduleRepository = new TestModuleRepository();
23
- moduleFactory = new TestModuleFactory();
24
- useCase = new GetIntegrationForUser({
25
- integrationRepository,
26
- integrationClasses: [DummyIntegration],
27
- moduleFactory,
28
- moduleRepository,
29
- });
30
- });
31
-
32
- describe('happy path', () => {
33
- it('returns integration dto', async () => {
34
- const entity = { id: 'entity-1', _id: 'entity-1' };
35
- moduleRepository.addEntity(entity);
36
-
37
- const record = await integrationRepository.createIntegration([entity.id], 'user-1', { type: 'dummy' });
38
-
39
- const dto = await useCase.execute(record.id, 'user-1');
40
- expect(dto.id).toBe(record.id);
41
- expect(dto.userId).toBe('user-1');
42
- expect(dto.config.type).toBe('dummy');
43
- });
44
-
45
- it('returns integration with multiple entities', async () => {
46
- const entity1 = { id: 'entity-1', _id: 'entity-1' };
47
- const entity2 = { id: 'entity-2', _id: 'entity-2' };
48
- moduleRepository.addEntity(entity1);
49
- moduleRepository.addEntity(entity2);
50
-
51
- const record = await integrationRepository.createIntegration([entity1.id, entity2.id], 'user-1', { type: 'dummy' });
52
-
53
- const dto = await useCase.execute(record.id, 'user-1');
54
- expect(dto.entities).toEqual([entity1, entity2]);
55
- });
56
-
57
- it('returns integration with complex config', async () => {
58
- const entity = { id: 'entity-1', _id: 'entity-1' };
59
- moduleRepository.addEntity(entity);
60
-
61
- const complexConfig = {
62
- type: 'dummy',
63
- settings: { api: { timeout: 5000 }, debug: true },
64
- features: ['webhooks', 'sync']
65
- };
66
-
67
- const record = await integrationRepository.createIntegration([entity.id], 'user-1', complexConfig);
68
-
69
- const dto = await useCase.execute(record.id, 'user-1');
70
- expect(dto.config).toEqual(complexConfig);
71
- });
72
- });
73
-
74
- describe('error cases', () => {
75
- it('throws error when integration not found', async () => {
76
- const nonExistentId = 'non-existent-id';
77
-
78
- await expect(useCase.execute(nonExistentId, 'user-1'))
79
- .rejects
80
- .toThrow();
81
- });
82
-
83
- it('throws error when user does not own integration', async () => {
84
- const entity = { id: 'entity-1', _id: 'entity-1' };
85
- moduleRepository.addEntity(entity);
86
-
87
- const record = await integrationRepository.createIntegration([entity.id], 'user-1', { type: 'dummy' });
88
-
89
- await expect(useCase.execute(record.id, 'different-user'))
90
- .rejects
91
- .toThrow();
92
- });
93
-
94
- it('throws error when integration class not found', async () => {
95
- const useCaseWithoutClasses = new GetIntegrationForUser({
96
- integrationRepository,
97
- integrationClasses: [],
98
- moduleFactory,
99
- moduleRepository,
100
- });
101
-
102
- const entity = { id: 'entity-1', _id: 'entity-1' };
103
- moduleRepository.addEntity(entity);
104
-
105
- const record = await integrationRepository.createIntegration([entity.id], 'user-1', { type: 'dummy' });
106
-
107
- await expect(useCaseWithoutClasses.execute(record.id, 'user-1'))
108
- .rejects
109
- .toThrow();
110
- });
111
-
112
- it('handles missing entities gracefully', async () => {
113
- const record = await integrationRepository.createIntegration(['missing-entity'], 'user-1', { type: 'dummy' });
114
-
115
- await expect(useCase.execute(record.id, 'user-1'))
116
- .rejects
117
- .toThrow();
118
- });
119
- });
120
-
121
- describe('edge cases', () => {
122
- it('handles userId as string vs number comparison', async () => {
123
- const entity = { id: 'entity-1', _id: 'entity-1' };
124
- moduleRepository.addEntity(entity);
125
-
126
- const record = await integrationRepository.createIntegration([entity.id], 'user-1', { type: 'dummy' });
127
-
128
- const dto1 = await useCase.execute(record.id, 'user-1');
129
- const dto2 = await useCase.execute(record.id, 'user-1');
130
-
131
- expect(dto1.userId).toBe(dto2.userId);
132
- });
133
-
134
- it('returns all integration properties', async () => {
135
- const entity = { id: 'entity-1', _id: 'entity-1' };
136
- moduleRepository.addEntity(entity);
137
-
138
- const record = await integrationRepository.createIntegration([entity.id], 'user-1', { type: 'dummy' });
139
-
140
- record.status = 'ACTIVE';
141
- record.version = '1.0.0';
142
- record.messages = { info: [{ title: 'Test', message: 'Message' }] };
143
-
144
- const dto = await useCase.execute(record.id, 'user-1');
145
- expect(dto.status).toBe('ACTIVE');
146
- expect(dto.version).toBe('1.0.0');
147
- expect(dto.messages).toEqual({ info: [{ title: 'Test', message: 'Message' }] });
148
- });
149
- });
150
- });
@@ -1,176 +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 { GetIntegrationInstance } = require('../../use-cases/get-integration-instance');
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('GetIntegrationInstance 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 GetIntegrationInstance({
22
- integrationRepository,
23
- integrationClasses: [DummyIntegration],
24
- moduleFactory,
25
- });
26
- });
27
-
28
- describe('happy path', () => {
29
- it('returns hydrated integration instance', async () => {
30
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
31
-
32
- const instance = await useCase.execute(record.id, 'user-1');
33
-
34
- expect(instance.id).toBe(record.id);
35
- expect(instance.getConfig().type).toBe('dummy');
36
- expect(instance.entities).toEqual(record.entitiesIds);
37
- expect(instance.userId).toBe('user-1');
38
- });
39
-
40
- it('returns instance with multiple modules', async () => {
41
- const record = await integrationRepository.createIntegration(['entity-1', 'entity-2'], 'user-1', { type: 'dummy' });
42
-
43
- const instance = await useCase.execute(record.id, 'user-1');
44
-
45
- expect(instance.entities).toEqual(['entity-1', 'entity-2']);
46
- expect(Object.keys(instance.modules)).toHaveLength(1);
47
- expect(instance.modules['stubModule']).toBeDefined();
48
- });
49
-
50
- it('initializes integration instance properly', async () => {
51
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
52
-
53
- const instance = await useCase.execute(record.id, 'user-1');
54
-
55
- expect(typeof instance.send).toBe('function');
56
- expect(typeof instance.getConfig).toBe('function');
57
- expect(typeof instance.initialize).toBe('function');
58
- });
59
-
60
- it('preserves all integration properties', async () => {
61
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy', custom: 'value' });
62
-
63
- record.status = 'ACTIVE';
64
- record.version = '2.0.0';
65
- record.messages = { logs: [{ title: 'Test', message: 'Log entry' }] };
66
-
67
- const instance = await useCase.execute(record.id, 'user-1');
68
-
69
- expect(instance.status).toBe('ACTIVE');
70
- expect(instance.version).toBe('2.0.0');
71
- expect(instance.messages).toEqual({ logs: [{ title: 'Test', message: 'Log entry' }] });
72
- expect(instance.getConfig().custom).toBe('value');
73
- });
74
- });
75
-
76
- describe('error cases', () => {
77
- it('throws error when integration not found', async () => {
78
- const nonExistentId = 'non-existent-id';
79
-
80
- await expect(useCase.execute(nonExistentId, 'user-1'))
81
- .rejects
82
- .toThrow(`No integration found by the ID of ${nonExistentId}`);
83
- });
84
-
85
- it('throws error when user does not own integration', async () => {
86
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
87
-
88
- await expect(useCase.execute(record.id, 'different-user'))
89
- .rejects
90
- .toThrow(`Integration ${record.id} does not belong to User different-user`);
91
- });
92
-
93
- it('throws error when integration class not found', async () => {
94
- const useCaseWithoutClasses = new GetIntegrationInstance({
95
- integrationRepository,
96
- integrationClasses: [],
97
- moduleFactory,
98
- });
99
-
100
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
101
-
102
- await expect(useCaseWithoutClasses.execute(record.id, 'user-1'))
103
- .rejects
104
- .toThrow('No integration class found for type: dummy');
105
- });
106
-
107
- it('throws error when integration has unknown type', async () => {
108
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'unknown-type' });
109
-
110
- await expect(useCase.execute(record.id, 'user-1'))
111
- .rejects
112
- .toThrow('No integration class found for type: unknown-type');
113
- });
114
- });
115
-
116
- describe('edge cases', () => {
117
- it('handles integration with no entities', async () => {
118
- const record = await integrationRepository.createIntegration([], 'user-1', { type: 'dummy' });
119
-
120
- const instance = await useCase.execute(record.id, 'user-1');
121
-
122
- expect(instance.entities).toEqual([]);
123
- expect(Object.keys(instance.modules)).toHaveLength(0);
124
- });
125
-
126
- it('handles integration with null config values', async () => {
127
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy', nullValue: null });
128
-
129
- const instance = await useCase.execute(record.id, 'user-1');
130
-
131
- expect(instance.getConfig().nullValue).toBeNull();
132
- });
133
-
134
- it('handles userId comparison edge cases', async () => {
135
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
136
-
137
- const instance1 = await useCase.execute(record.id, 'user-1');
138
- const instance2 = await useCase.execute(record.id, 'user-1');
139
-
140
- expect(instance1.userId).toBe(instance2.userId);
141
- });
142
-
143
- it('returns fresh instance on each call', async () => {
144
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
145
-
146
- const instance1 = await useCase.execute(record.id, 'user-1');
147
- const instance2 = await useCase.execute(record.id, 'user-1');
148
-
149
- expect(instance1).not.toBe(instance2);
150
- expect(instance1.id).toBe(instance2.id);
151
- });
152
-
153
- it('handles complex nested config structures', async () => {
154
- const complexConfig = {
155
- type: 'dummy',
156
- settings: {
157
- api: {
158
- timeout: 5000,
159
- retries: 3,
160
- endpoints: ['users', 'orders']
161
- },
162
- features: {
163
- webhooks: true,
164
- sync: { interval: 300 }
165
- }
166
- }
167
- };
168
-
169
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', complexConfig);
170
-
171
- const instance = await useCase.execute(record.id, 'user-1');
172
-
173
- expect(instance.getConfig()).toEqual(complexConfig);
174
- });
175
- });
176
- });
@@ -1,176 +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 { GetIntegrationsForUser } = require('../../use-cases/get-integrations-for-user');
9
- const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
10
- const { TestModuleFactory } = require('../../../modules/tests/doubles/test-module-factory');
11
- const { TestModuleRepository } = require('../../../modules/tests/doubles/test-module-repository');
12
- const { DummyIntegration } = require('../doubles/dummy-integration-class');
13
-
14
- describe('GetIntegrationsForUser Use-Case', () => {
15
- let integrationRepository;
16
- let moduleRepository;
17
- let moduleFactory;
18
- let useCase;
19
-
20
- beforeEach(() => {
21
- integrationRepository = new TestIntegrationRepository();
22
- moduleRepository = new TestModuleRepository();
23
- moduleFactory = new TestModuleFactory();
24
- useCase = new GetIntegrationsForUser({
25
- integrationRepository,
26
- integrationClasses: [DummyIntegration],
27
- moduleFactory,
28
- moduleRepository,
29
- });
30
- });
31
-
32
- describe('happy path', () => {
33
- it('returns integrations dto list for single user', async () => {
34
- const entity = { id: 'entity-1' };
35
- moduleRepository.addEntity(entity);
36
-
37
- await integrationRepository.createIntegration([entity.id], 'user-1', { type: 'dummy' });
38
-
39
- const list = await useCase.execute('user-1');
40
- expect(list.length).toBe(1);
41
- expect(list[0].config.type).toBe('dummy');
42
- expect(list[0].userId).toBe('user-1');
43
- });
44
-
45
- it('returns multiple integrations for same user', async () => {
46
- const entity1 = { id: 'entity-1' };
47
- const entity2 = { id: 'entity-2' };
48
- moduleRepository.addEntity(entity1);
49
- moduleRepository.addEntity(entity2);
50
-
51
- await integrationRepository.createIntegration([entity1.id], 'user-1', { type: 'dummy', name: 'first' });
52
- await integrationRepository.createIntegration([entity2.id], 'user-1', { type: 'dummy', name: 'second' });
53
-
54
- const list = await useCase.execute('user-1');
55
- expect(list.length).toBe(2);
56
- expect(list[0].config.name).toBe('first');
57
- expect(list[1].config.name).toBe('second');
58
- });
59
-
60
- it('filters integrations by user correctly', async () => {
61
- const entity1 = { id: 'entity-1' };
62
- const entity2 = { id: 'entity-2' };
63
- moduleRepository.addEntity(entity1);
64
- moduleRepository.addEntity(entity2);
65
-
66
- await integrationRepository.createIntegration([entity1.id], 'user-1', { type: 'dummy', owner: 'user1' });
67
- await integrationRepository.createIntegration([entity2.id], 'user-2', { type: 'dummy', owner: 'user2' });
68
-
69
- const user1List = await useCase.execute('user-1');
70
- const user2List = await useCase.execute('user-2');
71
-
72
- expect(user1List.length).toBe(1);
73
- expect(user2List.length).toBe(1);
74
- expect(user1List[0].config.owner).toBe('user1');
75
- expect(user2List[0].config.owner).toBe('user2');
76
- });
77
-
78
- it('returns empty array when user has no integrations', async () => {
79
- const entity = { id: 'entity-1' };
80
- moduleRepository.addEntity(entity);
81
-
82
- await integrationRepository.createIntegration([entity.id], 'user-1', { type: 'dummy' });
83
-
84
- const list = await useCase.execute('user-2');
85
- expect(list).toEqual([]);
86
- });
87
-
88
- it('tracks repository operations', async () => {
89
- const entity = { id: 'entity-1' };
90
- moduleRepository.addEntity(entity);
91
- await integrationRepository.createIntegration([entity.id], 'user-1', { type: 'dummy' });
92
- integrationRepository.clearHistory();
93
-
94
- await useCase.execute('user-1');
95
-
96
- const history = integrationRepository.getOperationHistory();
97
- const findOperation = history.find(op => op.operation === 'findByUserId');
98
- expect(findOperation).toEqual({
99
- operation: 'findByUserId',
100
- userId: 'user-1',
101
- count: 1
102
- });
103
- });
104
- });
105
-
106
- describe('error cases', () => {
107
- it('throws error when integration class not found', async () => {
108
- const useCaseWithoutClasses = new GetIntegrationsForUser({
109
- integrationRepository,
110
- integrationClasses: [],
111
- moduleFactory,
112
- moduleRepository,
113
- });
114
-
115
- const entity = { id: 'entity-1' };
116
- moduleRepository.addEntity(entity);
117
- await integrationRepository.createIntegration([entity.id], 'user-1', { type: 'dummy' });
118
-
119
- await expect(useCaseWithoutClasses.execute('user-1'))
120
- .rejects
121
- .toThrow();
122
- });
123
-
124
- it('handles missing entities gracefully', async () => {
125
- await integrationRepository.createIntegration(['missing-entity'], 'user-1', { type: 'dummy' });
126
-
127
- await expect(useCase.execute('user-1'))
128
- .rejects
129
- .toThrow();
130
- });
131
- });
132
-
133
- describe('edge cases', () => {
134
- it('handles user with null/undefined userId', async () => {
135
- const list1 = await useCase.execute(null);
136
- const list2 = await useCase.execute(undefined);
137
-
138
- expect(list1).toEqual([]);
139
- expect(list2).toEqual([]);
140
- });
141
-
142
- it('handles integrations with complex configs', async () => {
143
- const entity = { id: 'entity-1' };
144
- moduleRepository.addEntity(entity);
145
-
146
- const complexConfig = {
147
- type: 'dummy',
148
- settings: {
149
- nested: { deep: 'value' },
150
- array: [1, 2, 3],
151
- boolean: true,
152
- nullValue: null
153
- }
154
- };
155
-
156
- await integrationRepository.createIntegration([entity.id], 'user-1', complexConfig);
157
-
158
- const list = await useCase.execute('user-1');
159
- expect(list[0].config).toEqual(complexConfig);
160
- });
161
-
162
- it('handles integrations with multiple entities', async () => {
163
- const entity1 = { id: 'entity-1' };
164
- const entity2 = { id: 'entity-2' };
165
- const entity3 = { id: 'entity-3' };
166
- moduleRepository.addEntity(entity1);
167
- moduleRepository.addEntity(entity2);
168
- moduleRepository.addEntity(entity3);
169
-
170
- await integrationRepository.createIntegration([entity1.id, entity2.id, entity3.id], 'user-1', { type: 'dummy' });
171
-
172
- const list = await useCase.execute('user-1');
173
- expect(list[0].entities).toEqual([entity1, entity2, entity3]);
174
- });
175
- });
176
- });