@friggframework/core 2.0.0-next.41 → 2.0.0-next.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +693 -0
- package/README.md +931 -50
- package/application/commands/README.md +421 -0
- package/application/commands/credential-commands.js +224 -0
- package/application/commands/entity-commands.js +315 -0
- package/application/commands/integration-commands.js +160 -0
- package/application/commands/integration-commands.test.js +123 -0
- package/application/commands/user-commands.js +213 -0
- package/application/index.js +69 -0
- package/core/CLAUDE.md +690 -0
- package/core/create-handler.js +0 -6
- package/credential/repositories/credential-repository-factory.js +47 -0
- package/credential/repositories/credential-repository-interface.js +98 -0
- package/credential/repositories/credential-repository-mongo.js +301 -0
- package/credential/repositories/credential-repository-postgres.js +307 -0
- package/credential/repositories/credential-repository.js +307 -0
- package/credential/use-cases/get-credential-for-user.js +21 -0
- package/credential/use-cases/update-authentication-status.js +15 -0
- package/database/config.js +117 -0
- package/database/encryption/README.md +683 -0
- package/database/encryption/encryption-integration.test.js +553 -0
- package/database/encryption/encryption-schema-registry.js +141 -0
- package/database/encryption/encryption-schema-registry.test.js +392 -0
- package/database/encryption/field-encryption-service.js +226 -0
- package/database/encryption/field-encryption-service.test.js +525 -0
- package/database/encryption/logger.js +79 -0
- package/database/encryption/mongo-decryption-fix-verification.test.js +348 -0
- package/database/encryption/postgres-decryption-fix-verification.test.js +371 -0
- package/database/encryption/postgres-relation-decryption.test.js +245 -0
- package/database/encryption/prisma-encryption-extension.js +222 -0
- package/database/encryption/prisma-encryption-extension.test.js +439 -0
- package/database/index.js +25 -12
- package/database/models/readme.md +1 -0
- package/database/prisma.js +162 -0
- package/database/repositories/health-check-repository-factory.js +38 -0
- package/database/repositories/health-check-repository-interface.js +86 -0
- package/database/repositories/health-check-repository-mongodb.js +72 -0
- package/database/repositories/health-check-repository-postgres.js +75 -0
- package/database/repositories/health-check-repository.js +108 -0
- package/database/use-cases/check-database-health-use-case.js +34 -0
- package/database/use-cases/check-encryption-health-use-case.js +82 -0
- package/database/use-cases/test-encryption-use-case.js +252 -0
- package/encrypt/Cryptor.js +20 -152
- package/encrypt/index.js +1 -2
- package/encrypt/test-encrypt.js +0 -2
- package/handlers/app-definition-loader.js +38 -0
- package/handlers/app-handler-helpers.js +0 -3
- package/handlers/auth-flow.integration.test.js +147 -0
- package/handlers/backend-utils.js +25 -45
- package/handlers/integration-event-dispatcher.js +54 -0
- package/handlers/integration-event-dispatcher.test.js +141 -0
- package/handlers/routers/HEALTHCHECK.md +103 -1
- package/handlers/routers/auth.js +3 -14
- package/handlers/routers/health.js +63 -424
- package/handlers/routers/health.test.js +7 -0
- package/handlers/routers/integration-defined-routers.js +8 -5
- package/handlers/routers/user.js +27 -5
- package/handlers/routers/websocket.js +5 -3
- package/handlers/use-cases/check-external-apis-health-use-case.js +81 -0
- package/handlers/use-cases/check-integrations-health-use-case.js +32 -0
- package/handlers/workers/integration-defined-workers.js +6 -3
- package/index.js +45 -22
- package/integrations/index.js +12 -10
- package/integrations/integration-base.js +224 -53
- package/integrations/integration-router.js +386 -178
- package/integrations/options.js +1 -1
- package/integrations/repositories/integration-mapping-repository-factory.js +50 -0
- package/integrations/repositories/integration-mapping-repository-interface.js +106 -0
- package/integrations/repositories/integration-mapping-repository-mongo.js +161 -0
- package/integrations/repositories/integration-mapping-repository-postgres.js +227 -0
- package/integrations/repositories/integration-mapping-repository.js +156 -0
- package/integrations/repositories/integration-repository-factory.js +44 -0
- package/integrations/repositories/integration-repository-interface.js +115 -0
- package/integrations/repositories/integration-repository-mongo.js +271 -0
- package/integrations/repositories/integration-repository-postgres.js +319 -0
- package/integrations/tests/doubles/dummy-integration-class.js +90 -0
- package/integrations/tests/doubles/test-integration-repository.js +99 -0
- package/integrations/tests/use-cases/create-integration.test.js +131 -0
- package/integrations/tests/use-cases/delete-integration-for-user.test.js +150 -0
- package/integrations/tests/use-cases/find-integration-context-by-external-entity-id.test.js +92 -0
- package/integrations/tests/use-cases/get-integration-for-user.test.js +150 -0
- package/integrations/tests/use-cases/get-integration-instance.test.js +176 -0
- package/integrations/tests/use-cases/get-integrations-for-user.test.js +176 -0
- package/integrations/tests/use-cases/get-possible-integrations.test.js +188 -0
- package/integrations/tests/use-cases/update-integration-messages.test.js +142 -0
- package/integrations/tests/use-cases/update-integration-status.test.js +103 -0
- package/integrations/tests/use-cases/update-integration.test.js +141 -0
- package/integrations/use-cases/create-integration.js +83 -0
- package/integrations/use-cases/delete-integration-for-user.js +73 -0
- package/integrations/use-cases/find-integration-context-by-external-entity-id.js +72 -0
- package/integrations/use-cases/get-integration-for-user.js +78 -0
- package/integrations/use-cases/get-integration-instance-by-definition.js +67 -0
- package/integrations/use-cases/get-integration-instance.js +83 -0
- package/integrations/use-cases/get-integrations-for-user.js +87 -0
- package/integrations/use-cases/get-possible-integrations.js +27 -0
- package/integrations/use-cases/index.js +11 -0
- package/integrations/use-cases/load-integration-context-full.test.js +329 -0
- package/integrations/use-cases/load-integration-context.js +71 -0
- package/integrations/use-cases/load-integration-context.test.js +114 -0
- package/integrations/use-cases/update-integration-messages.js +44 -0
- package/integrations/use-cases/update-integration-status.js +32 -0
- package/integrations/use-cases/update-integration.js +93 -0
- package/integrations/utils/map-integration-dto.js +36 -0
- package/jest-global-setup-noop.js +3 -0
- package/jest-global-teardown-noop.js +3 -0
- package/{module-plugin → modules}/entity.js +1 -0
- package/{module-plugin → modules}/index.js +0 -8
- package/modules/module-factory.js +56 -0
- package/modules/module-hydration.test.js +205 -0
- package/modules/module.js +221 -0
- package/modules/repositories/module-repository-factory.js +33 -0
- package/modules/repositories/module-repository-interface.js +129 -0
- package/modules/repositories/module-repository-mongo.js +386 -0
- package/modules/repositories/module-repository-postgres.js +437 -0
- package/modules/repositories/module-repository.js +327 -0
- package/{module-plugin → modules}/test/mock-api/api.js +8 -3
- package/{module-plugin → modules}/test/mock-api/definition.js +12 -8
- package/modules/tests/doubles/test-module-factory.js +16 -0
- package/modules/tests/doubles/test-module-repository.js +39 -0
- package/modules/use-cases/get-entities-for-user.js +32 -0
- package/modules/use-cases/get-entity-options-by-id.js +59 -0
- package/modules/use-cases/get-entity-options-by-type.js +34 -0
- package/modules/use-cases/get-module-instance-from-type.js +31 -0
- package/modules/use-cases/get-module.js +56 -0
- package/modules/use-cases/process-authorization-callback.js +122 -0
- package/modules/use-cases/refresh-entity-options.js +59 -0
- package/modules/use-cases/test-module-auth.js +55 -0
- package/modules/utils/map-module-dto.js +18 -0
- package/package.json +14 -6
- package/prisma-mongodb/schema.prisma +318 -0
- package/prisma-postgresql/migrations/20250930193005_init/migration.sql +315 -0
- package/prisma-postgresql/migrations/20251006135218_init/migration.sql +9 -0
- package/prisma-postgresql/migrations/20251010000000_remove_unused_entity_reference_map/migration.sql +3 -0
- package/prisma-postgresql/migrations/migration_lock.toml +3 -0
- package/prisma-postgresql/schema.prisma +300 -0
- package/syncs/manager.js +468 -443
- package/syncs/repositories/sync-repository-factory.js +38 -0
- package/syncs/repositories/sync-repository-interface.js +109 -0
- package/syncs/repositories/sync-repository-mongo.js +239 -0
- package/syncs/repositories/sync-repository-postgres.js +319 -0
- package/syncs/sync.js +0 -1
- package/token/repositories/token-repository-factory.js +33 -0
- package/token/repositories/token-repository-interface.js +131 -0
- package/token/repositories/token-repository-mongo.js +212 -0
- package/token/repositories/token-repository-postgres.js +257 -0
- package/token/repositories/token-repository.js +219 -0
- package/types/integrations/index.d.ts +2 -6
- package/types/module-plugin/index.d.ts +5 -57
- package/types/syncs/index.d.ts +0 -2
- package/user/repositories/user-repository-factory.js +46 -0
- package/user/repositories/user-repository-interface.js +198 -0
- package/user/repositories/user-repository-mongo.js +250 -0
- package/user/repositories/user-repository-postgres.js +311 -0
- package/user/tests/doubles/test-user-repository.js +72 -0
- package/user/tests/use-cases/create-individual-user.test.js +24 -0
- package/user/tests/use-cases/create-organization-user.test.js +28 -0
- package/user/tests/use-cases/create-token-for-user-id.test.js +19 -0
- package/user/tests/use-cases/get-user-from-bearer-token.test.js +64 -0
- package/user/tests/use-cases/login-user.test.js +140 -0
- package/user/use-cases/create-individual-user.js +61 -0
- package/user/use-cases/create-organization-user.js +47 -0
- package/user/use-cases/create-token-for-user-id.js +30 -0
- package/user/use-cases/get-user-from-bearer-token.js +77 -0
- package/user/use-cases/login-user.js +122 -0
- package/user/user.js +77 -0
- package/websocket/repositories/websocket-connection-repository-factory.js +37 -0
- package/websocket/repositories/websocket-connection-repository-interface.js +106 -0
- package/websocket/repositories/websocket-connection-repository-mongo.js +155 -0
- package/websocket/repositories/websocket-connection-repository-postgres.js +195 -0
- package/websocket/repositories/websocket-connection-repository.js +160 -0
- package/database/models/State.js +0 -9
- package/database/models/Token.js +0 -70
- package/database/mongo.js +0 -171
- package/encrypt/Cryptor.test.js +0 -32
- package/encrypt/encrypt.js +0 -104
- package/encrypt/encrypt.test.js +0 -1069
- package/handlers/routers/middleware/loadUser.js +0 -15
- package/handlers/routers/middleware/requireLoggedInUser.js +0 -12
- package/integrations/create-frigg-backend.js +0 -31
- package/integrations/integration-factory.js +0 -251
- package/integrations/integration-mapping.js +0 -43
- package/integrations/integration-model.js +0 -46
- package/integrations/integration-user.js +0 -144
- package/integrations/test/integration-base.test.js +0 -144
- package/module-plugin/auther.js +0 -393
- package/module-plugin/credential.js +0 -22
- package/module-plugin/entity-manager.js +0 -70
- package/module-plugin/manager.js +0 -169
- package/module-plugin/module-factory.js +0 -61
- package/module-plugin/test/auther.test.js +0 -97
- /package/{module-plugin → modules}/ModuleConstants.js +0 -0
- /package/{module-plugin → modules}/requester/api-key.js +0 -0
- /package/{module-plugin → modules}/requester/basic.js +0 -0
- /package/{module-plugin → modules}/requester/oauth-2.js +0 -0
- /package/{module-plugin → modules}/requester/requester.js +0 -0
- /package/{module-plugin → modules}/requester/requester.test.js +0 -0
- /package/{module-plugin → modules}/test/mock-api/mocks/hubspot.js +0 -0
|
@@ -0,0 +1,176 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
});
|