@friggframework/core 2.0.0--canary.397.e634da9.0 → 2.0.0--canary.398.ad248a6.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 (98) hide show
  1. package/README.md +50 -931
  2. package/core/create-handler.js +0 -1
  3. package/database/models/WebsocketConnection.js +5 -0
  4. package/handlers/app-handler-helpers.js +3 -0
  5. package/handlers/backend-utils.js +44 -42
  6. package/handlers/routers/auth.js +14 -3
  7. package/handlers/routers/integration-defined-routers.js +5 -8
  8. package/handlers/routers/middleware/loadUser.js +15 -0
  9. package/handlers/routers/middleware/requireLoggedInUser.js +12 -0
  10. package/handlers/routers/user.js +5 -25
  11. package/handlers/workers/integration-defined-workers.js +3 -6
  12. package/index.js +16 -1
  13. package/integrations/create-frigg-backend.js +31 -0
  14. package/integrations/index.js +5 -0
  15. package/integrations/integration-base.js +46 -142
  16. package/integrations/integration-factory.js +251 -0
  17. package/integrations/integration-router.js +178 -301
  18. package/integrations/integration-user.js +144 -0
  19. package/integrations/options.js +1 -1
  20. package/integrations/test/integration-base.test.js +144 -0
  21. package/module-plugin/auther.js +393 -0
  22. package/module-plugin/entity-manager.js +70 -0
  23. package/{modules → module-plugin}/index.js +8 -0
  24. package/module-plugin/manager.js +169 -0
  25. package/module-plugin/module-factory.js +61 -0
  26. package/{modules → module-plugin}/test/mock-api/api.js +3 -8
  27. package/{modules → module-plugin}/test/mock-api/definition.js +8 -12
  28. package/package.json +5 -5
  29. package/syncs/sync.js +1 -0
  30. package/types/integrations/index.d.ts +6 -2
  31. package/types/module-plugin/index.d.ts +56 -4
  32. package/types/syncs/index.d.ts +2 -0
  33. package/credential/credential-repository.js +0 -42
  34. package/credential/use-cases/get-credential-for-user.js +0 -21
  35. package/credential/use-cases/update-authentication-status.js +0 -15
  36. package/handlers/app-definition-loader.js +0 -38
  37. package/integrations/integration-repository.js +0 -80
  38. package/integrations/integration.js +0 -246
  39. package/integrations/tests/doubles/dummy-integration-class.js +0 -90
  40. package/integrations/tests/doubles/test-integration-repository.js +0 -89
  41. package/integrations/tests/use-cases/create-integration.test.js +0 -124
  42. package/integrations/tests/use-cases/delete-integration-for-user.test.js +0 -143
  43. package/integrations/tests/use-cases/get-integration-for-user.test.js +0 -143
  44. package/integrations/tests/use-cases/get-integration-instance.test.js +0 -169
  45. package/integrations/tests/use-cases/get-integrations-for-user.test.js +0 -169
  46. package/integrations/tests/use-cases/get-possible-integrations.test.js +0 -188
  47. package/integrations/tests/use-cases/update-integration-messages.test.js +0 -142
  48. package/integrations/tests/use-cases/update-integration-status.test.js +0 -103
  49. package/integrations/tests/use-cases/update-integration.test.js +0 -134
  50. package/integrations/use-cases/create-integration.js +0 -71
  51. package/integrations/use-cases/delete-integration-for-user.js +0 -72
  52. package/integrations/use-cases/get-integration-for-user.js +0 -78
  53. package/integrations/use-cases/get-integration-instance-by-definition.js +0 -67
  54. package/integrations/use-cases/get-integration-instance.js +0 -82
  55. package/integrations/use-cases/get-integrations-for-user.js +0 -76
  56. package/integrations/use-cases/get-possible-integrations.js +0 -27
  57. package/integrations/use-cases/index.js +0 -11
  58. package/integrations/use-cases/update-integration-messages.js +0 -31
  59. package/integrations/use-cases/update-integration-status.js +0 -28
  60. package/integrations/use-cases/update-integration.js +0 -91
  61. package/integrations/utils/map-integration-dto.js +0 -36
  62. package/modules/module-factory.js +0 -54
  63. package/modules/module-repository.js +0 -107
  64. package/modules/module.js +0 -221
  65. package/modules/tests/doubles/test-module-factory.js +0 -16
  66. package/modules/tests/doubles/test-module-repository.js +0 -19
  67. package/modules/use-cases/get-entities-for-user.js +0 -32
  68. package/modules/use-cases/get-entity-options-by-id.js +0 -58
  69. package/modules/use-cases/get-entity-options-by-type.js +0 -34
  70. package/modules/use-cases/get-module-instance-from-type.js +0 -31
  71. package/modules/use-cases/get-module.js +0 -56
  72. package/modules/use-cases/process-authorization-callback.js +0 -114
  73. package/modules/use-cases/refresh-entity-options.js +0 -58
  74. package/modules/use-cases/test-module-auth.js +0 -54
  75. package/modules/utils/map-module-dto.js +0 -18
  76. package/user/tests/doubles/test-user-repository.js +0 -72
  77. package/user/tests/use-cases/create-individual-user.test.js +0 -24
  78. package/user/tests/use-cases/create-organization-user.test.js +0 -28
  79. package/user/tests/use-cases/create-token-for-user-id.test.js +0 -19
  80. package/user/tests/use-cases/get-user-from-bearer-token.test.js +0 -64
  81. package/user/tests/use-cases/login-user.test.js +0 -140
  82. package/user/use-cases/create-individual-user.js +0 -61
  83. package/user/use-cases/create-organization-user.js +0 -47
  84. package/user/use-cases/create-token-for-user-id.js +0 -30
  85. package/user/use-cases/get-user-from-bearer-token.js +0 -77
  86. package/user/use-cases/login-user.js +0 -122
  87. package/user/user-repository.js +0 -62
  88. package/user/user.js +0 -77
  89. /package/{modules → module-plugin}/ModuleConstants.js +0 -0
  90. /package/{modules → module-plugin}/credential.js +0 -0
  91. /package/{modules → module-plugin}/entity.js +0 -0
  92. /package/{modules → module-plugin}/requester/api-key.js +0 -0
  93. /package/{modules → module-plugin}/requester/basic.js +0 -0
  94. /package/{modules → module-plugin}/requester/oauth-2.js +0 -0
  95. /package/{modules → module-plugin}/requester/requester.js +0 -0
  96. /package/{modules → module-plugin}/requester/requester.test.js +0 -0
  97. /package/{modules → module-plugin}/test/auther.test.js +0 -0
  98. /package/{modules → module-plugin}/test/mock-api/mocks/hubspot.js +0 -0
