@friggframework/core 2.0.0-next.44 → 2.0.0-next.46
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/README.md +28 -0
- package/application/commands/integration-commands.js +19 -0
- package/core/Worker.js +8 -21
- package/credential/repositories/credential-repository-mongo.js +14 -8
- package/credential/repositories/credential-repository-postgres.js +14 -8
- package/credential/repositories/credential-repository.js +3 -8
- package/database/MONGODB_TRANSACTION_FIX.md +198 -0
- package/database/adapters/lambda-invoker.js +97 -0
- package/database/config.js +11 -2
- package/database/models/WebsocketConnection.js +11 -10
- package/database/prisma.js +63 -3
- package/database/repositories/health-check-repository-mongodb.js +3 -0
- package/database/repositories/migration-status-repository-s3.js +137 -0
- package/database/use-cases/check-database-state-use-case.js +81 -0
- package/database/use-cases/check-encryption-health-use-case.js +3 -2
- package/database/use-cases/get-database-state-via-worker-use-case.js +61 -0
- package/database/use-cases/get-migration-status-use-case.js +93 -0
- package/database/use-cases/run-database-migration-use-case.js +137 -0
- package/database/use-cases/trigger-database-migration-use-case.js +157 -0
- package/database/utils/mongodb-collection-utils.js +91 -0
- package/database/utils/mongodb-schema-init.js +106 -0
- package/database/utils/prisma-runner.js +400 -0
- package/database/utils/prisma-schema-parser.js +182 -0
- package/encrypt/Cryptor.js +14 -16
- package/generated/prisma-mongodb/client.d.ts +1 -0
- package/generated/prisma-mongodb/client.js +4 -0
- package/generated/prisma-mongodb/default.d.ts +1 -0
- package/generated/prisma-mongodb/default.js +4 -0
- package/generated/prisma-mongodb/edge.d.ts +1 -0
- package/generated/prisma-mongodb/edge.js +334 -0
- package/generated/prisma-mongodb/index-browser.js +316 -0
- package/generated/prisma-mongodb/index.d.ts +22897 -0
- package/generated/prisma-mongodb/index.js +359 -0
- package/generated/prisma-mongodb/package.json +183 -0
- package/generated/prisma-mongodb/query-engine-debian-openssl-3.0.x +0 -0
- package/generated/prisma-mongodb/query-engine-rhel-openssl-3.0.x +0 -0
- package/generated/prisma-mongodb/runtime/binary.d.ts +1 -0
- package/generated/prisma-mongodb/runtime/binary.js +289 -0
- package/generated/prisma-mongodb/runtime/edge-esm.js +34 -0
- package/generated/prisma-mongodb/runtime/edge.js +34 -0
- package/generated/prisma-mongodb/runtime/index-browser.d.ts +370 -0
- package/generated/prisma-mongodb/runtime/index-browser.js +16 -0
- package/generated/prisma-mongodb/runtime/library.d.ts +3977 -0
- package/generated/prisma-mongodb/runtime/react-native.js +83 -0
- package/generated/prisma-mongodb/runtime/wasm-compiler-edge.js +84 -0
- package/generated/prisma-mongodb/runtime/wasm-engine-edge.js +36 -0
- package/generated/prisma-mongodb/schema.prisma +362 -0
- package/generated/prisma-mongodb/wasm-edge-light-loader.mjs +4 -0
- package/generated/prisma-mongodb/wasm-worker-loader.mjs +4 -0
- package/generated/prisma-mongodb/wasm.d.ts +1 -0
- package/generated/prisma-mongodb/wasm.js +341 -0
- package/generated/prisma-postgresql/client.d.ts +1 -0
- package/generated/prisma-postgresql/client.js +4 -0
- package/generated/prisma-postgresql/default.d.ts +1 -0
- package/generated/prisma-postgresql/default.js +4 -0
- package/generated/prisma-postgresql/edge.d.ts +1 -0
- package/generated/prisma-postgresql/edge.js +356 -0
- package/generated/prisma-postgresql/index-browser.js +338 -0
- package/generated/prisma-postgresql/index.d.ts +25071 -0
- package/generated/prisma-postgresql/index.js +381 -0
- package/generated/prisma-postgresql/package.json +183 -0
- package/generated/prisma-postgresql/query-engine-debian-openssl-3.0.x +0 -0
- package/generated/prisma-postgresql/query-engine-rhel-openssl-3.0.x +0 -0
- package/generated/prisma-postgresql/query_engine_bg.js +2 -0
- package/generated/prisma-postgresql/query_engine_bg.wasm +0 -0
- package/generated/prisma-postgresql/runtime/binary.d.ts +1 -0
- package/generated/prisma-postgresql/runtime/binary.js +289 -0
- package/generated/prisma-postgresql/runtime/edge-esm.js +34 -0
- package/generated/prisma-postgresql/runtime/edge.js +34 -0
- package/generated/prisma-postgresql/runtime/index-browser.d.ts +370 -0
- package/generated/prisma-postgresql/runtime/index-browser.js +16 -0
- package/generated/prisma-postgresql/runtime/library.d.ts +3977 -0
- package/generated/prisma-postgresql/runtime/react-native.js +83 -0
- package/generated/prisma-postgresql/runtime/wasm-compiler-edge.js +84 -0
- package/generated/prisma-postgresql/runtime/wasm-engine-edge.js +36 -0
- package/generated/prisma-postgresql/schema.prisma +345 -0
- package/generated/prisma-postgresql/wasm-edge-light-loader.mjs +4 -0
- package/generated/prisma-postgresql/wasm-worker-loader.mjs +4 -0
- package/generated/prisma-postgresql/wasm.d.ts +1 -0
- package/generated/prisma-postgresql/wasm.js +363 -0
- package/handlers/WEBHOOKS.md +653 -0
- package/handlers/backend-utils.js +118 -3
- package/handlers/database-migration-handler.js +227 -0
- package/handlers/routers/auth.js +1 -1
- package/handlers/routers/db-migration.handler.js +29 -0
- package/handlers/routers/db-migration.js +256 -0
- package/handlers/routers/health.js +41 -6
- package/handlers/routers/integration-webhook-routers.js +67 -0
- package/handlers/use-cases/check-integrations-health-use-case.js +22 -10
- package/handlers/workers/db-migration.js +352 -0
- package/index.js +28 -0
- package/integrations/WEBHOOK-QUICKSTART.md +151 -0
- package/integrations/integration-base.js +74 -3
- package/integrations/integration-router.js +60 -70
- package/integrations/repositories/integration-repository-interface.js +12 -0
- package/integrations/repositories/integration-repository-mongo.js +32 -0
- package/integrations/repositories/integration-repository-postgres.js +33 -0
- package/integrations/repositories/process-repository-postgres.js +43 -20
- package/integrations/tests/doubles/dummy-integration-class.js +1 -8
- package/integrations/tests/doubles/test-integration-repository.js +2 -2
- package/logs/logger.js +0 -4
- package/modules/entity.js +0 -1
- package/modules/repositories/module-repository-mongo.js +3 -12
- package/modules/repositories/module-repository-postgres.js +0 -11
- package/modules/repositories/module-repository.js +1 -12
- package/modules/use-cases/get-entity-options-by-id.js +1 -1
- package/modules/use-cases/get-module.js +1 -2
- package/modules/use-cases/refresh-entity-options.js +1 -1
- package/modules/use-cases/test-module-auth.js +1 -1
- package/package.json +82 -66
- package/prisma-mongodb/schema.prisma +21 -21
- package/prisma-postgresql/schema.prisma +15 -15
- package/queues/queuer-util.js +28 -15
- package/types/core/index.d.ts +2 -2
- package/types/module-plugin/index.d.ts +0 -2
- package/user/repositories/user-repository-mongo.js +53 -12
- package/user/repositories/user-repository-postgres.js +53 -14
- package/user/use-cases/authenticate-user.js +127 -0
- package/user/use-cases/authenticate-with-shared-secret.js +48 -0
- package/user/use-cases/get-user-from-adopter-jwt.js +149 -0
- package/user/use-cases/get-user-from-x-frigg-headers.js +106 -0
- package/user/use-cases/login-user.js +1 -1
- package/user/user.js +18 -2
- package/websocket/repositories/websocket-connection-repository-mongo.js +11 -10
- package/websocket/repositories/websocket-connection-repository-postgres.js +11 -10
- package/websocket/repositories/websocket-connection-repository.js +11 -10
- package/application/commands/integration-commands.test.js +0 -123
- package/database/encryption/encryption-integration.test.js +0 -553
- package/database/encryption/encryption-schema-registry.test.js +0 -392
- package/database/encryption/field-encryption-service.test.js +0 -525
- package/database/encryption/mongo-decryption-fix-verification.test.js +0 -348
- package/database/encryption/postgres-decryption-fix-verification.test.js +0 -371
- package/database/encryption/postgres-relation-decryption.test.js +0 -245
- package/database/encryption/prisma-encryption-extension.test.js +0 -439
- package/errors/base-error.test.js +0 -32
- package/errors/fetch-error.test.js +0 -79
- package/errors/halt-error.test.js +0 -11
- package/errors/validation-errors.test.js +0 -120
- package/handlers/auth-flow.integration.test.js +0 -147
- package/handlers/integration-event-dispatcher.test.js +0 -141
- package/handlers/routers/health.test.js +0 -210
- package/integrations/tests/use-cases/create-integration.test.js +0 -131
- package/integrations/tests/use-cases/delete-integration-for-user.test.js +0 -150
- package/integrations/tests/use-cases/find-integration-context-by-external-entity-id.test.js +0 -92
- package/integrations/tests/use-cases/get-integration-for-user.test.js +0 -150
- package/integrations/tests/use-cases/get-integration-instance.test.js +0 -176
- package/integrations/tests/use-cases/get-integrations-for-user.test.js +0 -176
- package/integrations/tests/use-cases/get-possible-integrations.test.js +0 -188
- package/integrations/tests/use-cases/update-integration-messages.test.js +0 -142
- package/integrations/tests/use-cases/update-integration-status.test.js +0 -103
- package/integrations/tests/use-cases/update-integration.test.js +0 -141
- package/integrations/use-cases/create-process.test.js +0 -178
- package/integrations/use-cases/get-process.test.js +0 -190
- package/integrations/use-cases/load-integration-context-full.test.js +0 -329
- package/integrations/use-cases/load-integration-context.test.js +0 -114
- package/integrations/use-cases/update-process-metrics.test.js +0 -308
- package/integrations/use-cases/update-process-state.test.js +0 -256
- package/lambda/TimeoutCatcher.test.js +0 -68
- package/logs/logger.test.js +0 -76
- package/modules/module-hydration.test.js +0 -205
- package/modules/requester/requester.test.js +0 -28
- package/user/tests/use-cases/create-individual-user.test.js +0 -24
- package/user/tests/use-cases/create-organization-user.test.js +0 -28
- package/user/tests/use-cases/create-token-for-user-id.test.js +0 -19
- package/user/tests/use-cases/get-user-from-bearer-token.test.js +0 -64
- package/user/tests/use-cases/login-user.test.js +0 -140
|
@@ -1,329 +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 { LoadIntegrationContextUseCase } = require('./load-integration-context');
|
|
9
|
-
const { IntegrationBase } = require('../integration-base');
|
|
10
|
-
const { createIntegrationRepository } = require('../repositories/integration-repository-factory');
|
|
11
|
-
const { Module } = require('../../modules/module');
|
|
12
|
-
const { ModuleFactory } = require('../../modules/module-factory');
|
|
13
|
-
const { ModuleRepository } = require('../../modules/repositories/module-repository');
|
|
14
|
-
|
|
15
|
-
// Mock OAuth2 API class that extends requester pattern
|
|
16
|
-
class MockAsanaApi {
|
|
17
|
-
constructor(params) {
|
|
18
|
-
// Capture all injected params
|
|
19
|
-
this.client_id = params.client_id;
|
|
20
|
-
this.client_secret = params.client_secret;
|
|
21
|
-
this.redirect_uri = params.redirect_uri;
|
|
22
|
-
this.scope = params.scope;
|
|
23
|
-
this.access_token = params.access_token;
|
|
24
|
-
this.refresh_token = params.refresh_token;
|
|
25
|
-
this.delegate = params.delegate;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async getFolders() {
|
|
29
|
-
if (!this.access_token) {
|
|
30
|
-
throw new Error('No access token');
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
folders: ['Marketing', 'Development', 'Design'],
|
|
34
|
-
usedToken: this.access_token
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async listProjects() {
|
|
39
|
-
return {
|
|
40
|
-
projects: ['Q1 Launch', 'Website Redesign'],
|
|
41
|
-
clientId: this.client_id
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
getAuthorizationRequirements() {
|
|
46
|
-
return { type: 'oauth2', url: this.redirect_uri };
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
MockAsanaApi.requesterType = 'oauth2';
|
|
51
|
-
|
|
52
|
-
class MockFrontifyApi {
|
|
53
|
-
constructor(params) {
|
|
54
|
-
this.client_id = params.client_id;
|
|
55
|
-
this.client_secret = params.client_secret;
|
|
56
|
-
this.redirect_uri = params.redirect_uri;
|
|
57
|
-
this.scope = params.scope;
|
|
58
|
-
this.access_token = params.access_token;
|
|
59
|
-
this.refresh_token = params.refresh_token;
|
|
60
|
-
this.domain = params.domain;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async listBrands() {
|
|
64
|
-
return {
|
|
65
|
-
brands: ['Main Brand', 'Sub Brand'],
|
|
66
|
-
domain: this.domain,
|
|
67
|
-
token: this.access_token
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async searchAssets(query) {
|
|
72
|
-
return {
|
|
73
|
-
query,
|
|
74
|
-
assets: ['logo.svg', 'guidelines.pdf'],
|
|
75
|
-
clientSecret: this.client_secret ? 'hidden' : null
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
getAuthorizationRequirements() {
|
|
80
|
-
return { type: 'oauth2', url: this.redirect_uri };
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
MockFrontifyApi.requesterType = 'oauth2';
|
|
85
|
-
|
|
86
|
-
// Module definitions with env variables
|
|
87
|
-
const asanaDefinition = {
|
|
88
|
-
moduleName: 'asana',
|
|
89
|
-
modelName: 'Asana',
|
|
90
|
-
API: MockAsanaApi,
|
|
91
|
-
requiredAuthMethods: {
|
|
92
|
-
getToken: async () => {},
|
|
93
|
-
getEntityDetails: async () => {},
|
|
94
|
-
getCredentialDetails: async () => {},
|
|
95
|
-
apiPropertiesToPersist: {
|
|
96
|
-
credential: ['access_token', 'refresh_token'],
|
|
97
|
-
entity: [],
|
|
98
|
-
},
|
|
99
|
-
testAuthRequest: async () => true,
|
|
100
|
-
},
|
|
101
|
-
env: {
|
|
102
|
-
client_id: 'ASANA_CLIENT_ID_FROM_ENV',
|
|
103
|
-
client_secret: 'ASANA_SECRET_FROM_ENV',
|
|
104
|
-
redirect_uri: 'https://app.example.com/auth/asana',
|
|
105
|
-
scope: 'default',
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const frontifyDefinition = {
|
|
110
|
-
moduleName: 'frontify',
|
|
111
|
-
modelName: 'Frontify',
|
|
112
|
-
API: MockFrontifyApi,
|
|
113
|
-
requiredAuthMethods: {
|
|
114
|
-
getToken: async () => {},
|
|
115
|
-
getEntityDetails: async () => {},
|
|
116
|
-
getCredentialDetails: async () => {},
|
|
117
|
-
apiPropertiesToPersist: {
|
|
118
|
-
credential: ['access_token', 'refresh_token'],
|
|
119
|
-
entity: ['domain'],
|
|
120
|
-
},
|
|
121
|
-
testAuthRequest: async () => true,
|
|
122
|
-
},
|
|
123
|
-
env: {
|
|
124
|
-
client_id: 'FRONTIFY_CLIENT_ID_FROM_ENV',
|
|
125
|
-
client_secret: 'FRONTIFY_SECRET_FROM_ENV',
|
|
126
|
-
redirect_uri: 'https://app.example.com/auth/frontify',
|
|
127
|
-
scope: 'read write',
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// Integration class similar to AsanaIntegration
|
|
132
|
-
class TestIntegration extends IntegrationBase {
|
|
133
|
-
static Definition = {
|
|
134
|
-
name: 'test-integration',
|
|
135
|
-
version: '1.0.0',
|
|
136
|
-
modules: {
|
|
137
|
-
asana: {
|
|
138
|
-
definition: asanaDefinition,
|
|
139
|
-
},
|
|
140
|
-
frontify: {
|
|
141
|
-
definition: frontifyDefinition,
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
async performBusinessLogic() {
|
|
147
|
-
// After hydration, this method can use API modules
|
|
148
|
-
const folders = await this.asana.api.getFolders();
|
|
149
|
-
const brands = await this.frontify.api.listBrands();
|
|
150
|
-
return { folders, brands };
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
describe('LoadIntegrationContextUseCase - Full Rounded Test', () => {
|
|
155
|
-
it('should load integration with working API modules that have env vars and credentials', async () => {
|
|
156
|
-
// Setup: Create entities with credentials (simulating DB records)
|
|
157
|
-
const entities = [
|
|
158
|
-
{
|
|
159
|
-
id: 'entity-asana-123',
|
|
160
|
-
moduleName: 'asana',
|
|
161
|
-
userId: 'user-789',
|
|
162
|
-
credential: {
|
|
163
|
-
data: {
|
|
164
|
-
access_token: 'asana_access_token_xyz',
|
|
165
|
-
refresh_token: 'asana_refresh_token_abc',
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
id: 'entity-frontify-456',
|
|
171
|
-
moduleName: 'frontify',
|
|
172
|
-
userId: 'user-789',
|
|
173
|
-
domain: 'customer.frontify.com',
|
|
174
|
-
credential: {
|
|
175
|
-
data: {
|
|
176
|
-
access_token: 'frontify_access_token_uvw',
|
|
177
|
-
refresh_token: 'frontify_refresh_token_def',
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
];
|
|
182
|
-
|
|
183
|
-
// Mock repositories
|
|
184
|
-
const moduleRepository = {
|
|
185
|
-
findEntitiesByIds: jest.fn().mockResolvedValue(entities),
|
|
186
|
-
findEntityById: jest.fn().mockImplementation((id) =>
|
|
187
|
-
Promise.resolve(entities.find(e => e.id === id))
|
|
188
|
-
),
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
// Create module factory with definitions
|
|
192
|
-
const moduleFactory = new ModuleFactory({
|
|
193
|
-
moduleRepository,
|
|
194
|
-
moduleDefinitions: [asanaDefinition, frontifyDefinition],
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
// Create the use case
|
|
198
|
-
const useCase = new LoadIntegrationContextUseCase({
|
|
199
|
-
integrationRepository: createIntegrationRepository(),
|
|
200
|
-
moduleRepository,
|
|
201
|
-
moduleFactory,
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
// Execute: Load integration context
|
|
205
|
-
const integrationRecord = {
|
|
206
|
-
id: 'integration-999',
|
|
207
|
-
userId: 'user-789',
|
|
208
|
-
entitiesIds: ['entity-asana-123', 'entity-frontify-456'],
|
|
209
|
-
status: 'active',
|
|
210
|
-
config: { someConfig: true },
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
const context = await useCase.execute({ integrationRecord });
|
|
214
|
-
|
|
215
|
-
// Verify: Context has modules
|
|
216
|
-
expect(context.modules).toHaveLength(2);
|
|
217
|
-
|
|
218
|
-
// Create integration instance and hydrate it
|
|
219
|
-
const integration = new TestIntegration();
|
|
220
|
-
integration.setIntegrationRecord(context);
|
|
221
|
-
|
|
222
|
-
// Verify: Integration has modules attached
|
|
223
|
-
expect(integration.asana).toBeDefined();
|
|
224
|
-
expect(integration.frontify).toBeDefined();
|
|
225
|
-
expect(integration.modules.asana).toBe(integration.asana);
|
|
226
|
-
expect(integration.modules.frontify).toBe(integration.frontify);
|
|
227
|
-
|
|
228
|
-
// CRITICAL TEST: Verify API instances have env vars from definition
|
|
229
|
-
expect(integration.asana.api.client_id).toBe('ASANA_CLIENT_ID_FROM_ENV');
|
|
230
|
-
expect(integration.asana.api.client_secret).toBe('ASANA_SECRET_FROM_ENV');
|
|
231
|
-
expect(integration.asana.api.redirect_uri).toBe('https://app.example.com/auth/asana');
|
|
232
|
-
expect(integration.asana.api.scope).toBe('default');
|
|
233
|
-
|
|
234
|
-
expect(integration.frontify.api.client_id).toBe('FRONTIFY_CLIENT_ID_FROM_ENV');
|
|
235
|
-
expect(integration.frontify.api.client_secret).toBe('FRONTIFY_SECRET_FROM_ENV');
|
|
236
|
-
expect(integration.frontify.api.redirect_uri).toBe('https://app.example.com/auth/frontify');
|
|
237
|
-
expect(integration.frontify.api.scope).toBe('read write');
|
|
238
|
-
|
|
239
|
-
// CRITICAL TEST: Verify API instances have credentials from entities
|
|
240
|
-
expect(integration.asana.api.access_token).toBe('asana_access_token_xyz');
|
|
241
|
-
expect(integration.asana.api.refresh_token).toBe('asana_refresh_token_abc');
|
|
242
|
-
|
|
243
|
-
expect(integration.frontify.api.access_token).toBe('frontify_access_token_uvw');
|
|
244
|
-
expect(integration.frontify.api.refresh_token).toBe('frontify_refresh_token_def');
|
|
245
|
-
expect(integration.frontify.api.domain).toBe('customer.frontify.com');
|
|
246
|
-
|
|
247
|
-
// CRITICAL TEST: Can call API methods successfully
|
|
248
|
-
const folders = await integration.asana.api.getFolders();
|
|
249
|
-
expect(folders.folders).toEqual(['Marketing', 'Development', 'Design']);
|
|
250
|
-
expect(folders.usedToken).toBe('asana_access_token_xyz');
|
|
251
|
-
|
|
252
|
-
const projects = await integration.asana.api.listProjects();
|
|
253
|
-
expect(projects.projects).toEqual(['Q1 Launch', 'Website Redesign']);
|
|
254
|
-
expect(projects.clientId).toBe('ASANA_CLIENT_ID_FROM_ENV');
|
|
255
|
-
|
|
256
|
-
const brands = await integration.frontify.api.listBrands();
|
|
257
|
-
expect(brands.brands).toEqual(['Main Brand', 'Sub Brand']);
|
|
258
|
-
expect(brands.domain).toBe('customer.frontify.com');
|
|
259
|
-
expect(brands.token).toBe('frontify_access_token_uvw');
|
|
260
|
-
|
|
261
|
-
const assets = await integration.frontify.api.searchAssets('logo');
|
|
262
|
-
expect(assets.query).toBe('logo');
|
|
263
|
-
expect(assets.assets).toEqual(['logo.svg', 'guidelines.pdf']);
|
|
264
|
-
expect(assets.clientSecret).toBe('hidden'); // Verifies secret exists
|
|
265
|
-
|
|
266
|
-
// CRITICAL TEST: Business logic methods can use hydrated APIs
|
|
267
|
-
const businessResult = await integration.performBusinessLogic();
|
|
268
|
-
expect(businessResult.folders.folders).toEqual(['Marketing', 'Development', 'Design']);
|
|
269
|
-
expect(businessResult.brands.brands).toEqual(['Main Brand', 'Sub Brand']);
|
|
270
|
-
|
|
271
|
-
// Verify the complete chain: env → Module → API → Integration
|
|
272
|
-
console.log('\n✅ Full Integration Test Results:');
|
|
273
|
-
console.log(' ENV vars injected: ✓');
|
|
274
|
-
console.log(' Credentials injected: ✓');
|
|
275
|
-
console.log(' API methods callable: ✓');
|
|
276
|
-
console.log(' Business logic works: ✓');
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it('should handle missing credentials gracefully', async () => {
|
|
280
|
-
// Entity without credentials
|
|
281
|
-
const entities = [
|
|
282
|
-
{
|
|
283
|
-
id: 'entity-no-creds',
|
|
284
|
-
moduleName: 'asana',
|
|
285
|
-
userId: 'user-123',
|
|
286
|
-
credential: {
|
|
287
|
-
data: {
|
|
288
|
-
// Empty credential data - no access_token
|
|
289
|
-
},
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
];
|
|
293
|
-
|
|
294
|
-
const moduleRepository = {
|
|
295
|
-
findEntitiesByIds: jest.fn().mockResolvedValue(entities),
|
|
296
|
-
findEntityById: jest.fn().mockResolvedValue(entities[0]),
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
const moduleFactory = new ModuleFactory({
|
|
300
|
-
moduleRepository,
|
|
301
|
-
moduleDefinitions: [asanaDefinition],
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
const useCase = new LoadIntegrationContextUseCase({
|
|
305
|
-
integrationRepository: createIntegrationRepository(),
|
|
306
|
-
moduleRepository,
|
|
307
|
-
moduleFactory,
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
const context = await useCase.execute({
|
|
311
|
-
integrationRecord: {
|
|
312
|
-
id: 'integration-1',
|
|
313
|
-
userId: 'user-123',
|
|
314
|
-
entitiesIds: ['entity-no-creds'],
|
|
315
|
-
},
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
const integration = new TestIntegration();
|
|
319
|
-
integration.setIntegrationRecord(context);
|
|
320
|
-
|
|
321
|
-
// Should have module with env vars but no credentials
|
|
322
|
-
expect(integration.asana).toBeDefined();
|
|
323
|
-
expect(integration.asana.api.client_id).toBe('ASANA_CLIENT_ID_FROM_ENV');
|
|
324
|
-
expect(integration.asana.api.access_token).toBeUndefined();
|
|
325
|
-
|
|
326
|
-
// API method should fail without token
|
|
327
|
-
await expect(integration.asana.api.getFolders()).rejects.toThrow('No access token');
|
|
328
|
-
});
|
|
329
|
-
});
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
const { LoadIntegrationContextUseCase } = require('./load-integration-context');
|
|
2
|
-
|
|
3
|
-
class FakeIntegration {}
|
|
4
|
-
FakeIntegration.Definition = {
|
|
5
|
-
name: 'fake',
|
|
6
|
-
modules: {},
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
describe('LoadIntegrationContextUseCase', () => {
|
|
10
|
-
it('throws when neither integrationId nor integrationRecord resolve to a record', async () => {
|
|
11
|
-
const integrationRepository = {
|
|
12
|
-
findIntegrationById: jest.fn().mockResolvedValue(null),
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const useCase = new LoadIntegrationContextUseCase({
|
|
16
|
-
integrationClass: FakeIntegration,
|
|
17
|
-
integrationRepository,
|
|
18
|
-
moduleRepository: { findEntitiesByIds: jest.fn() },
|
|
19
|
-
moduleFactory: { getModuleInstance: jest.fn() },
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
await expect(
|
|
23
|
-
useCase.execute({ integrationId: 'missing-id' })
|
|
24
|
-
).rejects.toMatchObject({
|
|
25
|
-
message: 'Integration record not found',
|
|
26
|
-
code: 'INTEGRATION_RECORD_NOT_FOUND',
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('returns record with empty entities/modules when no entity ids provided', async () => {
|
|
31
|
-
const integrationRecord = {
|
|
32
|
-
id: 'integration-1',
|
|
33
|
-
userId: 'user-1',
|
|
34
|
-
entitiesIds: [],
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const moduleRepository = { findEntitiesByIds: jest.fn() };
|
|
38
|
-
const moduleFactory = { getModuleInstance: jest.fn() };
|
|
39
|
-
|
|
40
|
-
const useCase = new LoadIntegrationContextUseCase({
|
|
41
|
-
integrationClass: FakeIntegration,
|
|
42
|
-
integrationRepository: {},
|
|
43
|
-
moduleRepository,
|
|
44
|
-
moduleFactory,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const result = await useCase.execute({ integrationRecord });
|
|
48
|
-
|
|
49
|
-
expect(result).toEqual({
|
|
50
|
-
record: {
|
|
51
|
-
...integrationRecord,
|
|
52
|
-
entities: [],
|
|
53
|
-
},
|
|
54
|
-
modules: [],
|
|
55
|
-
});
|
|
56
|
-
expect(moduleRepository.findEntitiesByIds).not.toHaveBeenCalled();
|
|
57
|
-
expect(moduleFactory.getModuleInstance).not.toHaveBeenCalled();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('hydrates modules and entities when entity ids are provided', async () => {
|
|
61
|
-
const integrationRecord = {
|
|
62
|
-
id: 'integration-2',
|
|
63
|
-
userId: 'user-2',
|
|
64
|
-
entitiesIds: ['entity-1', 'entity-2'],
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const entities = [
|
|
68
|
-
{ id: 'entity-1', name: 'First Entity' },
|
|
69
|
-
{ id: 'entity-2', name: 'Second Entity' },
|
|
70
|
-
];
|
|
71
|
-
|
|
72
|
-
const modules = [{ name: 'module-1' }, { name: 'module-2' }];
|
|
73
|
-
|
|
74
|
-
const moduleRepository = {
|
|
75
|
-
findEntitiesByIds: jest.fn().mockResolvedValue(entities),
|
|
76
|
-
};
|
|
77
|
-
const moduleFactory = {
|
|
78
|
-
getModuleInstance: jest
|
|
79
|
-
.fn()
|
|
80
|
-
.mockResolvedValueOnce(modules[0])
|
|
81
|
-
.mockResolvedValueOnce(modules[1]),
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const useCase = new LoadIntegrationContextUseCase({
|
|
85
|
-
integrationClass: FakeIntegration,
|
|
86
|
-
integrationRepository: {},
|
|
87
|
-
moduleRepository,
|
|
88
|
-
moduleFactory,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const result = await useCase.execute({ integrationRecord });
|
|
92
|
-
|
|
93
|
-
expect(moduleRepository.findEntitiesByIds).toHaveBeenCalledWith(
|
|
94
|
-
integrationRecord.entitiesIds
|
|
95
|
-
);
|
|
96
|
-
expect(moduleFactory.getModuleInstance).toHaveBeenNthCalledWith(
|
|
97
|
-
1,
|
|
98
|
-
'entity-1',
|
|
99
|
-
integrationRecord.userId
|
|
100
|
-
);
|
|
101
|
-
expect(moduleFactory.getModuleInstance).toHaveBeenNthCalledWith(
|
|
102
|
-
2,
|
|
103
|
-
'entity-2',
|
|
104
|
-
integrationRecord.userId
|
|
105
|
-
);
|
|
106
|
-
expect(result).toEqual({
|
|
107
|
-
record: {
|
|
108
|
-
...integrationRecord,
|
|
109
|
-
entities,
|
|
110
|
-
},
|
|
111
|
-
modules,
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
});
|