@friggframework/core 2.0.0--canary.461.bb7fcba.0 → 2.0.0--canary.461.5767fa4.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.
- 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 +336 -0
- package/generated/prisma-mongodb/index-browser.js +318 -0
- package/generated/prisma-mongodb/index.d.ts +22993 -0
- package/generated/prisma-mongodb/index.js +361 -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 +364 -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 +343 -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 +358 -0
- package/generated/prisma-postgresql/index-browser.js +340 -0
- package/generated/prisma-postgresql/index.d.ts +25171 -0
- package/generated/prisma-postgresql/index.js +383 -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 +347 -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 +365 -0
- package/package.json +5 -5
- package/application/commands/integration-commands.test.js +0 -123
- package/core/Worker.test.js +0 -159
- 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/database/repositories/migration-status-repository-s3.test.js +0 -158
- package/database/use-cases/check-encryption-health-use-case.test.js +0 -192
- package/database/use-cases/get-migration-status-use-case.test.js +0 -171
- package/database/use-cases/run-database-migration-use-case.test.js +0 -310
- package/database/use-cases/trigger-database-migration-use-case.test.js +0 -250
- package/database/utils/prisma-runner.test.js +0 -486
- package/encrypt/Cryptor.test.js +0 -144
- 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 -209
- package/handlers/routers/db-migration.test.js +0 -51
- package/handlers/routers/health.test.js +0 -210
- package/handlers/routers/integration-webhook-routers.test.js +0 -126
- package/handlers/use-cases/check-integrations-health-use-case.test.js +0 -125
- package/handlers/webhook-flow.integration.test.js +0 -356
- package/handlers/workers/db-migration.test.js +0 -50
- package/handlers/workers/integration-defined-workers.test.js +0 -184
- package/integrations/tests/integration-router-multi-auth.test.js +0 -369
- 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/queues/queuer-util.test.js +0 -132
- 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-adopter-jwt.test.js +0 -113
- package/user/tests/use-cases/get-user-from-bearer-token.test.js +0 -64
- package/user/tests/use-cases/get-user-from-x-frigg-headers.test.js +0 -346
- package/user/tests/use-cases/login-user.test.js +0 -220
- package/user/tests/user-password-encryption-isolation.test.js +0 -237
- package/user/tests/user-password-hashing.test.js +0 -235
- package/websocket/repositories/websocket-connection-repository.test.js +0 -227
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const { TimeoutCatcher } = require("./TimeoutCatcher");
|
|
2
|
-
|
|
3
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
4
|
-
|
|
5
|
-
describe("Time Sentinel", () => {
|
|
6
|
-
it("requires a positive wait time", () => {
|
|
7
|
-
try {
|
|
8
|
-
new TimeoutCatcher({
|
|
9
|
-
timeout: 1_000,
|
|
10
|
-
});
|
|
11
|
-
throw new Error("Expected error was not thrown");
|
|
12
|
-
} catch (error) {
|
|
13
|
-
expect(error).toHaveProperty(
|
|
14
|
-
"message",
|
|
15
|
-
"Wait time was not a positive number of milliseconds"
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("exits normally if the work is completed", async () => {
|
|
21
|
-
let cleanUpCalled = false;
|
|
22
|
-
const sentinel = new TimeoutCatcher({
|
|
23
|
-
cleanUp: () => (cleanUpCalled = true),
|
|
24
|
-
timeout: 3_000,
|
|
25
|
-
work: async () => {
|
|
26
|
-
await sleep(500);
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const didFinish = await sentinel.watch();
|
|
31
|
-
expect(didFinish).toEqual(true);
|
|
32
|
-
expect(cleanUpCalled).toEqual(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("terminates before time out if work runs long", async () => {
|
|
36
|
-
let cleanUpCalled = false;
|
|
37
|
-
const sentinel = new TimeoutCatcher({
|
|
38
|
-
cleanUp: () => (cleanUpCalled = true),
|
|
39
|
-
timeout: 3_000,
|
|
40
|
-
work: async () => {
|
|
41
|
-
await sleep(1_500);
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const didFinish = await sentinel.watch();
|
|
46
|
-
expect(didFinish).toEqual(false);
|
|
47
|
-
expect(cleanUpCalled).toEqual(true);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("rethrows unexpected errors", async () => {
|
|
51
|
-
let cleanUpCalled = false;
|
|
52
|
-
const sentinel = new TimeoutCatcher({
|
|
53
|
-
cleanUp: () => (cleanUpCalled = true),
|
|
54
|
-
timeout: 3_000,
|
|
55
|
-
work: async () => {
|
|
56
|
-
throw new Error("Spam spam spam spam");
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
await sentinel.watch();
|
|
62
|
-
throw new Error("Expected error did not occur");
|
|
63
|
-
} catch (error) {
|
|
64
|
-
expect(error).toHaveProperty("message", "Spam spam spam spam");
|
|
65
|
-
expect(cleanUpCalled).toEqual(false);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
});
|
package/logs/logger.test.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
const { debug, initDebugLog, flushDebugLog } = require('./logger');
|
|
2
|
-
const sinon = require('sinon');
|
|
3
|
-
const {
|
|
4
|
-
overrideEnvironment,
|
|
5
|
-
restoreEnvironment,
|
|
6
|
-
} = require('@friggframework/test');
|
|
7
|
-
|
|
8
|
-
/* eslint-disable no-console */
|
|
9
|
-
|
|
10
|
-
describe('Logger', () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
sinon.stub(console, 'debug');
|
|
13
|
-
sinon.stub(console, 'error');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
console.debug.restore();
|
|
18
|
-
console.error.restore();
|
|
19
|
-
restoreEnvironment();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('runs', () => {
|
|
23
|
-
initDebugLog('Test Event', { test: true });
|
|
24
|
-
debug('Add a message', 'or two', { or: 3 });
|
|
25
|
-
flushDebugLog(new Error());
|
|
26
|
-
|
|
27
|
-
expect(console.debug).toHaveProperty('callCount', 2);
|
|
28
|
-
expect(console.error).toHaveProperty('callCount', 1);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('logs immediately when environment variable set', () => {
|
|
32
|
-
overrideEnvironment({ DEBUG_VERBOSE: '1' });
|
|
33
|
-
|
|
34
|
-
debug('Add a message', 'or two', { or: 3 });
|
|
35
|
-
debug('And another');
|
|
36
|
-
|
|
37
|
-
expect(console.debug).toHaveProperty('callCount', 2);
|
|
38
|
-
expect(console.error).toHaveProperty('callCount', 0);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('is resilient to missing parameters', () => {
|
|
42
|
-
initDebugLog();
|
|
43
|
-
debug();
|
|
44
|
-
flushDebugLog();
|
|
45
|
-
|
|
46
|
-
expect(console.debug).toHaveProperty('callCount', 0);
|
|
47
|
-
expect(console.error).toHaveProperty('callCount', 1);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('outputs parent errors', () => {
|
|
51
|
-
initDebugLog();
|
|
52
|
-
|
|
53
|
-
const error = new Error();
|
|
54
|
-
error.cause = new Error();
|
|
55
|
-
error.cause.cause = new Error();
|
|
56
|
-
error.cause.cause.cause = new Error();
|
|
57
|
-
|
|
58
|
-
flushDebugLog(error);
|
|
59
|
-
|
|
60
|
-
expect(console.debug).toHaveProperty('callCount', 0);
|
|
61
|
-
expect(console.error).toHaveProperty('callCount', 7); // 1 + 2 for each cause
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('adds a debug message if more than 1 error encountered', () => {
|
|
65
|
-
initDebugLog();
|
|
66
|
-
flushDebugLog(new Error());
|
|
67
|
-
|
|
68
|
-
expect(console.debug).toHaveProperty('callCount', 0);
|
|
69
|
-
expect(console.error).toHaveProperty('callCount', 1);
|
|
70
|
-
|
|
71
|
-
flushDebugLog(new Error());
|
|
72
|
-
|
|
73
|
-
expect(console.debug).toHaveProperty('callCount', 1);
|
|
74
|
-
expect(console.error).toHaveProperty('callCount', 2);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
@@ -1,205 +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 { Module } = require('./module');
|
|
9
|
-
const { ModuleFactory } = require('./module-factory');
|
|
10
|
-
|
|
11
|
-
// Mock OAuth2Requester base class
|
|
12
|
-
class MockOAuth2Api {
|
|
13
|
-
constructor(params) {
|
|
14
|
-
// Capture all params passed to API constructor
|
|
15
|
-
this.client_id = params.client_id;
|
|
16
|
-
this.client_secret = params.client_secret;
|
|
17
|
-
this.redirect_uri = params.redirect_uri;
|
|
18
|
-
this.scope = params.scope;
|
|
19
|
-
this.access_token = params.access_token;
|
|
20
|
-
this.refresh_token = params.refresh_token;
|
|
21
|
-
this.domain = params.domain;
|
|
22
|
-
this.delegate = params.delegate;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Mock API methods
|
|
26
|
-
async listProjects() {
|
|
27
|
-
if (!this.access_token) {
|
|
28
|
-
throw new Error('No access token provided');
|
|
29
|
-
}
|
|
30
|
-
return { projects: ['project1', 'project2'] };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async getFolders() {
|
|
34
|
-
if (!this.access_token) {
|
|
35
|
-
throw new Error('No access token provided');
|
|
36
|
-
}
|
|
37
|
-
return { folders: ['folder1', 'folder2'] };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
getAuthorizationRequirements() {
|
|
41
|
-
return { type: 'oauth2', url: 'https://example.com/oauth' };
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
MockOAuth2Api.requesterType = 'oauth2';
|
|
46
|
-
|
|
47
|
-
// Mock module definition
|
|
48
|
-
const mockModuleDefinition = {
|
|
49
|
-
moduleName: 'testmodule',
|
|
50
|
-
modelName: 'TestModule',
|
|
51
|
-
API: MockOAuth2Api,
|
|
52
|
-
requiredAuthMethods: {
|
|
53
|
-
getToken: async () => {},
|
|
54
|
-
getEntityDetails: async () => {},
|
|
55
|
-
getCredentialDetails: async () => {},
|
|
56
|
-
apiPropertiesToPersist: {
|
|
57
|
-
credential: ['access_token', 'refresh_token'],
|
|
58
|
-
entity: ['domain'],
|
|
59
|
-
},
|
|
60
|
-
testAuthRequest: async () => true,
|
|
61
|
-
},
|
|
62
|
-
env: {
|
|
63
|
-
client_id: 'test_client_id',
|
|
64
|
-
client_secret: 'test_client_secret',
|
|
65
|
-
redirect_uri: 'https://test.com/redirect',
|
|
66
|
-
scope: 'read write',
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
describe('Module Hydration', () => {
|
|
71
|
-
describe('Module API instantiation', () => {
|
|
72
|
-
it('should create API instance with merged env and credential params', () => {
|
|
73
|
-
const entity = {
|
|
74
|
-
id: 'entity-1',
|
|
75
|
-
moduleName: 'testmodule',
|
|
76
|
-
domain: 'test.domain.com',
|
|
77
|
-
credential: {
|
|
78
|
-
data: {
|
|
79
|
-
access_token: 'test_access_token',
|
|
80
|
-
refresh_token: 'test_refresh_token',
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const module = new Module({
|
|
86
|
-
definition: mockModuleDefinition,
|
|
87
|
-
userId: 'user-1',
|
|
88
|
-
entity,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// Verify module properties
|
|
92
|
-
expect(module.name).toBe('testmodule');
|
|
93
|
-
expect(module.api).toBeDefined();
|
|
94
|
-
|
|
95
|
-
// Verify API was instantiated with correct params
|
|
96
|
-
expect(module.api.client_id).toBe('test_client_id');
|
|
97
|
-
expect(module.api.client_secret).toBe('test_client_secret');
|
|
98
|
-
expect(module.api.redirect_uri).toBe('https://test.com/redirect');
|
|
99
|
-
expect(module.api.scope).toBe('read write');
|
|
100
|
-
expect(module.api.access_token).toBe('test_access_token');
|
|
101
|
-
expect(module.api.refresh_token).toBe('test_refresh_token');
|
|
102
|
-
expect(module.api.domain).toBe('test.domain.com');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should allow API methods to be called with credentials', async () => {
|
|
106
|
-
const entity = {
|
|
107
|
-
id: 'entity-1',
|
|
108
|
-
moduleName: 'testmodule',
|
|
109
|
-
credential: {
|
|
110
|
-
data: {
|
|
111
|
-
access_token: 'valid_token',
|
|
112
|
-
refresh_token: 'valid_refresh_token',
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const module = new Module({
|
|
118
|
-
definition: mockModuleDefinition,
|
|
119
|
-
userId: 'user-1',
|
|
120
|
-
entity,
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// Test that API methods work with credentials
|
|
124
|
-
const projects = await module.api.listProjects();
|
|
125
|
-
expect(projects).toEqual({ projects: ['project1', 'project2'] });
|
|
126
|
-
|
|
127
|
-
const folders = await module.api.getFolders();
|
|
128
|
-
expect(folders).toEqual({ folders: ['folder1', 'folder2'] });
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should handle missing credentials gracefully', () => {
|
|
132
|
-
const entity = {
|
|
133
|
-
id: 'entity-1',
|
|
134
|
-
moduleName: 'testmodule',
|
|
135
|
-
credential: {
|
|
136
|
-
data: {
|
|
137
|
-
// Empty credential data - no access_token
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const module = new Module({
|
|
143
|
-
definition: mockModuleDefinition,
|
|
144
|
-
userId: 'user-1',
|
|
145
|
-
entity,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// API should still be created with env params only
|
|
149
|
-
expect(module.api).toBeDefined();
|
|
150
|
-
expect(module.api.client_id).toBe('test_client_id');
|
|
151
|
-
expect(module.api.access_token).toBeUndefined();
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
describe('ModuleFactory', () => {
|
|
156
|
-
it('should create module instance from entity and definition', async () => {
|
|
157
|
-
const entity = {
|
|
158
|
-
id: 'entity-1',
|
|
159
|
-
moduleName: 'testmodule',
|
|
160
|
-
userId: 'user-1',
|
|
161
|
-
credential: {
|
|
162
|
-
data: {
|
|
163
|
-
access_token: 'factory_token',
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const moduleRepository = {
|
|
169
|
-
findEntityById: jest.fn().mockResolvedValue(entity),
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const factory = new ModuleFactory({
|
|
173
|
-
moduleRepository,
|
|
174
|
-
moduleDefinitions: [mockModuleDefinition],
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
const module = await factory.getModuleInstance('entity-1', 'user-1');
|
|
178
|
-
|
|
179
|
-
expect(module).toBeDefined();
|
|
180
|
-
expect(module.api).toBeDefined();
|
|
181
|
-
expect(module.api.access_token).toBe('factory_token');
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it('should throw error if module definition not found', async () => {
|
|
185
|
-
const entity = {
|
|
186
|
-
id: 'entity-1',
|
|
187
|
-
moduleName: 'unknownmodule',
|
|
188
|
-
userId: 'user-1',
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
const moduleRepository = {
|
|
192
|
-
findEntityById: jest.fn().mockResolvedValue(entity),
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
const factory = new ModuleFactory({
|
|
196
|
-
moduleRepository,
|
|
197
|
-
moduleDefinitions: [mockModuleDefinition],
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
await expect(
|
|
201
|
-
factory.getModuleInstance('entity-1', 'user-1')
|
|
202
|
-
).rejects.toThrow('Module definition not found for module: unknownmodule');
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const { Requester } = require('./requester');
|
|
2
|
-
|
|
3
|
-
describe('429 and 5xx testing', () => {
|
|
4
|
-
let backOffArray = [1, 1, 1];
|
|
5
|
-
let requester = new Requester({ backOff: backOffArray });
|
|
6
|
-
let sum = backOffArray.reduce((a, b) => {
|
|
7
|
-
return a + b;
|
|
8
|
-
}, 0);
|
|
9
|
-
it.skip("should retry with 'exponential' back off due to 429", async () => {
|
|
10
|
-
let startTime = await Date.now();
|
|
11
|
-
let res = await requester._get({
|
|
12
|
-
url: 'https://70e18ff0-1967-4fb5-8f96-10477ab6bb9e.mock.pstmn.io//429',
|
|
13
|
-
});
|
|
14
|
-
let endTime = await Date.now();
|
|
15
|
-
let difference = endTime - startTime;
|
|
16
|
-
expect(difference).toBeGreaterThan(sum * 1000);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it.skip("should retry with 'exponential' back off due to 500", async () => {
|
|
20
|
-
let startTime = await Date.now();
|
|
21
|
-
let res = await requester._get({
|
|
22
|
-
url: 'https://70e18ff0-1967-4fb5-8f96-10477ab6bb9e.mock.pstmn.io//5xx',
|
|
23
|
-
});
|
|
24
|
-
let endTime = await Date.now();
|
|
25
|
-
let difference = endTime - startTime;
|
|
26
|
-
expect(difference).toBeGreaterThan(sum * 1000);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for QueuerUtil - AWS SDK v3 Migration
|
|
3
|
-
*
|
|
4
|
-
* Tests SQS operations using aws-sdk-client-mock
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { mockClient } = require('aws-sdk-client-mock');
|
|
8
|
-
const { SQSClient, SendMessageCommand, SendMessageBatchCommand } = require('@aws-sdk/client-sqs');
|
|
9
|
-
const { QueuerUtil } = require('./queuer-util');
|
|
10
|
-
|
|
11
|
-
describe('QueuerUtil - AWS SDK v3', () => {
|
|
12
|
-
let sqsMock;
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
sqsMock = mockClient(SQSClient);
|
|
16
|
-
jest.clearAllMocks();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
sqsMock.reset();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('send()', () => {
|
|
24
|
-
it('should send single message to SQS', async () => {
|
|
25
|
-
sqsMock.on(SendMessageCommand).resolves({
|
|
26
|
-
MessageId: 'test-message-id-123'
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const message = { test: 'data', id: 1 };
|
|
30
|
-
const queueUrl = 'https://sqs.us-east-1.amazonaws.com/123456789/test-queue';
|
|
31
|
-
|
|
32
|
-
const result = await QueuerUtil.send(message, queueUrl);
|
|
33
|
-
|
|
34
|
-
expect(result.MessageId).toBe('test-message-id-123');
|
|
35
|
-
expect(sqsMock.calls()).toHaveLength(1);
|
|
36
|
-
|
|
37
|
-
const call = sqsMock.call(0);
|
|
38
|
-
expect(call.args[0].input).toMatchObject({
|
|
39
|
-
MessageBody: JSON.stringify(message),
|
|
40
|
-
QueueUrl: queueUrl,
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should handle SQS errors', async () => {
|
|
45
|
-
sqsMock.on(SendMessageCommand).rejects(new Error('SQS Error'));
|
|
46
|
-
|
|
47
|
-
const message = { test: 'data' };
|
|
48
|
-
const queueUrl = 'https://sqs.us-east-1.amazonaws.com/123456789/test-queue';
|
|
49
|
-
|
|
50
|
-
await expect(QueuerUtil.send(message, queueUrl)).rejects.toThrow('SQS Error');
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('batchSend()', () => {
|
|
55
|
-
it('should send batch of messages to SQS', async () => {
|
|
56
|
-
sqsMock.on(SendMessageBatchCommand).resolves({
|
|
57
|
-
Successful: [{ MessageId: 'msg-1' }],
|
|
58
|
-
Failed: []
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const entries = Array(5).fill().map((_, i) => ({ data: `test-${i}` }));
|
|
62
|
-
const queueUrl = 'https://sqs.us-east-1.amazonaws.com/123456789/test-queue';
|
|
63
|
-
|
|
64
|
-
const result = await QueuerUtil.batchSend(entries, queueUrl);
|
|
65
|
-
|
|
66
|
-
expect(sqsMock.calls()).toHaveLength(1);
|
|
67
|
-
|
|
68
|
-
const call = sqsMock.call(0);
|
|
69
|
-
expect(call.args[0].input.Entries).toHaveLength(5);
|
|
70
|
-
expect(call.args[0].input.QueueUrl).toBe(queueUrl);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should send multiple batches for large entry sets (10 per batch)', async () => {
|
|
74
|
-
sqsMock.on(SendMessageBatchCommand).resolves({
|
|
75
|
-
Successful: [],
|
|
76
|
-
Failed: []
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const entries = Array(25).fill().map((_, i) => ({ data: `test-${i}` }));
|
|
80
|
-
const queueUrl = 'https://sqs.us-east-1.amazonaws.com/123456789/test-queue';
|
|
81
|
-
|
|
82
|
-
await QueuerUtil.batchSend(entries, queueUrl);
|
|
83
|
-
|
|
84
|
-
// Should send 3 batches (10 + 10 + 5)
|
|
85
|
-
expect(sqsMock.calls()).toHaveLength(3);
|
|
86
|
-
|
|
87
|
-
expect(sqsMock.call(0).args[0].input.Entries).toHaveLength(10);
|
|
88
|
-
expect(sqsMock.call(1).args[0].input.Entries).toHaveLength(10);
|
|
89
|
-
expect(sqsMock.call(2).args[0].input.Entries).toHaveLength(5);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should handle empty entries array', async () => {
|
|
93
|
-
const result = await QueuerUtil.batchSend([], 'https://queue-url');
|
|
94
|
-
|
|
95
|
-
expect(result).toEqual({});
|
|
96
|
-
expect(sqsMock.calls()).toHaveLength(0);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should send exact batch of 10 without remainder', async () => {
|
|
100
|
-
sqsMock.on(SendMessageBatchCommand).resolves({
|
|
101
|
-
Successful: [],
|
|
102
|
-
Failed: []
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const entries = Array(10).fill().map((_, i) => ({ data: `test-${i}` }));
|
|
106
|
-
const queueUrl = 'https://sqs.us-east-1.amazonaws.com/123456789/test-queue';
|
|
107
|
-
|
|
108
|
-
const result = await QueuerUtil.batchSend(entries, queueUrl);
|
|
109
|
-
|
|
110
|
-
expect(sqsMock.calls()).toHaveLength(1);
|
|
111
|
-
expect(result).toEqual({}); // Returns empty object when exact batch
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should generate unique IDs for each entry', async () => {
|
|
115
|
-
sqsMock.on(SendMessageBatchCommand).resolves({
|
|
116
|
-
Successful: [],
|
|
117
|
-
Failed: []
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
const entries = [{ data: 'test-1' }, { data: 'test-2' }];
|
|
121
|
-
const queueUrl = 'https://sqs.us-east-1.amazonaws.com/123456789/test-queue';
|
|
122
|
-
|
|
123
|
-
await QueuerUtil.batchSend(entries, queueUrl);
|
|
124
|
-
|
|
125
|
-
const sentEntries = sqsMock.call(0).args[0].input.Entries;
|
|
126
|
-
expect(sentEntries[0].Id).toBeDefined();
|
|
127
|
-
expect(sentEntries[1].Id).toBeDefined();
|
|
128
|
-
expect(sentEntries[0].Id).not.toBe(sentEntries[1].Id);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
CreateIndividualUser,
|
|
3
|
-
} = require('../../use-cases/create-individual-user');
|
|
4
|
-
const { TestUserRepository } = require('../doubles/test-user-repository');
|
|
5
|
-
|
|
6
|
-
describe('CreateIndividualUser Use Case', () => {
|
|
7
|
-
it('should create and return an individual user via the repository', async () => {
|
|
8
|
-
const userConfig = { usePassword: true };
|
|
9
|
-
const userRepository = new TestUserRepository({ userConfig });
|
|
10
|
-
const createIndividualUser = new CreateIndividualUser({
|
|
11
|
-
userRepository,
|
|
12
|
-
userConfig,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const params = {
|
|
16
|
-
username: 'test-user',
|
|
17
|
-
password: 'password123',
|
|
18
|
-
};
|
|
19
|
-
const user = await createIndividualUser.execute(params);
|
|
20
|
-
|
|
21
|
-
expect(user).toBeDefined();
|
|
22
|
-
expect(user.getIndividualUser().username).toBe(params.username);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
CreateOrganizationUser,
|
|
3
|
-
} = require('../../use-cases/create-organization-user');
|
|
4
|
-
const { TestUserRepository } = require('../doubles/test-user-repository');
|
|
5
|
-
|
|
6
|
-
describe('CreateOrganizationUser Use Case', () => {
|
|
7
|
-
it('should create and return an organization user via the repository', async () => {
|
|
8
|
-
const userConfig = {
|
|
9
|
-
primary: 'organization',
|
|
10
|
-
organizationUserRequired: true,
|
|
11
|
-
individualUserRequired: false,
|
|
12
|
-
};
|
|
13
|
-
const userRepository = new TestUserRepository({ userConfig });
|
|
14
|
-
const createOrganizationUser = new CreateOrganizationUser({
|
|
15
|
-
userRepository,
|
|
16
|
-
userConfig,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const params = {
|
|
20
|
-
name: 'Test Org',
|
|
21
|
-
appOrgId: 'org-123',
|
|
22
|
-
};
|
|
23
|
-
const user = await createOrganizationUser.execute(params);
|
|
24
|
-
|
|
25
|
-
expect(user).toBeDefined();
|
|
26
|
-
expect(user.getOrganizationUser().name).toBe(params.name);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
CreateTokenForUserId,
|
|
3
|
-
} = require('../../use-cases/create-token-for-user-id');
|
|
4
|
-
const { TestUserRepository } = require('../doubles/test-user-repository');
|
|
5
|
-
|
|
6
|
-
describe('CreateTokenForUserId Use Case', () => {
|
|
7
|
-
it('should create and return a token via the repository', async () => {
|
|
8
|
-
const userConfig = {}; // Not used by this use case, but required by the test repo
|
|
9
|
-
const userRepository = new TestUserRepository({ userConfig });
|
|
10
|
-
const createTokenForUserId = new CreateTokenForUserId({ userRepository });
|
|
11
|
-
|
|
12
|
-
const userId = 'user-123';
|
|
13
|
-
const token = await createTokenForUserId.execute(userId);
|
|
14
|
-
|
|
15
|
-
expect(token).toBeDefined();
|
|
16
|
-
// The mock token is deterministic, so we can check it
|
|
17
|
-
expect(token).toContain(`token-for-${userId}`);
|
|
18
|
-
});
|
|
19
|
-
});
|