@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.
Files changed (163) hide show
  1. package/README.md +28 -0
  2. package/application/commands/integration-commands.js +19 -0
  3. package/core/Worker.js +8 -21
  4. package/credential/repositories/credential-repository-mongo.js +14 -8
  5. package/credential/repositories/credential-repository-postgres.js +14 -8
  6. package/credential/repositories/credential-repository.js +3 -8
  7. package/database/MONGODB_TRANSACTION_FIX.md +198 -0
  8. package/database/adapters/lambda-invoker.js +97 -0
  9. package/database/config.js +11 -2
  10. package/database/models/WebsocketConnection.js +11 -10
  11. package/database/prisma.js +63 -3
  12. package/database/repositories/health-check-repository-mongodb.js +3 -0
  13. package/database/repositories/migration-status-repository-s3.js +137 -0
  14. package/database/use-cases/check-database-state-use-case.js +81 -0
  15. package/database/use-cases/check-encryption-health-use-case.js +3 -2
  16. package/database/use-cases/get-database-state-via-worker-use-case.js +61 -0
  17. package/database/use-cases/get-migration-status-use-case.js +93 -0
  18. package/database/use-cases/run-database-migration-use-case.js +137 -0
  19. package/database/use-cases/trigger-database-migration-use-case.js +157 -0
  20. package/database/utils/mongodb-collection-utils.js +91 -0
  21. package/database/utils/mongodb-schema-init.js +106 -0
  22. package/database/utils/prisma-runner.js +400 -0
  23. package/database/utils/prisma-schema-parser.js +182 -0
  24. package/encrypt/Cryptor.js +14 -16
  25. package/generated/prisma-mongodb/client.d.ts +1 -0
  26. package/generated/prisma-mongodb/client.js +4 -0
  27. package/generated/prisma-mongodb/default.d.ts +1 -0
  28. package/generated/prisma-mongodb/default.js +4 -0
  29. package/generated/prisma-mongodb/edge.d.ts +1 -0
  30. package/generated/prisma-mongodb/edge.js +334 -0
  31. package/generated/prisma-mongodb/index-browser.js +316 -0
  32. package/generated/prisma-mongodb/index.d.ts +22897 -0
  33. package/generated/prisma-mongodb/index.js +359 -0
  34. package/generated/prisma-mongodb/package.json +183 -0
  35. package/generated/prisma-mongodb/query-engine-debian-openssl-3.0.x +0 -0
  36. package/generated/prisma-mongodb/query-engine-rhel-openssl-3.0.x +0 -0
  37. package/generated/prisma-mongodb/runtime/binary.d.ts +1 -0
  38. package/generated/prisma-mongodb/runtime/binary.js +289 -0
  39. package/generated/prisma-mongodb/runtime/edge-esm.js +34 -0
  40. package/generated/prisma-mongodb/runtime/edge.js +34 -0
  41. package/generated/prisma-mongodb/runtime/index-browser.d.ts +370 -0
  42. package/generated/prisma-mongodb/runtime/index-browser.js +16 -0
  43. package/generated/prisma-mongodb/runtime/library.d.ts +3977 -0
  44. package/generated/prisma-mongodb/runtime/react-native.js +83 -0
  45. package/generated/prisma-mongodb/runtime/wasm-compiler-edge.js +84 -0
  46. package/generated/prisma-mongodb/runtime/wasm-engine-edge.js +36 -0
  47. package/generated/prisma-mongodb/schema.prisma +362 -0
  48. package/generated/prisma-mongodb/wasm-edge-light-loader.mjs +4 -0
  49. package/generated/prisma-mongodb/wasm-worker-loader.mjs +4 -0
  50. package/generated/prisma-mongodb/wasm.d.ts +1 -0
  51. package/generated/prisma-mongodb/wasm.js +341 -0
  52. package/generated/prisma-postgresql/client.d.ts +1 -0
  53. package/generated/prisma-postgresql/client.js +4 -0
  54. package/generated/prisma-postgresql/default.d.ts +1 -0
  55. package/generated/prisma-postgresql/default.js +4 -0
  56. package/generated/prisma-postgresql/edge.d.ts +1 -0
  57. package/generated/prisma-postgresql/edge.js +356 -0
  58. package/generated/prisma-postgresql/index-browser.js +338 -0
  59. package/generated/prisma-postgresql/index.d.ts +25071 -0
  60. package/generated/prisma-postgresql/index.js +381 -0
  61. package/generated/prisma-postgresql/package.json +183 -0
  62. package/generated/prisma-postgresql/query-engine-debian-openssl-3.0.x +0 -0
  63. package/generated/prisma-postgresql/query-engine-rhel-openssl-3.0.x +0 -0
  64. package/generated/prisma-postgresql/query_engine_bg.js +2 -0
  65. package/generated/prisma-postgresql/query_engine_bg.wasm +0 -0
  66. package/generated/prisma-postgresql/runtime/binary.d.ts +1 -0
  67. package/generated/prisma-postgresql/runtime/binary.js +289 -0
  68. package/generated/prisma-postgresql/runtime/edge-esm.js +34 -0
  69. package/generated/prisma-postgresql/runtime/edge.js +34 -0
  70. package/generated/prisma-postgresql/runtime/index-browser.d.ts +370 -0
  71. package/generated/prisma-postgresql/runtime/index-browser.js +16 -0
  72. package/generated/prisma-postgresql/runtime/library.d.ts +3977 -0
  73. package/generated/prisma-postgresql/runtime/react-native.js +83 -0
  74. package/generated/prisma-postgresql/runtime/wasm-compiler-edge.js +84 -0
  75. package/generated/prisma-postgresql/runtime/wasm-engine-edge.js +36 -0
  76. package/generated/prisma-postgresql/schema.prisma +345 -0
  77. package/generated/prisma-postgresql/wasm-edge-light-loader.mjs +4 -0
  78. package/generated/prisma-postgresql/wasm-worker-loader.mjs +4 -0
  79. package/generated/prisma-postgresql/wasm.d.ts +1 -0
  80. package/generated/prisma-postgresql/wasm.js +363 -0
  81. package/handlers/database-migration-handler.js +227 -0
  82. package/handlers/routers/auth.js +1 -1
  83. package/handlers/routers/db-migration.handler.js +29 -0
  84. package/handlers/routers/db-migration.js +256 -0
  85. package/handlers/routers/health.js +41 -6
  86. package/handlers/routers/integration-webhook-routers.js +2 -2
  87. package/handlers/use-cases/check-integrations-health-use-case.js +22 -10
  88. package/handlers/workers/db-migration.js +352 -0
  89. package/index.js +12 -0
  90. package/integrations/integration-router.js +60 -70
  91. package/integrations/repositories/integration-repository-interface.js +12 -0
  92. package/integrations/repositories/integration-repository-mongo.js +32 -0
  93. package/integrations/repositories/integration-repository-postgres.js +33 -0
  94. package/integrations/repositories/process-repository-postgres.js +2 -2
  95. package/integrations/tests/doubles/test-integration-repository.js +2 -2
  96. package/logs/logger.js +0 -4
  97. package/modules/entity.js +0 -1
  98. package/modules/repositories/module-repository-mongo.js +3 -12
  99. package/modules/repositories/module-repository-postgres.js +0 -11
  100. package/modules/repositories/module-repository.js +1 -12
  101. package/modules/use-cases/get-entity-options-by-id.js +1 -1
  102. package/modules/use-cases/get-module.js +1 -2
  103. package/modules/use-cases/refresh-entity-options.js +1 -1
  104. package/modules/use-cases/test-module-auth.js +1 -1
  105. package/package.json +82 -66
  106. package/prisma-mongodb/schema.prisma +21 -21
  107. package/prisma-postgresql/schema.prisma +15 -15
  108. package/queues/queuer-util.js +24 -21
  109. package/types/core/index.d.ts +2 -2
  110. package/types/module-plugin/index.d.ts +0 -2
  111. package/user/use-cases/authenticate-user.js +127 -0
  112. package/user/use-cases/authenticate-with-shared-secret.js +48 -0
  113. package/user/use-cases/get-user-from-adopter-jwt.js +149 -0
  114. package/user/use-cases/get-user-from-x-frigg-headers.js +106 -0
  115. package/user/user.js +16 -0
  116. package/websocket/repositories/websocket-connection-repository-mongo.js +11 -10
  117. package/websocket/repositories/websocket-connection-repository-postgres.js +11 -10
  118. package/websocket/repositories/websocket-connection-repository.js +11 -10
  119. package/application/commands/integration-commands.test.js +0 -123
  120. package/database/encryption/encryption-integration.test.js +0 -553
  121. package/database/encryption/encryption-schema-registry.test.js +0 -392
  122. package/database/encryption/field-encryption-service.test.js +0 -525
  123. package/database/encryption/mongo-decryption-fix-verification.test.js +0 -348
  124. package/database/encryption/postgres-decryption-fix-verification.test.js +0 -371
  125. package/database/encryption/postgres-relation-decryption.test.js +0 -245
  126. package/database/encryption/prisma-encryption-extension.test.js +0 -439
  127. package/errors/base-error.test.js +0 -32
  128. package/errors/fetch-error.test.js +0 -79
  129. package/errors/halt-error.test.js +0 -11
  130. package/errors/validation-errors.test.js +0 -120
  131. package/handlers/auth-flow.integration.test.js +0 -147
  132. package/handlers/integration-event-dispatcher.test.js +0 -209
  133. package/handlers/routers/health.test.js +0 -210
  134. package/handlers/routers/integration-webhook-routers.test.js +0 -126
  135. package/handlers/webhook-flow.integration.test.js +0 -356
  136. package/handlers/workers/integration-defined-workers.test.js +0 -184
  137. package/integrations/tests/use-cases/create-integration.test.js +0 -131
  138. package/integrations/tests/use-cases/delete-integration-for-user.test.js +0 -150
  139. package/integrations/tests/use-cases/find-integration-context-by-external-entity-id.test.js +0 -92
  140. package/integrations/tests/use-cases/get-integration-for-user.test.js +0 -150
  141. package/integrations/tests/use-cases/get-integration-instance.test.js +0 -176
  142. package/integrations/tests/use-cases/get-integrations-for-user.test.js +0 -176
  143. package/integrations/tests/use-cases/get-possible-integrations.test.js +0 -188
  144. package/integrations/tests/use-cases/update-integration-messages.test.js +0 -142
  145. package/integrations/tests/use-cases/update-integration-status.test.js +0 -103
  146. package/integrations/tests/use-cases/update-integration.test.js +0 -141
  147. package/integrations/use-cases/create-process.test.js +0 -178
  148. package/integrations/use-cases/get-process.test.js +0 -190
  149. package/integrations/use-cases/load-integration-context-full.test.js +0 -329
  150. package/integrations/use-cases/load-integration-context.test.js +0 -114
  151. package/integrations/use-cases/update-process-metrics.test.js +0 -308
  152. package/integrations/use-cases/update-process-state.test.js +0 -256
  153. package/lambda/TimeoutCatcher.test.js +0 -68
  154. package/logs/logger.test.js +0 -76
  155. package/modules/module-hydration.test.js +0 -205
  156. package/modules/requester/requester.test.js +0 -28
  157. package/user/tests/use-cases/create-individual-user.test.js +0 -24
  158. package/user/tests/use-cases/create-organization-user.test.js +0 -28
  159. package/user/tests/use-cases/create-token-for-user-id.test.js +0 -19
  160. package/user/tests/use-cases/get-user-from-bearer-token.test.js +0 -64
  161. package/user/tests/use-cases/login-user.test.js +0 -220
  162. package/user/tests/user-password-encryption-isolation.test.js +0 -237
  163. package/user/tests/user-password-hashing.test.js +0 -235
