-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathCloudCodeAdapter.integration.spec.js
More file actions
107 lines (90 loc) · 3.69 KB
/
CloudCodeAdapter.integration.spec.js
File metadata and controls
107 lines (90 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict';
const { CloudCodeManager } = require('../lib/cloud-code/CloudCodeManager');
const { InProcessAdapter } = require('../lib/cloud-code/adapters/InProcessAdapter');
describe('Cloud Code Adapter Integration', () => {
describe('composable adapters', () => {
it('supports multiple adapters registering different hooks', async () => {
const manager = new CloudCodeManager();
const inProcessCloud = {
getRouter() {
return {
getManifest() {
return {
protocol: 'ParseCloud/1.0',
hooks: {
functions: [{ name: 'inProcessFn' }],
triggers: [],
jobs: [],
},
};
},
async dispatchFunction() { return { success: 'from-in-process' }; },
async dispatchTrigger() { return { success: {} }; },
async dispatchJob() { return { success: null }; },
};
},
};
const inProcessAdapter = new InProcessAdapter(inProcessCloud);
const inProcessRegistry = manager.createRegistry(inProcessAdapter.name);
await inProcessAdapter.initialize(inProcessRegistry, { appId: 'test', masterKey: 'mk', serverURL: 'http://localhost' });
// Simulate legacy registration via manager directly
manager.defineFunction('legacyFn', () => 'from-legacy', 'legacy');
const legacyEntry = manager.getFunction('legacyFn');
expect(legacyEntry).toBeDefined();
expect(manager.getFunction('inProcessFn')).toBeDefined();
expect(manager.getFunctionNames().sort()).toEqual(['inProcessFn', 'legacyFn']);
});
it('throws on conflict between adapters', async () => {
const manager = new CloudCodeManager();
// Register a function from "legacy" source
manager.defineFunction('shared', () => 'from-legacy', 'legacy');
// InProcess adapter tries to register same function
const inProcessCloud = {
getRouter() {
return {
getManifest() {
return {
protocol: 'ParseCloud/1.0',
hooks: { functions: [{ name: 'shared' }], triggers: [], jobs: [] },
};
},
async dispatchFunction() { return { success: 'from-in-process' }; },
async dispatchTrigger() { return { success: {} }; },
async dispatchJob() { return { success: null }; },
};
},
};
const adapter = new InProcessAdapter(inProcessCloud);
const registry = manager.createRegistry(adapter.name);
await expectAsync(
adapter.initialize(registry, { appId: 'test', masterKey: 'mk', serverURL: 'http://localhost' })
).toBeRejectedWithError(/already registered/);
});
});
describe('shutdown', () => {
it('shuts down all adapters', async () => {
const manager = new CloudCodeManager();
let shutdownCalled = false;
const adapter = {
name: 'test',
async initialize() {},
async isHealthy() { return true; },
async shutdown() { shutdownCalled = true; },
};
await manager.initialize([adapter], { appId: 'test', masterKey: 'mk', serverURL: 'http://localhost' });
await manager.shutdown();
expect(shutdownCalled).toBe(true);
});
});
describe('unregisterAll', () => {
it('allows re-registration after unregisterAll', () => {
const manager = new CloudCodeManager();
manager.defineFunction('fn', () => 'first', 'adapter-a');
manager.unregisterAll('adapter-a');
expect(() => {
manager.defineFunction('fn', () => 'second', 'adapter-b');
}).not.toThrow();
expect(manager.getFunction('fn')).toBeDefined();
});
});
});