@kumori/aurora-backend-handler 1.1.41 → 1.1.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/.gitlab-ci.yml +21 -21
- package/jest.config.ts +1 -0
- package/package.json +2 -2
- package/test/backend-handler.test.ts +992 -730
- package/test/deploy-service-helper.test.ts +678 -274
- package/test/event-helper.test.ts +489 -104
- package/test/event-names.test.ts +186 -0
|
@@ -1,152 +1,537 @@
|
|
|
1
|
-
|
|
2
1
|
import EventHelper from '../event-helper';
|
|
3
|
-
import { EventNames } from '
|
|
2
|
+
import { EventNames } from '../event-names';
|
|
3
|
+
|
|
4
|
+
const makeMockHandler = () => ({
|
|
5
|
+
publish: jest.fn(),
|
|
6
|
+
subscribe: jest.fn(),
|
|
7
|
+
unsubscribe: jest.fn(),
|
|
8
|
+
});
|
|
4
9
|
|
|
5
10
|
beforeEach(() => {
|
|
6
11
|
jest.clearAllMocks();
|
|
7
12
|
});
|
|
8
13
|
|
|
9
|
-
describe('EventHelper', () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
describe('EventHelper - createEvent defensive branches', () => {
|
|
15
|
+
it('log error cuando globalEventHandler es null', () => {
|
|
16
|
+
const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
17
|
+
const helper = new EventHelper(null as any);
|
|
18
|
+
try { helper.tenant.publish.creation({} as any); } catch {}
|
|
19
|
+
expect(consoleSpy).toHaveBeenCalled();
|
|
20
|
+
consoleSpy.mockRestore();
|
|
21
|
+
});
|
|
17
22
|
|
|
23
|
+
it('log error cuando subscribe no existe en el handler', () => {
|
|
24
|
+
const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
25
|
+
const handler = { publish: jest.fn(), unsubscribe: jest.fn() } as any;
|
|
26
|
+
const helper = new EventHelper(handler);
|
|
27
|
+
try { helper.tenant.subscribe.creation(() => {}); } catch {}
|
|
28
|
+
expect(consoleSpy).toHaveBeenCalled();
|
|
29
|
+
consoleSpy.mockRestore();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
18
32
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
describe('EventHelper - Tenant events', () => {
|
|
34
|
+
const handler = makeMockHandler();
|
|
35
|
+
const helper = new EventHelper(handler);
|
|
36
|
+
|
|
37
|
+
const events: Array<{ method: string; eventName: EventNames }> = [
|
|
38
|
+
{ method: 'creation', eventName: EventNames.CreateTenant },
|
|
39
|
+
{ method: 'created', eventName: EventNames.TenantCreated },
|
|
40
|
+
{ method: 'creationError', eventName: EventNames.TenantCreationError },
|
|
41
|
+
{ method: 'update', eventName: EventNames.UpdateTenant },
|
|
42
|
+
{ method: 'updated', eventName: EventNames.TenantUpdated },
|
|
43
|
+
{ method: 'updateError', eventName: EventNames.TenantUpdateError },
|
|
44
|
+
{ method: 'delete', eventName: EventNames.DeleteTenant },
|
|
45
|
+
{ method: 'deleted', eventName: EventNames.TenantDeleted },
|
|
46
|
+
{ method: 'deletionError', eventName: EventNames.TenantDeletionError },
|
|
47
|
+
{ method: 'createRegistry', eventName: EventNames.CreateRegistry },
|
|
48
|
+
{ method: 'registryCreated', eventName: EventNames.RegistryCreated },
|
|
49
|
+
{ method: 'registryCreationError', eventName: EventNames.RegistryCreationError },
|
|
50
|
+
{ method: 'updateRegistry', eventName: EventNames.UpdateRegistry },
|
|
51
|
+
{ method: 'registryUpdated', eventName: EventNames.RegistryUpdated },
|
|
52
|
+
{ method: 'registryUpdateError', eventName: EventNames.RegistryUpdateError },
|
|
53
|
+
{ method: 'deleteRegistry', eventName: EventNames.DeleteRegistry },
|
|
54
|
+
{ method: 'registryDeleted', eventName: EventNames.RegistryDeleted },
|
|
55
|
+
{ method: 'registryDeletionError', eventName: EventNames.RegistryDeletionError },
|
|
56
|
+
{ method: 'inviteUser', eventName: EventNames.InviteUser },
|
|
57
|
+
{ method: 'userInvited', eventName: EventNames.UserInvited },
|
|
58
|
+
{ method: 'inviteError', eventName: EventNames.UserInviteError },
|
|
59
|
+
{ method: 'removeUser', eventName: EventNames.RemoveUserFromTenant },
|
|
60
|
+
{ method: 'userRemoved', eventName: EventNames.UserRemovedFromTenant },
|
|
61
|
+
{ method: 'removeUserError', eventName: EventNames.UserRemovalFromTenantError },
|
|
62
|
+
{ method: 'acceptInvite', eventName: EventNames.AcceptInvite },
|
|
63
|
+
{ method: 'inviteAccepted', eventName: EventNames.InviteAccepted },
|
|
64
|
+
{ method: 'acceptInviteError', eventName: EventNames.InviteAcceptError },
|
|
65
|
+
{ method: 'updateInvite', eventName: EventNames.UpdateInvite },
|
|
66
|
+
{ method: 'inviteUpdated', eventName: EventNames.InviteUpdated },
|
|
67
|
+
{ method: 'inviteUpdateError', eventName: EventNames.InviteUpdateError },
|
|
68
|
+
{ method: 'rejectInvite', eventName: EventNames.RejectInvite },
|
|
69
|
+
{ method: 'inviteRejected', eventName: EventNames.InviteRejected },
|
|
70
|
+
{ method: 'inviteRejectError', eventName: EventNames.InviteRejectError },
|
|
71
|
+
{ method: 'createToken', eventName: EventNames.CreateToken },
|
|
72
|
+
{ method: 'tokenCreated', eventName: EventNames.TokenCreated },
|
|
73
|
+
{ method: 'tokenCreationError', eventName: EventNames.TokenCreationError },
|
|
74
|
+
{ method: 'deleteToken', eventName: EventNames.DeleteToken },
|
|
75
|
+
{ method: 'tokenDeleted', eventName: EventNames.TokenDeleted },
|
|
76
|
+
{ method: 'tokenDeletionError', eventName: EventNames.TokenDeletionError },
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
events.forEach(({ method, eventName }) => {
|
|
80
|
+
it(`tenant.publish.${method} usa ${eventName}`, () => {
|
|
81
|
+
jest.clearAllMocks();
|
|
82
|
+
const payload = {};
|
|
83
|
+
(helper.tenant.publish as any)[method](payload);
|
|
84
|
+
expect(handler.publish).toHaveBeenCalledWith(eventName, payload);
|
|
26
85
|
});
|
|
27
86
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
expect(
|
|
87
|
+
it(`tenant.subscribe.${method} usa ${eventName}`, () => {
|
|
88
|
+
jest.clearAllMocks();
|
|
89
|
+
const cb = jest.fn();
|
|
90
|
+
(helper.tenant.subscribe as any)[method](cb);
|
|
91
|
+
expect(handler.subscribe).toHaveBeenCalledWith(eventName, cb);
|
|
33
92
|
});
|
|
34
93
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
expect(
|
|
94
|
+
it(`tenant.unsubscribe.${method} usa ${eventName}`, () => {
|
|
95
|
+
jest.clearAllMocks();
|
|
96
|
+
const cb = jest.fn();
|
|
97
|
+
(helper.tenant.unsubscribe as any)[method](cb);
|
|
98
|
+
expect(handler.unsubscribe).toHaveBeenCalledWith(eventName, cb);
|
|
40
99
|
});
|
|
41
100
|
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('EventHelper - User events', () => {
|
|
104
|
+
const handler = makeMockHandler();
|
|
105
|
+
const helper = new EventHelper(handler);
|
|
106
|
+
|
|
107
|
+
const events: Array<{ method: string; eventName: EventNames }> = [
|
|
108
|
+
{ method: 'creation', eventName: EventNames.CreateUser },
|
|
109
|
+
{ method: 'created', eventName: EventNames.UserCreated },
|
|
110
|
+
{ method: 'creationError', eventName: EventNames.UserCreationError },
|
|
111
|
+
{ method: 'update', eventName: EventNames.UpdateUser },
|
|
112
|
+
{ method: 'updated', eventName: EventNames.UserUpdated },
|
|
113
|
+
{ method: 'updateError', eventName: EventNames.UserUpdateError },
|
|
114
|
+
{ method: 'load', eventName: EventNames.LoadUser },
|
|
115
|
+
{ method: 'loaded', eventName: EventNames.UserLoaded },
|
|
116
|
+
{ method: 'loadError', eventName: EventNames.UserLoadError },
|
|
117
|
+
{ method: 'delete', eventName: EventNames.DeleteUser },
|
|
118
|
+
{ method: 'deleted', eventName: EventNames.UserDeleted },
|
|
119
|
+
{ method: 'deletionError', eventName: EventNames.UserDeletionError },
|
|
120
|
+
{ method: 'authError', eventName: EventNames.AuthError },
|
|
121
|
+
];
|
|
42
122
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
eventHelper.user.publish.creation(payload as any);
|
|
49
|
-
expect(spy).toHaveBeenCalledWith(EventNames.CreateUser, payload);
|
|
123
|
+
events.forEach(({ method, eventName }) => {
|
|
124
|
+
it(`user.publish.${method} usa ${eventName}`, () => {
|
|
125
|
+
jest.clearAllMocks();
|
|
126
|
+
(helper.user.publish as any)[method]({});
|
|
127
|
+
expect(handler.publish).toHaveBeenCalledWith(eventName, {});
|
|
50
128
|
});
|
|
51
129
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
expect(
|
|
130
|
+
it(`user.subscribe.${method} usa ${eventName}`, () => {
|
|
131
|
+
jest.clearAllMocks();
|
|
132
|
+
const cb = jest.fn();
|
|
133
|
+
(helper.user.subscribe as any)[method](cb);
|
|
134
|
+
expect(handler.subscribe).toHaveBeenCalledWith(eventName, cb);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it(`user.unsubscribe.${method} usa ${eventName}`, () => {
|
|
138
|
+
jest.clearAllMocks();
|
|
139
|
+
const cb = jest.fn();
|
|
140
|
+
(helper.user.unsubscribe as any)[method](cb);
|
|
141
|
+
expect(handler.unsubscribe).toHaveBeenCalledWith(eventName, cb);
|
|
57
142
|
});
|
|
58
143
|
});
|
|
144
|
+
});
|
|
59
145
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
146
|
+
describe('EventHelper - Account events', () => {
|
|
147
|
+
const handler = makeMockHandler();
|
|
148
|
+
const helper = new EventHelper(handler);
|
|
149
|
+
|
|
150
|
+
const events: Array<{ method: string; eventName: EventNames }> = [
|
|
151
|
+
{ method: 'creation', eventName: EventNames.CreateAccount },
|
|
152
|
+
{ method: 'created', eventName: EventNames.AccountCreated },
|
|
153
|
+
{ method: 'creationError', eventName: EventNames.AccountCreationError },
|
|
154
|
+
{ method: 'update', eventName: EventNames.UpdateAccount },
|
|
155
|
+
{ method: 'updated', eventName: EventNames.AccountUpdated },
|
|
156
|
+
{ method: 'updateError', eventName: EventNames.AccountUpdateError },
|
|
157
|
+
{ method: 'delete', eventName: EventNames.DeleteAccount },
|
|
158
|
+
{ method: 'deleted', eventName: EventNames.AccountDeleted },
|
|
159
|
+
{ method: 'deletionError', eventName: EventNames.AccountDeletionError },
|
|
160
|
+
{ method: 'clean', eventName: EventNames.CleanAccount },
|
|
161
|
+
{ method: 'cleaned', eventName: EventNames.AccountCleaned },
|
|
162
|
+
{ method: 'cleanError', eventName: EventNames.AccountCleanError },
|
|
163
|
+
];
|
|
164
|
+
|
|
165
|
+
events.forEach(({ method, eventName }) => {
|
|
166
|
+
it(`account.publish.${method} usa ${eventName}`, () => {
|
|
167
|
+
jest.clearAllMocks();
|
|
168
|
+
(helper.account.publish as any)[method]({});
|
|
169
|
+
expect(handler.publish).toHaveBeenCalledWith(eventName, {});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it(`account.subscribe.${method} usa ${eventName}`, () => {
|
|
173
|
+
jest.clearAllMocks();
|
|
174
|
+
const cb = jest.fn();
|
|
175
|
+
(helper.account.subscribe as any)[method](cb);
|
|
176
|
+
expect(handler.subscribe).toHaveBeenCalledWith(eventName, cb);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it(`account.unsubscribe.${method} usa ${eventName}`, () => {
|
|
180
|
+
jest.clearAllMocks();
|
|
181
|
+
const cb = jest.fn();
|
|
182
|
+
(helper.account.unsubscribe as any)[method](cb);
|
|
183
|
+
expect(handler.unsubscribe).toHaveBeenCalledWith(eventName, cb);
|
|
67
184
|
});
|
|
68
185
|
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe('EventHelper - Environment events', () => {
|
|
189
|
+
const handler = makeMockHandler();
|
|
190
|
+
const helper = new EventHelper(handler);
|
|
69
191
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
192
|
+
const events: Array<{ method: string; eventName: EventNames }> = [
|
|
193
|
+
{ method: 'creation', eventName: EventNames.CreateEnvironment },
|
|
194
|
+
{ method: 'created', eventName: EventNames.EnvironmentCreated },
|
|
195
|
+
{ method: 'creationError', eventName: EventNames.EnvironmentCreationError },
|
|
196
|
+
{ method: 'update', eventName: EventNames.UpdateEnvironment },
|
|
197
|
+
{ method: 'updated', eventName: EventNames.EnvironmentUpdated },
|
|
198
|
+
{ method: 'updateError', eventName: EventNames.EnvironmentUpdateError },
|
|
199
|
+
{ method: 'delete', eventName: EventNames.DeleteEnvironment },
|
|
200
|
+
{ method: 'deleted', eventName: EventNames.EnvironmentDeleted },
|
|
201
|
+
{ method: 'deletionError', eventName: EventNames.EvironmentDeletionError },
|
|
202
|
+
{ method: 'clean', eventName: EventNames.CleanEnvironment },
|
|
203
|
+
{ method: 'cleaned', eventName: EventNames.EnvironmentCleaned },
|
|
204
|
+
{ method: 'cleanError', eventName: EventNames.EnvironmentCleanError },
|
|
205
|
+
{ method: 'scale', eventName: EventNames.ScaleEnvironment },
|
|
206
|
+
{ method: 'scaled', eventName: EventNames.EnvironmentScaled },
|
|
207
|
+
{ method: 'scaleError', eventName: EventNames.EnvironmentScaleError },
|
|
208
|
+
];
|
|
209
|
+
|
|
210
|
+
events.forEach(({ method, eventName }) => {
|
|
211
|
+
it(`environment.publish.${method} usa ${eventName}`, () => {
|
|
212
|
+
jest.clearAllMocks();
|
|
213
|
+
(helper.environment.publish as any)[method]({});
|
|
214
|
+
expect(handler.publish).toHaveBeenCalledWith(eventName, {});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it(`environment.subscribe.${method} usa ${eventName}`, () => {
|
|
218
|
+
jest.clearAllMocks();
|
|
219
|
+
const cb = jest.fn();
|
|
220
|
+
(helper.environment.subscribe as any)[method](cb);
|
|
221
|
+
expect(handler.subscribe).toHaveBeenCalledWith(eventName, cb);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it(`environment.unsubscribe.${method} usa ${eventName}`, () => {
|
|
225
|
+
jest.clearAllMocks();
|
|
226
|
+
const cb = jest.fn();
|
|
227
|
+
(helper.environment.unsubscribe as any)[method](cb);
|
|
228
|
+
expect(handler.unsubscribe).toHaveBeenCalledWith(eventName, cb);
|
|
77
229
|
});
|
|
78
230
|
});
|
|
231
|
+
});
|
|
79
232
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
233
|
+
describe('EventHelper - Service events', () => {
|
|
234
|
+
const handler = makeMockHandler();
|
|
235
|
+
const helper = new EventHelper(handler);
|
|
236
|
+
|
|
237
|
+
const events: Array<{ method: string; eventName: EventNames }> = [
|
|
238
|
+
{ method: 'deploy', eventName: EventNames.DeployService },
|
|
239
|
+
{ method: 'deployed', eventName: EventNames.ServiceDeployed },
|
|
240
|
+
{ method: 'deploymentError', eventName: EventNames.ServiceDeploymentError },
|
|
241
|
+
{ method: 'update', eventName: EventNames.UpdateService },
|
|
242
|
+
{ method: 'updated', eventName: EventNames.ServiceUpdated },
|
|
243
|
+
{ method: 'updateError', eventName: EventNames.ServiceUpdateError },
|
|
244
|
+
{ method: 'delete', eventName: EventNames.DeleteService },
|
|
245
|
+
{ method: 'deleted', eventName: EventNames.ServiceDeleted },
|
|
246
|
+
{ method: 'deletionError', eventName: EventNames.ServiceDeletionError },
|
|
247
|
+
{ method: 'requestLogs', eventName: EventNames.RequestLogs },
|
|
248
|
+
{ method: 'restart', eventName: EventNames.RestartService },
|
|
249
|
+
{ method: 'restarted', eventName: EventNames.ServiceRestarted },
|
|
250
|
+
{ method: 'restartError', eventName: EventNames.ServiceRestartError },
|
|
251
|
+
{ method: 'requestRevisionData', eventName: EventNames.RequestRevisionData },
|
|
252
|
+
{ method: 'updateServiceLinks', eventName: EventNames.updateServiceLinks },
|
|
253
|
+
{ method: 'changeRevision', eventName: EventNames.ChangeRevision },
|
|
254
|
+
{ method: 'revisionChanged', eventName: EventNames.RevisionChanged },
|
|
255
|
+
{ method: 'revisionChangeError', eventName: EventNames.RevisionChangeError },
|
|
256
|
+
{ method: 'restartInstance', eventName: EventNames.RestartInstance },
|
|
257
|
+
{ method: 'instanceRestarted', eventName: EventNames.InstanceRestarted },
|
|
258
|
+
{ method: 'instanceRestartError', eventName: EventNames.InstanceRestartError },
|
|
259
|
+
];
|
|
260
|
+
|
|
261
|
+
events.forEach(({ method, eventName }) => {
|
|
262
|
+
it(`service.publish.${method} usa ${eventName}`, () => {
|
|
263
|
+
jest.clearAllMocks();
|
|
264
|
+
(helper.service.publish as any)[method]({});
|
|
265
|
+
expect(handler.publish).toHaveBeenCalledWith(eventName, {});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it(`service.subscribe.${method} usa ${eventName}`, () => {
|
|
269
|
+
jest.clearAllMocks();
|
|
270
|
+
const cb = jest.fn();
|
|
271
|
+
(helper.service.subscribe as any)[method](cb);
|
|
272
|
+
expect(handler.subscribe).toHaveBeenCalledWith(eventName, cb);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it(`service.unsubscribe.${method} usa ${eventName}`, () => {
|
|
276
|
+
jest.clearAllMocks();
|
|
277
|
+
const cb = jest.fn();
|
|
278
|
+
(helper.service.unsubscribe as any)[method](cb);
|
|
279
|
+
expect(handler.unsubscribe).toHaveBeenCalledWith(eventName, cb);
|
|
87
280
|
});
|
|
88
281
|
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
describe('EventHelper - Marketplace events', () => {
|
|
285
|
+
const handler = makeMockHandler();
|
|
286
|
+
const helper = new EventHelper(handler);
|
|
287
|
+
|
|
288
|
+
const events: Array<{ method: string; eventName: EventNames }> = [
|
|
289
|
+
{ method: 'deployItem', eventName: EventNames.DeployMarketplaceItem },
|
|
290
|
+
{ method: 'itemDeployed', eventName: EventNames.MarketplaceItemDeployed },
|
|
291
|
+
{ method: 'deploymentError', eventName: EventNames.MarketplaceItemDeploymentError },
|
|
292
|
+
{ method: 'updateItem', eventName: EventNames.UpdateMarketplaceItem },
|
|
293
|
+
{ method: 'itemUpdated', eventName: EventNames.MarketplaceItemUpdated },
|
|
294
|
+
{ method: 'updateError', eventName: EventNames.MarketplaceItemUpdateError },
|
|
295
|
+
{ method: 'deleteItem', eventName: EventNames.DeleteMarketplaceItem },
|
|
296
|
+
{ method: 'itemDeleted', eventName: EventNames.MarketplaceItemDeleted },
|
|
297
|
+
{ method: 'deletionError', eventName: EventNames.MarketplaceItemDeletionError },
|
|
298
|
+
{ method: 'loadItems', eventName: EventNames.LoadMarketplaceItems },
|
|
299
|
+
{ method: 'itemsLoaded', eventName: EventNames.MarketplaceItemsLoaded },
|
|
300
|
+
{ method: 'loadSchema', eventName: EventNames.LoadMarketplaceSchema },
|
|
301
|
+
{ method: 'schemaLoaded', eventName: EventNames.MarketplaceSchemaLoaded },
|
|
302
|
+
{ method: 'schemaLoadError', eventName: EventNames.MarketplaceSchemaLoadError },
|
|
303
|
+
];
|
|
304
|
+
|
|
305
|
+
events.forEach(({ method, eventName }) => {
|
|
306
|
+
it(`marketplace.publish.${method} usa ${eventName}`, () => {
|
|
307
|
+
jest.clearAllMocks();
|
|
308
|
+
(helper.marketplace.publish as any)[method]({});
|
|
309
|
+
expect(handler.publish).toHaveBeenCalledWith(eventName, {});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it(`marketplace.subscribe.${method} usa ${eventName}`, () => {
|
|
313
|
+
jest.clearAllMocks();
|
|
314
|
+
const cb = jest.fn();
|
|
315
|
+
(helper.marketplace.subscribe as any)[method](cb);
|
|
316
|
+
expect(handler.subscribe).toHaveBeenCalledWith(eventName, cb);
|
|
317
|
+
});
|
|
89
318
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
eventHelper.marketplace.publish.deployItem(payload as any);
|
|
96
|
-
expect(spy).toHaveBeenCalledWith(EventNames.DeployMarketplaceItem, payload);
|
|
319
|
+
it(`marketplace.unsubscribe.${method} usa ${eventName}`, () => {
|
|
320
|
+
jest.clearAllMocks();
|
|
321
|
+
const cb = jest.fn();
|
|
322
|
+
(helper.marketplace.unsubscribe as any)[method](cb);
|
|
323
|
+
expect(handler.unsubscribe).toHaveBeenCalledWith(eventName, cb);
|
|
97
324
|
});
|
|
98
325
|
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
describe('EventHelper - Resource events', () => {
|
|
329
|
+
const handler = makeMockHandler();
|
|
330
|
+
const helper = new EventHelper(handler);
|
|
99
331
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
332
|
+
const events: Array<{ method: string; eventName: EventNames }> = [
|
|
333
|
+
{ method: 'creation', eventName: EventNames.CreateResource },
|
|
334
|
+
{ method: 'created', eventName: EventNames.ResourceCreated },
|
|
335
|
+
{ method: 'creationError', eventName: EventNames.ResourceCreationError },
|
|
336
|
+
{ method: 'update', eventName: EventNames.UpdateResource },
|
|
337
|
+
{ method: 'updated', eventName: EventNames.ResourceUpdated },
|
|
338
|
+
{ method: 'updateError', eventName: EventNames.ResourceUpdateError },
|
|
339
|
+
{ method: 'delete', eventName: EventNames.DeleteResource },
|
|
340
|
+
{ method: 'deleted', eventName: EventNames.ResourceDeleted },
|
|
341
|
+
{ method: 'deletionError', eventName: EventNames.ResourceDeletionError },
|
|
342
|
+
];
|
|
343
|
+
|
|
344
|
+
events.forEach(({ method, eventName }) => {
|
|
345
|
+
it(`resource.publish.${method} usa ${eventName}`, () => {
|
|
346
|
+
jest.clearAllMocks();
|
|
347
|
+
(helper.resource.publish as any)[method]({});
|
|
348
|
+
expect(handler.publish).toHaveBeenCalledWith(eventName, {});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it(`resource.subscribe.${method} usa ${eventName}`, () => {
|
|
352
|
+
jest.clearAllMocks();
|
|
353
|
+
const cb = jest.fn();
|
|
354
|
+
(helper.resource.subscribe as any)[method](cb);
|
|
355
|
+
expect(handler.subscribe).toHaveBeenCalledWith(eventName, cb);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it(`resource.unsubscribe.${method} usa ${eventName}`, () => {
|
|
359
|
+
jest.clearAllMocks();
|
|
360
|
+
const cb = jest.fn();
|
|
361
|
+
(helper.resource.unsubscribe as any)[method](cb);
|
|
362
|
+
expect(handler.unsubscribe).toHaveBeenCalledWith(eventName, cb);
|
|
107
363
|
});
|
|
108
364
|
});
|
|
365
|
+
});
|
|
109
366
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
367
|
+
describe('EventHelper - Plan events', () => {
|
|
368
|
+
const handler = makeMockHandler();
|
|
369
|
+
const helper = new EventHelper(handler);
|
|
370
|
+
|
|
371
|
+
const events: Array<{ method: string; eventName: EventNames }> = [
|
|
372
|
+
{ method: 'upgrade', eventName: EventNames.UpdatePlan },
|
|
373
|
+
{ method: 'upgraded', eventName: EventNames.PlanUpdated },
|
|
374
|
+
{ method: 'upgradeError', eventName: EventNames.PlanUpdateError },
|
|
375
|
+
{ method: 'downgrade', eventName: EventNames.DowngradePlan },
|
|
376
|
+
{ method: 'downgraded', eventName: EventNames.PlanDowngraded },
|
|
377
|
+
{ method: 'downgradeError', eventName: EventNames.PlanDowngradeError },
|
|
378
|
+
];
|
|
379
|
+
|
|
380
|
+
events.forEach(({ method, eventName }) => {
|
|
381
|
+
it(`plan.publish.${method} usa ${eventName}`, () => {
|
|
382
|
+
jest.clearAllMocks();
|
|
383
|
+
(helper.plan.publish as any)[method]('test');
|
|
384
|
+
expect(handler.publish).toHaveBeenCalledWith(eventName, 'test');
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it(`plan.subscribe.${method} usa ${eventName}`, () => {
|
|
388
|
+
jest.clearAllMocks();
|
|
389
|
+
const cb = jest.fn();
|
|
390
|
+
(helper.plan.subscribe as any)[method](cb);
|
|
391
|
+
expect(handler.subscribe).toHaveBeenCalledWith(eventName, cb);
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it(`plan.unsubscribe.${method} usa ${eventName}`, () => {
|
|
395
|
+
jest.clearAllMocks();
|
|
396
|
+
const cb = jest.fn();
|
|
397
|
+
(helper.plan.unsubscribe as any)[method](cb);
|
|
398
|
+
expect(handler.unsubscribe).toHaveBeenCalledWith(eventName, cb);
|
|
117
399
|
});
|
|
118
400
|
});
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
describe('EventHelper - Organization events', () => {
|
|
404
|
+
const handler = makeMockHandler();
|
|
405
|
+
const helper = new EventHelper(handler);
|
|
406
|
+
|
|
407
|
+
const events: Array<{ method: string; eventName: EventNames }> = [
|
|
408
|
+
{ method: 'creation', eventName: EventNames.CreateOrganization },
|
|
409
|
+
{ method: 'created', eventName: EventNames.OrganizationCreated },
|
|
410
|
+
{ method: 'creationError', eventName: EventNames.OrganizationCreationError },
|
|
411
|
+
{ method: 'update', eventName: EventNames.UpdateOrganization },
|
|
412
|
+
{ method: 'updated', eventName: EventNames.OrganizationUpdated },
|
|
413
|
+
{ method: 'updateError', eventName: EventNames.OrganizationUpdateError },
|
|
414
|
+
{ method: 'delete', eventName: EventNames.DeleteOrganization },
|
|
415
|
+
{ method: 'deleted', eventName: EventNames.OrganizationDeleted },
|
|
416
|
+
{ method: 'deletionError', eventName: EventNames.OrganizationDeletionError },
|
|
417
|
+
];
|
|
418
|
+
|
|
419
|
+
events.forEach(({ method, eventName }) => {
|
|
420
|
+
it(`organization.publish.${method} usa ${eventName}`, () => {
|
|
421
|
+
jest.clearAllMocks();
|
|
422
|
+
(helper.organization.publish as any)[method]({});
|
|
423
|
+
expect(handler.publish).toHaveBeenCalledWith(eventName, {});
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it(`organization.subscribe.${method} usa ${eventName}`, () => {
|
|
427
|
+
jest.clearAllMocks();
|
|
428
|
+
const cb = jest.fn();
|
|
429
|
+
(helper.organization.subscribe as any)[method](cb);
|
|
430
|
+
expect(handler.subscribe).toHaveBeenCalledWith(eventName, cb);
|
|
431
|
+
});
|
|
119
432
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
eventHelper.organization.publish.creation(payload as any);
|
|
126
|
-
expect(spy).toHaveBeenCalledWith(EventNames.CreateOrganization, payload);
|
|
433
|
+
it(`organization.unsubscribe.${method} usa ${eventName}`, () => {
|
|
434
|
+
jest.clearAllMocks();
|
|
435
|
+
const cb = jest.fn();
|
|
436
|
+
(helper.organization.unsubscribe as any)[method](cb);
|
|
437
|
+
expect(handler.unsubscribe).toHaveBeenCalledWith(eventName, cb);
|
|
127
438
|
});
|
|
128
439
|
});
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
describe('EventHelper - Notification events', () => {
|
|
443
|
+
const handler = makeMockHandler();
|
|
444
|
+
const helper = new EventHelper(handler);
|
|
129
445
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
446
|
+
const events: Array<{ method: string; eventName: EventNames }> = [
|
|
447
|
+
{ method: 'creation', eventName: EventNames.CreateNotification },
|
|
448
|
+
{ method: 'deletion', eventName: EventNames.DeleteNotification },
|
|
449
|
+
{ method: 'read', eventName: EventNames.NotificationRead },
|
|
450
|
+
];
|
|
451
|
+
|
|
452
|
+
events.forEach(({ method, eventName }) => {
|
|
453
|
+
it(`notification.publish.${method} usa ${eventName}`, () => {
|
|
454
|
+
jest.clearAllMocks();
|
|
455
|
+
(helper.notification.publish as any)[method]({});
|
|
456
|
+
expect(handler.publish).toHaveBeenCalledWith(eventName, {});
|
|
136
457
|
});
|
|
137
458
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
expect(
|
|
459
|
+
it(`notification.subscribe.${method} usa ${eventName}`, () => {
|
|
460
|
+
jest.clearAllMocks();
|
|
461
|
+
const cb = jest.fn();
|
|
462
|
+
(helper.notification.subscribe as any)[method](cb);
|
|
463
|
+
expect(handler.subscribe).toHaveBeenCalledWith(eventName, cb);
|
|
143
464
|
});
|
|
144
465
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
expect(
|
|
466
|
+
it(`notification.unsubscribe.${method} usa ${eventName}`, () => {
|
|
467
|
+
jest.clearAllMocks();
|
|
468
|
+
const cb = jest.fn();
|
|
469
|
+
(helper.notification.unsubscribe as any)[method](cb);
|
|
470
|
+
expect(handler.unsubscribe).toHaveBeenCalledWith(eventName, cb);
|
|
150
471
|
});
|
|
151
472
|
});
|
|
152
473
|
});
|
|
474
|
+
|
|
475
|
+
describe('EventHelper - PlanProviders events', () => {
|
|
476
|
+
const handler = makeMockHandler();
|
|
477
|
+
const helper = new EventHelper(handler);
|
|
478
|
+
|
|
479
|
+
it('planProviders.publish.loadPlans usa LoadPlanProviders', () => {
|
|
480
|
+
helper.planProviders.publish.loadPlans();
|
|
481
|
+
expect(handler.publish).toHaveBeenCalledWith(EventNames.LoadPlanProviders, undefined);
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it('planProviders.publish.plansLoaded usa PlanProvidersLoaded', () => {
|
|
485
|
+
jest.clearAllMocks();
|
|
486
|
+
helper.planProviders.publish.plansLoaded([]);
|
|
487
|
+
expect(handler.publish).toHaveBeenCalledWith(EventNames.PlanProvidersLoaded, []);
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
it('planProviders.publish.loadError usa PlanProvidersLoadError', () => {
|
|
491
|
+
jest.clearAllMocks();
|
|
492
|
+
helper.planProviders.publish.loadError();
|
|
493
|
+
expect(handler.publish).toHaveBeenCalledWith(EventNames.PlanProvidersLoadError, undefined);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it('planProviders.subscribe.loadPlans usa LoadPlanProviders', () => {
|
|
497
|
+
jest.clearAllMocks();
|
|
498
|
+
const cb = jest.fn();
|
|
499
|
+
helper.planProviders.subscribe.loadPlans(cb);
|
|
500
|
+
expect(handler.subscribe).toHaveBeenCalledWith(EventNames.LoadPlanProviders, cb);
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
it('planProviders.subscribe.plansLoaded usa PlanProvidersLoaded', () => {
|
|
504
|
+
jest.clearAllMocks();
|
|
505
|
+
const cb = jest.fn();
|
|
506
|
+
helper.planProviders.subscribe.plansLoaded(cb);
|
|
507
|
+
expect(handler.subscribe).toHaveBeenCalledWith(EventNames.PlanProvidersLoaded, cb);
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
it('planProviders.subscribe.loadError usa PlanProvidersLoadError', () => {
|
|
511
|
+
jest.clearAllMocks();
|
|
512
|
+
const cb = jest.fn();
|
|
513
|
+
helper.planProviders.subscribe.loadError(cb);
|
|
514
|
+
expect(handler.subscribe).toHaveBeenCalledWith(EventNames.PlanProvidersLoadError, cb);
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
it('planProviders.unsubscribe.loadPlans usa LoadPlanProviders', () => {
|
|
518
|
+
jest.clearAllMocks();
|
|
519
|
+
const cb = jest.fn();
|
|
520
|
+
helper.planProviders.unsubscribe.loadPlans(cb);
|
|
521
|
+
expect(handler.unsubscribe).toHaveBeenCalledWith(EventNames.LoadPlanProviders, cb);
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
it('planProviders.unsubscribe.plansLoaded usa PlanProvidersLoaded', () => {
|
|
525
|
+
jest.clearAllMocks();
|
|
526
|
+
const cb = jest.fn();
|
|
527
|
+
helper.planProviders.unsubscribe.plansLoaded(cb);
|
|
528
|
+
expect(handler.unsubscribe).toHaveBeenCalledWith(EventNames.PlanProvidersLoaded, cb);
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it('planProviders.unsubscribe.loadError usa PlanProvidersLoadError', () => {
|
|
532
|
+
jest.clearAllMocks();
|
|
533
|
+
const cb = jest.fn();
|
|
534
|
+
helper.planProviders.unsubscribe.loadError(cb);
|
|
535
|
+
expect(handler.unsubscribe).toHaveBeenCalledWith(EventNames.PlanProvidersLoadError, cb);
|
|
536
|
+
});
|
|
537
|
+
});
|