@@ -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
- });
@@ -1,188 +0,0 @@
1
- const { GetPossibleIntegrations } = require('../../use-cases/get-possible-integrations');
2
- const { DummyIntegration } = require('../doubles/dummy-integration-class');
3
-
4
- describe('GetPossibleIntegrations Use-Case', () => {
5
- describe('happy path', () => {
6
- it('returns option details array for single integration', async () => {
7
- const useCase = new GetPossibleIntegrations({ integrationClasses: [DummyIntegration] });
8
- const result = await useCase.execute();
9
-
10
- expect(Array.isArray(result)).toBe(true);
11
- expect(result.length).toBe(1);
12
- expect(result[0].display).toBeDefined();
13
- expect(result[0].display.label).toBe('Dummy Integration');
14
- expect(result[0].display.description).toBe('A dummy integration for testing');
15
- expect(result[0].name).toBe('dummy');
16
- expect(result[0].version).toBe('1.0.0');
17
- });
18
-
19
- it('returns multiple integration options', async () => {
20
- class AnotherDummyIntegration {
21
- static Definition = {
22
- name: 'another-dummy',
23
- version: '2.0.0',
24
- modules: { dummy: {} },
25
- display: {
26
- label: 'Another Dummy',
27
- description: 'Another test integration',
28
- detailsUrl: 'https://another.example.com',
29
- icon: 'another-icon'
30
- }
31
- };
32
-
33
- static getOptionDetails() {
34
- return {
35
- name: this.Definition.name,
36
- version: this.Definition.version,
37
- display: this.Definition.display
38
- };
39
- }
40
- }
41
-
42
- const useCase = new GetPossibleIntegrations({
43
- integrationClasses: [DummyIntegration, AnotherDummyIntegration]
44
- });
45
- const result = await useCase.execute();
46
-
47
- expect(result.length).toBe(2);
48
- expect(result[0].name).toBe('dummy');
49
- expect(result[1].name).toBe('another-dummy');
50
- });
51
-
52
- it('includes all required display properties', async () => {
53
- const useCase = new GetPossibleIntegrations({ integrationClasses: [DummyIntegration] });
54
- const result = await useCase.execute();
55
-
56
- const integration = result[0];
57
- expect(integration.display.label).toBeDefined();
58
- expect(integration.display.description).toBeDefined();
59
- expect(integration.display.detailsUrl).toBeDefined();
60
- expect(integration.display.icon).toBeDefined();
61
- });
62
- });
63
-
64
- describe('error cases', () => {
65
- it('returns empty array when no integration classes provided', async () => {
66
- const useCase = new GetPossibleIntegrations({ integrationClasses: [] });
67
- const result = await useCase.execute();
68
-
69
- expect(Array.isArray(result)).toBe(true);
70
- expect(result.length).toBe(0);
71
- });
72
-
73
- it('handles integration class without getOptionDetails method', async () => {
74
- class InvalidIntegration {
75
- static Definition = { name: 'invalid' };
76
- }
77
-
78
- const useCase = new GetPossibleIntegrations({ integrationClasses: [InvalidIntegration] });
79
-
80
- await expect(useCase.execute()).rejects.toThrow();
81
- });
82
-
83
- it('handles integration class with incomplete Definition', async () => {
84
- class IncompleteIntegration {
85
- static Definition = {
86
- name: 'incomplete',
87
- modules: { dummy: {} }
88
- };
89
-
90
- static getOptionDetails() {
91
- return {
92
- name: this.Definition.name,
93
- version: this.Definition.version,
94
- display: this.Definition.display
95
- };
96
- }
97
- }
98
-
99
- const useCase = new GetPossibleIntegrations({ integrationClasses: [IncompleteIntegration] });
100
- const result = await useCase.execute();
101
-
102
- expect(result.length).toBe(1);
103
- expect(result[0].name).toBe('incomplete');
104
- expect(result[0].display).toBeUndefined();
105
- });
106
- });
107
-
108
- describe('edge cases', () => {
109
- it('handles null integrationClasses parameter', async () => {
110
- const useCase = new GetPossibleIntegrations({ integrationClasses: null });
111
-
112
- await expect(useCase.execute()).rejects.toThrow();
113
- });
114
-
115
- it('handles undefined integrationClasses parameter', async () => {
116
- const useCase = new GetPossibleIntegrations({ integrationClasses: undefined });
117
-
118
- await expect(useCase.execute()).rejects.toThrow();
119
- });
120
-
121
- it('filters out null/undefined integration classes', async () => {
122
- const useCase = new GetPossibleIntegrations({
123
- integrationClasses: [DummyIntegration, null, undefined].filter(Boolean)
124
- });
125
- const result = await useCase.execute();
126
-
127
- expect(result.length).toBe(1);
128
- expect(result[0].name).toBe('dummy');
129
- });
130
-
131
- it('handles integration with complex display properties', async () => {
132
- class ComplexIntegration {
133
- static Definition = {
134
- name: 'complex',
135
- version: '3.0.0',
136
- modules: { dummy: {} },
137
- display: {
138
- label: 'Complex Integration with Special Characters! 🚀',
139
- description: 'A very long description that includes\nnewlines and\ttabs and special characters like émojis 🎉',
140
- detailsUrl: 'https://complex.example.com/with/path?param=value&other=123',
141
- icon: 'data:image/svg+xml;base64,PHN2Zz48L3N2Zz4=',
142
- category: 'Test & Development',
143
- tags: ['testing', 'development', 'complex']
144
- }
145
- };
146
-
147
- static getOptionDetails() {
148
- return {
149
- name: this.Definition.name,
150
- version: this.Definition.version,
151
- display: this.Definition.display
152
- };
153
- }
154
- }
155
-
156
- const useCase = new GetPossibleIntegrations({ integrationClasses: [ComplexIntegration] });
157
- const result = await useCase.execute();
158
-
159
- expect(result[0].display.label).toContain('🚀');
160
- expect(result[0].display.description).toContain('🎉');
161
- expect(result[0].display.detailsUrl).toContain('?param=value');
162
- });
163
-
164
- it('preserves integration class order', async () => {
165
- class FirstIntegration {
166
- static Definition = { name: 'first', version: '1.0.0', modules: { dummy: {} }, display: { label: 'First' } };
167
- static getOptionDetails() { return { name: this.Definition.name, version: this.Definition.version, display: this.Definition.display }; }
168
- }
169
- class SecondIntegration {
170
- static Definition = { name: 'second', version: '1.0.0', modules: { dummy: {} }, display: { label: 'Second' } };
171
- static getOptionDetails() { return { name: this.Definition.name, version: this.Definition.version, display: this.Definition.display }; }
172
- }
173
- class ThirdIntegration {
174
- static Definition = { name: 'third', version: '1.0.0', modules: { dummy: {} }, display: { label: 'Third' } };
175
- static getOptionDetails() { return { name: this.Definition.name, version: this.Definition.version, display: this.Definition.display }; }
176
- }
177
-
178
- const useCase = new GetPossibleIntegrations({
179
- integrationClasses: [FirstIntegration, SecondIntegration, ThirdIntegration]
180
- });
181
- const result = await useCase.execute();
182
-
183
- expect(result[0].name).toBe('first');
184
- expect(result[1].name).toBe('second');
185
- expect(result[2].name).toBe('third');
186
- });
187
- });
188
- });
@@ -1,142 +0,0 @@
1
- const { UpdateIntegrationMessages } = require('../../use-cases/update-integration-messages');
2
- const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
3
-
4
- describe('UpdateIntegrationMessages Use-Case', () => {
5
- let integrationRepository;
6
- let useCase;
7
-
8
- beforeEach(() => {
9
- integrationRepository = new TestIntegrationRepository();
10
- useCase = new UpdateIntegrationMessages({ integrationRepository });
11
- });
12
-
13
- describe('happy path', () => {
14
- it('adds message with correct details', async () => {
15
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy' });
16
- const timestamp = Date.now();
17
-
18
- await useCase.execute(record.id, 'errors', 'Test Error', 'Error details here', timestamp);
19
-
20
- const fetched = await integrationRepository.findIntegrationById(record.id);
21
- expect(fetched.messages.errors.length).toBe(1);
22
- expect(fetched.messages.errors[0]).toEqual({
23
- title: 'Test Error',
24
- message: 'Error details here',
25
- timestamp: timestamp
26
- });
27
- });
28
-
29
- it('adds multiple messages to same type', async () => {
30
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy' });
31
-
32
- await useCase.execute(record.id, 'errors', 'Error 1', 'First error', 1000);
33
- await useCase.execute(record.id, 'errors', 'Error 2', 'Second error', 2000);
34
-
35
- const fetched = await integrationRepository.findIntegrationById(record.id);
36
- expect(fetched.messages.errors.length).toBe(2);
37
- expect(fetched.messages.errors[0].title).toBe('Error 1');
38
- expect(fetched.messages.errors[1].title).toBe('Error 2');
39
- });
40
-
41
- it('adds messages to different types', async () => {
42
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy' });
43
-
44
- await useCase.execute(record.id, 'errors', 'Error Title', 'Error body', 1000);
45
- await useCase.execute(record.id, 'warnings', 'Warning Title', 'Warning body', 2000);
46
- await useCase.execute(record.id, 'info', 'Info Title', 'Info body', 3000);
47
-
48
- const fetched = await integrationRepository.findIntegrationById(record.id);
49
- expect(fetched.messages.errors.length).toBe(1);
50
- expect(fetched.messages.warnings.length).toBe(1);
51
- expect(fetched.messages.info.length).toBe(1);
52
- });
53
-
54
- it('tracks message update operation', async () => {
55
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy' });
56
- integrationRepository.clearHistory();
57
-
58
- await useCase.execute(record.id, 'logs', 'Log Entry', 'Log details', Date.now());
59
-
60
- const history = integrationRepository.getOperationHistory();
61
- const updateOperation = history.find(op => op.operation === 'updateMessages');
62
- expect(updateOperation).toEqual({
63
- operation: 'updateMessages',
64
- id: record.id,
65
- type: 'logs',
66
- success: true
67
- });
68
- });
69
- });
70
-
71
- describe('error cases', () => {
72
- it('returns false when integration not found', async () => {
73
- const nonExistentId = 'non-existent-id';
74
-
75
- const result = await useCase.execute(nonExistentId, 'errors', 'title', 'body', Date.now());
76
-
77
- expect(result).toBe(false);
78
- });
79
-
80
- it('tracks failed message update operation', async () => {
81
- const nonExistentId = 'non-existent-id';
82
- integrationRepository.clearHistory();
83
-
84
- await useCase.execute(nonExistentId, 'errors', 'title', 'body', Date.now());
85
-
86
- const history = integrationRepository.getOperationHistory();
87
- const updateOperation = history.find(op => op.operation === 'updateMessages');
88
- expect(updateOperation).toEqual({
89
- operation: 'updateMessages',
90
- id: nonExistentId,
91
- success: false
92
- });
93
- });
94
- });
95
-
96
- describe('edge cases', () => {
97
- it('handles empty title and body', async () => {
98
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy' });
99
-
100
- await useCase.execute(record.id, 'info', '', '', Date.now());
101
-
102
- const fetched = await integrationRepository.findIntegrationById(record.id);
103
- expect(fetched.messages.info[0].title).toBe('');
104
- expect(fetched.messages.info[0].message).toBe('');
105
- });
106
-
107
- it('handles null and undefined values', async () => {
108
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy' });
109
-
110
- await useCase.execute(record.id, 'warnings', null, undefined, null);
111
-
112
- const fetched = await integrationRepository.findIntegrationById(record.id);
113
- expect(fetched.messages.warnings[0].title).toBeNull();
114
- expect(fetched.messages.warnings[0].message).toBeUndefined();
115
- expect(fetched.messages.warnings[0].timestamp).toBeNull();
116
- });
117
-
118
- it('handles very long message content', async () => {
119
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy' });
120
- const longTitle = 'A'.repeat(1000);
121
- const longBody = 'B'.repeat(5000);
122
-
123
- await useCase.execute(record.id, 'errors', longTitle, longBody, Date.now());
124
-
125
- const fetched = await integrationRepository.findIntegrationById(record.id);
126
- expect(fetched.messages.errors[0].title).toBe(longTitle);
127
- expect(fetched.messages.errors[0].message).toBe(longBody);
128
- });
129
-
130
- it('handles special characters in messages', async () => {
131
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy' });
132
- const specialTitle = '🚨 Error with émojis & spëcial chars';
133
- const specialBody = 'Body with\nnewlines\tand\ttabs';
134
-
135
- await useCase.execute(record.id, 'errors', specialTitle, specialBody, Date.now());
136
-
137
- const fetched = await integrationRepository.findIntegrationById(record.id);
138
- expect(fetched.messages.errors[0].title).toBe(specialTitle);
139
- expect(fetched.messages.errors[0].message).toBe(specialBody);
140
- });
141
- });
142
- });
@@ -1,103 +0,0 @@
1
- const { UpdateIntegrationStatus } = require('../../use-cases/update-integration-status');
2
- const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
3
-
4
- describe('UpdateIntegrationStatus Use-Case', () => {
5
- let integrationRepository;
6
- let useCase;
7
-
8
- beforeEach(() => {
9
- integrationRepository = new TestIntegrationRepository();
10
- useCase = new UpdateIntegrationStatus({
11
- integrationRepository,
12
- });
13
- });
14
-
15
- describe('happy path', () => {
16
- it('updates integration status', async () => {
17
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
18
-
19
- const result = await useCase.execute(record.id, 'ACTIVE');
20
-
21
- expect(result).toBe(true);
22
-
23
- const updatedRecord = await integrationRepository.findIntegrationById(record.id);
24
- expect(updatedRecord.status).toBe('ACTIVE');
25
- });
26
-
27
- it('tracks status update operation', async () => {
28
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
29
- integrationRepository.clearHistory();
30
-
31
- await useCase.execute(record.id, 'PAUSED');
32
-
33
- const history = integrationRepository.getOperationHistory();
34
- const updateOperation = history.find(op => op.operation === 'updateStatus');
35
- expect(updateOperation).toEqual({
36
- operation: 'updateStatus',
37
- id: record.id,
38
- status: 'PAUSED',
39
- success: true
40
- });
41
- });
42
-
43
- it('handles different status values', async () => {
44
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
45
-
46
- const statuses = ['ACTIVE', 'PAUSED', 'ERROR', 'DISABLED'];
47
-
48
- for (const status of statuses) {
49
- await useCase.execute(record.id, status);
50
- const updatedRecord = await integrationRepository.findIntegrationById(record.id);
51
- expect(updatedRecord.status).toBe(status);
52
- }
53
- });
54
- });
55
-
56
- describe('error cases', () => {
57
- it('returns false when integration not found', async () => {
58
- const nonExistentId = 'non-existent-id';
59
-
60
- const result = await useCase.execute(nonExistentId, 'ACTIVE');
61
-
62
- expect(result).toBe(false);
63
- });
64
-
65
- it('tracks failed update operation', async () => {
66
- const nonExistentId = 'non-existent-id';
67
- integrationRepository.clearHistory();
68
-
69
- await useCase.execute(nonExistentId, 'ACTIVE');
70
-
71
- const history = integrationRepository.getOperationHistory();
72
- const updateOperation = history.find(op => op.operation === 'updateStatus');
73
- expect(updateOperation).toEqual({
74
- operation: 'updateStatus',
75
- id: nonExistentId,
76
- status: 'ACTIVE',
77
- success: false
78
- });
79
- });
80
- });
81
-
82
- describe('edge cases', () => {
83
- it('handles null status value', async () => {
84
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
85
-
86
- const result = await useCase.execute(record.id, null);
87
-
88
- expect(result).toBe(true);
89
- const updatedRecord = await integrationRepository.findIntegrationById(record.id);
90
- expect(updatedRecord.status).toBeNull();
91
- });
92
-
93
- it('handles empty string status', async () => {
94
- const record = await integrationRepository.createIntegration(['entity-1'], 'user-1', { type: 'dummy' });
95
-
96
- const result = await useCase.execute(record.id, '');
97
-
98
- expect(result).toBe(true);
99
- const updatedRecord = await integrationRepository.findIntegrationById(record.id);
100
- expect(updatedRecord.status).toBe('');
101
- });
102
- });
103
- });