@friggframework/core 2.0.0--canary.461.61382d8.0 → 2.0.0--canary.461.3d6d8ad.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 (120) hide show
  1. package/database/use-cases/check-migration-status-use-case.js +81 -0
  2. package/generated/prisma-mongodb/client.d.ts +1 -0
  3. package/generated/prisma-mongodb/client.js +4 -0
  4. package/generated/prisma-mongodb/default.d.ts +1 -0
  5. package/generated/prisma-mongodb/default.js +4 -0
  6. package/generated/prisma-mongodb/edge.d.ts +1 -0
  7. package/generated/prisma-mongodb/edge.js +336 -0
  8. package/generated/prisma-mongodb/index-browser.js +318 -0
  9. package/generated/prisma-mongodb/index.d.ts +22993 -0
  10. package/generated/prisma-mongodb/index.js +361 -0
  11. package/generated/prisma-mongodb/package.json +183 -0
  12. package/generated/prisma-mongodb/query-engine-debian-openssl-3.0.x +0 -0
  13. package/generated/prisma-mongodb/query-engine-rhel-openssl-3.0.x +0 -0
  14. package/generated/prisma-mongodb/runtime/binary.d.ts +1 -0
  15. package/generated/prisma-mongodb/runtime/binary.js +289 -0
  16. package/generated/prisma-mongodb/runtime/edge-esm.js +34 -0
  17. package/generated/prisma-mongodb/runtime/edge.js +34 -0
  18. package/generated/prisma-mongodb/runtime/index-browser.d.ts +370 -0
  19. package/generated/prisma-mongodb/runtime/index-browser.js +16 -0
  20. package/generated/prisma-mongodb/runtime/library.d.ts +3977 -0
  21. package/generated/prisma-mongodb/runtime/react-native.js +83 -0
  22. package/generated/prisma-mongodb/runtime/wasm-compiler-edge.js +84 -0
  23. package/generated/prisma-mongodb/runtime/wasm-engine-edge.js +36 -0
  24. package/generated/prisma-mongodb/schema.prisma +364 -0
  25. package/generated/prisma-mongodb/wasm-edge-light-loader.mjs +4 -0
  26. package/generated/prisma-mongodb/wasm-worker-loader.mjs +4 -0
  27. package/generated/prisma-mongodb/wasm.d.ts +1 -0
  28. package/generated/prisma-mongodb/wasm.js +343 -0
  29. package/generated/prisma-postgresql/client.d.ts +1 -0
  30. package/generated/prisma-postgresql/client.js +4 -0
  31. package/generated/prisma-postgresql/default.d.ts +1 -0
  32. package/generated/prisma-postgresql/default.js +4 -0
  33. package/generated/prisma-postgresql/edge.d.ts +1 -0
  34. package/generated/prisma-postgresql/edge.js +358 -0
  35. package/generated/prisma-postgresql/index-browser.js +340 -0
  36. package/generated/prisma-postgresql/index.d.ts +25171 -0
  37. package/generated/prisma-postgresql/index.js +383 -0
  38. package/generated/prisma-postgresql/package.json +183 -0
  39. package/generated/prisma-postgresql/query-engine-debian-openssl-3.0.x +0 -0
  40. package/generated/prisma-postgresql/query-engine-rhel-openssl-3.0.x +0 -0
  41. package/generated/prisma-postgresql/query_engine_bg.js +2 -0
  42. package/generated/prisma-postgresql/query_engine_bg.wasm +0 -0
  43. package/generated/prisma-postgresql/runtime/binary.d.ts +1 -0
  44. package/generated/prisma-postgresql/runtime/binary.js +289 -0
  45. package/generated/prisma-postgresql/runtime/edge-esm.js +34 -0
  46. package/generated/prisma-postgresql/runtime/edge.js +34 -0
  47. package/generated/prisma-postgresql/runtime/index-browser.d.ts +370 -0
  48. package/generated/prisma-postgresql/runtime/index-browser.js +16 -0
  49. package/generated/prisma-postgresql/runtime/library.d.ts +3977 -0
  50. package/generated/prisma-postgresql/runtime/react-native.js +83 -0
  51. package/generated/prisma-postgresql/runtime/wasm-compiler-edge.js +84 -0
  52. package/generated/prisma-postgresql/runtime/wasm-engine-edge.js +36 -0
  53. package/generated/prisma-postgresql/schema.prisma +347 -0
  54. package/generated/prisma-postgresql/wasm-edge-light-loader.mjs +4 -0
  55. package/generated/prisma-postgresql/wasm-worker-loader.mjs +4 -0
  56. package/generated/prisma-postgresql/wasm.d.ts +1 -0
  57. package/generated/prisma-postgresql/wasm.js +365 -0
  58. package/handlers/routers/db-migration.js +52 -0
  59. package/package.json +5 -5
  60. package/application/commands/integration-commands.test.js +0 -123
  61. package/core/Worker.test.js +0 -159
  62. package/database/encryption/encryption-integration.test.js +0 -553
  63. package/database/encryption/encryption-schema-registry.test.js +0 -392
  64. package/database/encryption/field-encryption-service.test.js +0 -525
  65. package/database/encryption/mongo-decryption-fix-verification.test.js +0 -348
  66. package/database/encryption/postgres-decryption-fix-verification.test.js +0 -371
  67. package/database/encryption/postgres-relation-decryption.test.js +0 -245
  68. package/database/encryption/prisma-encryption-extension.test.js +0 -439
  69. package/database/repositories/migration-status-repository-s3.test.js +0 -158
  70. package/database/use-cases/check-encryption-health-use-case.test.js +0 -192
  71. package/database/use-cases/get-migration-status-use-case.test.js +0 -171
  72. package/database/use-cases/run-database-migration-use-case.test.js +0 -310
  73. package/database/use-cases/trigger-database-migration-use-case.test.js +0 -250
  74. package/database/utils/prisma-runner.test.js +0 -486
  75. package/encrypt/Cryptor.test.js +0 -144
  76. package/errors/base-error.test.js +0 -32
  77. package/errors/fetch-error.test.js +0 -79
  78. package/errors/halt-error.test.js +0 -11
  79. package/errors/validation-errors.test.js +0 -120
  80. package/handlers/auth-flow.integration.test.js +0 -147
  81. package/handlers/integration-event-dispatcher.test.js +0 -209
  82. package/handlers/routers/db-migration.test.js +0 -51
  83. package/handlers/routers/health.test.js +0 -210
  84. package/handlers/routers/integration-webhook-routers.test.js +0 -126
  85. package/handlers/use-cases/check-integrations-health-use-case.test.js +0 -125
  86. package/handlers/webhook-flow.integration.test.js +0 -356
  87. package/handlers/workers/db-migration.test.js +0 -50
  88. package/handlers/workers/integration-defined-workers.test.js +0 -184
  89. package/integrations/tests/integration-router-multi-auth.test.js +0 -369
  90. package/integrations/tests/use-cases/create-integration.test.js +0 -131
  91. package/integrations/tests/use-cases/delete-integration-for-user.test.js +0 -150
  92. package/integrations/tests/use-cases/find-integration-context-by-external-entity-id.test.js +0 -92
  93. package/integrations/tests/use-cases/get-integration-for-user.test.js +0 -150
  94. package/integrations/tests/use-cases/get-integration-instance.test.js +0 -176
  95. package/integrations/tests/use-cases/get-integrations-for-user.test.js +0 -176
  96. package/integrations/tests/use-cases/get-possible-integrations.test.js +0 -188
  97. package/integrations/tests/use-cases/update-integration-messages.test.js +0 -142
  98. package/integrations/tests/use-cases/update-integration-status.test.js +0 -103
  99. package/integrations/tests/use-cases/update-integration.test.js +0 -141
  100. package/integrations/use-cases/create-process.test.js +0 -178
  101. package/integrations/use-cases/get-process.test.js +0 -190
  102. package/integrations/use-cases/load-integration-context-full.test.js +0 -329
  103. package/integrations/use-cases/load-integration-context.test.js +0 -114
  104. package/integrations/use-cases/update-process-metrics.test.js +0 -308
  105. package/integrations/use-cases/update-process-state.test.js +0 -256
  106. package/lambda/TimeoutCatcher.test.js +0 -68
  107. package/logs/logger.test.js +0 -76
  108. package/modules/module-hydration.test.js +0 -205
  109. package/modules/requester/requester.test.js +0 -28
  110. package/queues/queuer-util.test.js +0 -132
  111. package/user/tests/use-cases/create-individual-user.test.js +0 -24
  112. package/user/tests/use-cases/create-organization-user.test.js +0 -28
  113. package/user/tests/use-cases/create-token-for-user-id.test.js +0 -19
  114. package/user/tests/use-cases/get-user-from-adopter-jwt.test.js +0 -113
  115. package/user/tests/use-cases/get-user-from-bearer-token.test.js +0 -64
  116. package/user/tests/use-cases/get-user-from-x-frigg-headers.test.js +0 -346
  117. package/user/tests/use-cases/login-user.test.js +0 -220
  118. package/user/tests/user-password-encryption-isolation.test.js +0 -237
  119. package/user/tests/user-password-hashing.test.js +0 -235
  120. package/websocket/repositories/websocket-connection-repository.test.js +0 -227
@@ -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
- });
@@ -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
- });