@@ -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,134 +0,0 @@
1
- const { UpdateIntegration } = require('../../use-cases/update-integration');
2
- const { TestIntegrationRepository } = require('../doubles/test-integration-repository');
3
- const { TestModuleFactory } = require('../../../modules/tests/doubles/test-module-factory');
4
- const { DummyIntegration } = require('../doubles/dummy-integration-class');
5
-
6
- describe('UpdateIntegration Use-Case', () => {
7
- let integrationRepository;
8
- let moduleFactory;
9
- let useCase;
10
-
11
- beforeEach(() => {
12
- integrationRepository = new TestIntegrationRepository();
13
- moduleFactory = new TestModuleFactory();
14
- useCase = new UpdateIntegration({
15
- integrationRepository,
16
- integrationClasses: [DummyIntegration],
17
- moduleFactory,
18
- });
19
- });
20
-
21
- describe('happy path', () => {
22
- it('calls on update and returns dto', async () => {
23
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy', foo: 'bar' });
24
-
25
- const newConfig = { type: 'dummy', foo: 'baz' };
26
- const dto = await useCase.execute(record.id, 'user-1', newConfig);
27
-
28
- expect(dto.config.foo).toBe('baz');
29
- expect(dto.id).toBe(record.id);
30
- expect(dto.userId).toBe('user-1');
31
- });
32
-
33
- it('triggers ON_UPDATE event with correct payload', async () => {
34
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy', foo: 'bar' });
35
- integrationRepository.clearHistory();
36
-
37
- const newConfig = { type: 'dummy', foo: 'updated' };
38
- await useCase.execute(record.id, 'user-1', newConfig);
39
-
40
- const history = integrationRepository.getOperationHistory();
41
- const findOperation = history.find(op => op.operation === 'findById');
42
- expect(findOperation).toEqual({
43
- operation: 'findById',
44
- id: record.id,
45
- found: true
46
- });
47
- });
48
-
49
- it('updates integration with multiple entities', async () => {
50
- const record = await integrationRepository.createIntegration(['e1', 'e2'], 'user-1', { type: 'dummy' });
51
-
52
- const newConfig = { type: 'dummy', updated: true };
53
- const dto = await useCase.execute(record.id, 'user-1', newConfig);
54
-
55
- expect(dto.entities).toEqual(['e1', 'e2']);
56
- expect(dto.config.updated).toBe(true);
57
- });
58
- });
59
-
60
- describe('error cases', () => {
61
- it('throws error when integration not found', async () => {
62
- const nonExistentId = 'non-existent-id';
63
- const newConfig = { type: 'dummy', foo: 'baz' };
64
-
65
- await expect(useCase.execute(nonExistentId, 'user-1', newConfig))
66
- .rejects
67
- .toThrow(`No integration found by the ID of ${nonExistentId}`);
68
- });
69
-
70
- it('throws error when integration class not found', async () => {
71
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'unknown-type' });
72
-
73
- const newConfig = { type: 'unknown-type', foo: 'baz' };
74
-
75
- await expect(useCase.execute(record.id, 'user-1', newConfig))
76
- .rejects
77
- .toThrow('No integration class found for type: unknown-type');
78
- });
79
-
80
- it('throws error when user does not own integration', async () => {
81
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy' });
82
-
83
- const newConfig = { type: 'dummy', foo: 'baz' };
84
-
85
- await expect(useCase.execute(record.id, 'different-user', newConfig))
86
- .rejects
87
- .toThrow(`Integration ${record.id} does not belong to User different-user`);
88
- });
89
-
90
- it('throws error when no integration classes provided', async () => {
91
- const useCaseWithoutClasses = new UpdateIntegration({
92
- integrationRepository,
93
- integrationClasses: [],
94
- moduleFactory,
95
- });
96
-
97
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy' });
98
- const newConfig = { type: 'dummy', foo: 'baz' };
99
-
100
- await expect(useCaseWithoutClasses.execute(record.id, 'user-1', newConfig))
101
- .rejects
102
- .toThrow('No integration class found for type: dummy');
103
- });
104
- });
105
-
106
- describe('edge cases', () => {
107
- it('handles config with null values', async () => {
108
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy', foo: 'bar' });
109
-
110
- const newConfig = { type: 'dummy', foo: null, bar: undefined };
111
- const dto = await useCase.execute(record.id, 'user-1', newConfig);
112
-
113
- expect(dto.config.foo).toBeNull();
114
- expect(dto.config.bar).toBeUndefined();
115
- });
116
-
117
- it('handles deeply nested config updates', async () => {
118
- const record = await integrationRepository.createIntegration(['e1'], 'user-1', { type: 'dummy', nested: { old: 'value' } });
119
-
120
- const newConfig = {
121
- type: 'dummy',
122
- nested: {
123
- new: 'value',
124
- deep: { level: 'test' }
125
- }
126
- };
127
- const dto = await useCase.execute(record.id, 'user-1', newConfig);
128
-
129
- expect(dto.config.nested.new).toBe('value');
130
- expect(dto.config.nested.deep.level).toBe('test');
131
- expect(dto.config.nested.old).toBeUndefined();
132
- });
133
- });
134
- });
@@ -1,71 +0,0 @@
1
- // Removed Integration wrapper - using IntegrationBase directly
2
- const { mapIntegrationClassToIntegrationDTO } = require('../utils/map-integration-dto');
3
-
4
- /**
5
- * Use case for creating a new integration instance.
6
- * @class CreateIntegration
7
- */
8
- class CreateIntegration {
9
- /**
10
- * Creates a new CreateIntegration instance.
11
- * @param {Object} params - Configuration parameters.
12
- * @param {import('../integration-repository').IntegrationRepository} params.integrationRepository - Repository for integration data operations.
13
- * @param {import('../integration-classes').IntegrationClasses} params.integrationClasses - Array of available integration classes.
14
- * @param {import('../../modules/module-factory').ModuleFactory} params.moduleFactory - Service for module instantiation and management.
15
- */
16
- constructor({ integrationRepository, integrationClasses, moduleFactory }) {
17
- this.integrationRepository = integrationRepository;
18
- this.integrationClasses = integrationClasses;
19
- this.moduleFactory = moduleFactory;
20
- }
21
-
22
- /**
23
- * Executes the integration creation process.
24
- * @async
25
- * @param {string[]} entities - Array of entity IDs to associate with the integration.
26
- * @param {string} userId - ID of the user creating the integration.
27
- * @param {Object} config - Configuration object for the integration.
28
- * @param {string} config.type - Type of integration to create.
29
- * @returns {Promise<Object>} The created integration DTO.
30
- * @throws {Error} When integration class is not found for the specified type.
31
- */
32
- async execute(entities, userId, config) {
33
- const integrationRecord = await this.integrationRepository.createIntegration(entities, userId, config);
34
-
35
-
36
- const integrationClass = this.integrationClasses.find(
37
- (integrationClass) => integrationClass.Definition.name === integrationRecord.config.type
38
- );
39
-
40
- if (!integrationClass) {
41
- throw new Error(`No integration class found for type: ${integrationRecord.config.type}`);
42
- }
43
-
44
- const modules = [];
45
- for (const entityId of integrationRecord.entitiesIds) {
46
- const moduleInstance = await this.moduleFactory.getModuleInstance(
47
- entityId,
48
- integrationRecord.userId
49
- );
50
- modules.push(moduleInstance);
51
- }
52
-
53
- const integrationInstance = new integrationClass({
54
- id: integrationRecord.id,
55
- userId: integrationRecord.userId,
56
- entities: integrationRecord.entitiesIds,
57
- config: integrationRecord.config,
58
- status: integrationRecord.status,
59
- version: integrationRecord.version,
60
- messages: integrationRecord.messages,
61
- modules
62
- });
63
-
64
- await integrationInstance.initialize();
65
- await integrationInstance.send('ON_CREATE', { integrationId: integrationRecord.id });
66
-
67
- return mapIntegrationClassToIntegrationDTO(integrationInstance);
68
- }
69
- }
70
-
71
- module.exports = { CreateIntegration };