wabe 0.6.11 → 0.6.13

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.
Files changed (162) hide show
  1. package/dist/authentication/Session.d.ts +10 -12
  2. package/dist/authentication/cookies.d.ts +1 -0
  3. package/dist/authentication/index.d.ts +1 -0
  4. package/dist/authentication/interface.d.ts +20 -0
  5. package/dist/authentication/security.d.ts +18 -0
  6. package/dist/database/DatabaseController.d.ts +57 -3
  7. package/dist/database/interface.d.ts +5 -0
  8. package/dist/file/interface.d.ts +23 -0
  9. package/dist/file/security.d.ts +6 -0
  10. package/dist/graphql/GraphQLSchema.d.ts +1 -1
  11. package/dist/graphql/resolvers.d.ts +1 -0
  12. package/dist/hooks/protected.d.ts +3 -0
  13. package/dist/hooks/virtualFields.d.ts +3 -0
  14. package/dist/index.js +1757 -818
  15. package/dist/schema/Schema.d.ts +66 -7
  16. package/dist/server/index.d.ts +2 -1
  17. package/dist/server/routes/index.d.ts +4 -1
  18. package/dist/utils/database.d.ts +1 -0
  19. package/dist/utils/export.d.ts +1 -0
  20. package/dist/utils/index.d.ts +1 -0
  21. package/package.json +7 -4
  22. package/bucket/b.txt +0 -1
  23. package/dev/index.ts +0 -215
  24. package/generated/schema.graphql +0 -1892
  25. package/generated/wabe.ts +0 -439
  26. package/src/authentication/OTP.test.ts +0 -69
  27. package/src/authentication/OTP.ts +0 -64
  28. package/src/authentication/Session.test.ts +0 -629
  29. package/src/authentication/Session.ts +0 -493
  30. package/src/authentication/defaultAuthentication.ts +0 -209
  31. package/src/authentication/index.ts +0 -3
  32. package/src/authentication/interface.ts +0 -155
  33. package/src/authentication/oauth/GitHub.test.ts +0 -91
  34. package/src/authentication/oauth/GitHub.ts +0 -121
  35. package/src/authentication/oauth/Google.test.ts +0 -91
  36. package/src/authentication/oauth/Google.ts +0 -101
  37. package/src/authentication/oauth/Oauth2Client.test.ts +0 -219
  38. package/src/authentication/oauth/Oauth2Client.ts +0 -135
  39. package/src/authentication/oauth/index.ts +0 -2
  40. package/src/authentication/oauth/utils.test.ts +0 -33
  41. package/src/authentication/oauth/utils.ts +0 -27
  42. package/src/authentication/providers/EmailOTP.test.ts +0 -127
  43. package/src/authentication/providers/EmailOTP.ts +0 -84
  44. package/src/authentication/providers/EmailPassword.test.ts +0 -176
  45. package/src/authentication/providers/EmailPassword.ts +0 -116
  46. package/src/authentication/providers/EmailPasswordSRP.test.ts +0 -208
  47. package/src/authentication/providers/EmailPasswordSRP.ts +0 -179
  48. package/src/authentication/providers/GitHub.ts +0 -24
  49. package/src/authentication/providers/Google.ts +0 -24
  50. package/src/authentication/providers/OAuth.test.ts +0 -185
  51. package/src/authentication/providers/OAuth.ts +0 -106
  52. package/src/authentication/providers/PhonePassword.test.ts +0 -176
  53. package/src/authentication/providers/PhonePassword.ts +0 -115
  54. package/src/authentication/providers/QRCodeOTP.test.ts +0 -77
  55. package/src/authentication/providers/QRCodeOTP.ts +0 -58
  56. package/src/authentication/providers/index.ts +0 -6
  57. package/src/authentication/resolvers/refreshResolver.test.ts +0 -30
  58. package/src/authentication/resolvers/refreshResolver.ts +0 -19
  59. package/src/authentication/resolvers/signInWithResolver.inte.test.ts +0 -59
  60. package/src/authentication/resolvers/signInWithResolver.test.ts +0 -293
  61. package/src/authentication/resolvers/signInWithResolver.ts +0 -92
  62. package/src/authentication/resolvers/signOutResolver.test.ts +0 -38
  63. package/src/authentication/resolvers/signOutResolver.ts +0 -18
  64. package/src/authentication/resolvers/signUpWithResolver.test.ts +0 -180
  65. package/src/authentication/resolvers/signUpWithResolver.ts +0 -65
  66. package/src/authentication/resolvers/verifyChallenge.test.ts +0 -133
  67. package/src/authentication/resolvers/verifyChallenge.ts +0 -62
  68. package/src/authentication/roles.test.ts +0 -49
  69. package/src/authentication/roles.ts +0 -40
  70. package/src/authentication/utils.test.ts +0 -97
  71. package/src/authentication/utils.ts +0 -39
  72. package/src/cache/InMemoryCache.test.ts +0 -62
  73. package/src/cache/InMemoryCache.ts +0 -45
  74. package/src/cron/index.test.ts +0 -17
  75. package/src/cron/index.ts +0 -43
  76. package/src/database/DatabaseController.test.ts +0 -613
  77. package/src/database/DatabaseController.ts +0 -1007
  78. package/src/database/index.test.ts +0 -1372
  79. package/src/database/index.ts +0 -9
  80. package/src/database/interface.ts +0 -302
  81. package/src/email/DevAdapter.ts +0 -7
  82. package/src/email/EmailController.test.ts +0 -29
  83. package/src/email/EmailController.ts +0 -13
  84. package/src/email/index.ts +0 -2
  85. package/src/email/interface.ts +0 -36
  86. package/src/email/templates/sendOtpCode.ts +0 -120
  87. package/src/file/FileController.ts +0 -28
  88. package/src/file/FileDevAdapter.ts +0 -51
  89. package/src/file/hookDeleteFile.ts +0 -25
  90. package/src/file/hookReadFile.ts +0 -66
  91. package/src/file/hookUploadFile.ts +0 -50
  92. package/src/file/index.test.ts +0 -932
  93. package/src/file/index.ts +0 -2
  94. package/src/file/interface.ts +0 -39
  95. package/src/graphql/GraphQLSchema.test.ts +0 -4408
  96. package/src/graphql/GraphQLSchema.ts +0 -880
  97. package/src/graphql/index.ts +0 -2
  98. package/src/graphql/parseGraphqlSchema.ts +0 -85
  99. package/src/graphql/parser.test.ts +0 -203
  100. package/src/graphql/parser.ts +0 -542
  101. package/src/graphql/pointerAndRelationFunction.ts +0 -191
  102. package/src/graphql/resolvers.ts +0 -442
  103. package/src/graphql/tests/aggregation.test.ts +0 -1115
  104. package/src/graphql/tests/e2e.test.ts +0 -590
  105. package/src/graphql/tests/scalars.test.ts +0 -250
  106. package/src/graphql/types.ts +0 -227
  107. package/src/hooks/HookObject.test.ts +0 -122
  108. package/src/hooks/HookObject.ts +0 -165
  109. package/src/hooks/authentication.ts +0 -67
  110. package/src/hooks/createUser.test.ts +0 -77
  111. package/src/hooks/createUser.ts +0 -10
  112. package/src/hooks/defaultFields.test.ts +0 -176
  113. package/src/hooks/defaultFields.ts +0 -32
  114. package/src/hooks/deleteSession.test.ts +0 -181
  115. package/src/hooks/deleteSession.ts +0 -20
  116. package/src/hooks/hashFieldHook.test.ts +0 -152
  117. package/src/hooks/hashFieldHook.ts +0 -89
  118. package/src/hooks/index.test.ts +0 -258
  119. package/src/hooks/index.ts +0 -414
  120. package/src/hooks/permissions.test.ts +0 -412
  121. package/src/hooks/permissions.ts +0 -93
  122. package/src/hooks/protected.test.ts +0 -551
  123. package/src/hooks/protected.ts +0 -60
  124. package/src/hooks/searchableFields.test.ts +0 -147
  125. package/src/hooks/searchableFields.ts +0 -86
  126. package/src/hooks/session.test.ts +0 -134
  127. package/src/hooks/session.ts +0 -76
  128. package/src/hooks/setEmail.test.ts +0 -216
  129. package/src/hooks/setEmail.ts +0 -33
  130. package/src/hooks/setupAcl.test.ts +0 -618
  131. package/src/hooks/setupAcl.ts +0 -25
  132. package/src/index.ts +0 -9
  133. package/src/schema/Schema.test.ts +0 -482
  134. package/src/schema/Schema.ts +0 -757
  135. package/src/schema/defaultResolvers.ts +0 -93
  136. package/src/schema/index.ts +0 -1
  137. package/src/schema/resolvers/meResolver.test.ts +0 -62
  138. package/src/schema/resolvers/meResolver.ts +0 -10
  139. package/src/schema/resolvers/resetPassword.test.ts +0 -341
  140. package/src/schema/resolvers/resetPassword.ts +0 -63
  141. package/src/schema/resolvers/sendEmail.test.ts +0 -118
  142. package/src/schema/resolvers/sendEmail.ts +0 -21
  143. package/src/schema/resolvers/sendOtpCode.test.ts +0 -141
  144. package/src/schema/resolvers/sendOtpCode.ts +0 -52
  145. package/src/security.test.ts +0 -3434
  146. package/src/server/defaultSessionHandler.test.ts +0 -62
  147. package/src/server/defaultSessionHandler.ts +0 -105
  148. package/src/server/generateCodegen.ts +0 -433
  149. package/src/server/index.test.ts +0 -532
  150. package/src/server/index.ts +0 -334
  151. package/src/server/interface.ts +0 -11
  152. package/src/server/routes/authHandler.ts +0 -169
  153. package/src/server/routes/index.ts +0 -39
  154. package/src/utils/crypto.test.ts +0 -41
  155. package/src/utils/crypto.ts +0 -105
  156. package/src/utils/export.ts +0 -11
  157. package/src/utils/helper.ts +0 -204
  158. package/src/utils/index.test.ts +0 -11
  159. package/src/utils/index.ts +0 -189
  160. package/src/utils/preload.ts +0 -8
  161. package/src/utils/testHelper.ts +0 -116
  162. package/tsconfig.json +0 -32
@@ -1,613 +0,0 @@
1
- import { describe, it, expect, mock, afterEach, spyOn, afterAll } from 'bun:test'
2
- import type { WhereType } from '.'
3
- import * as hooks from '../hooks/index'
4
- import type { WabeContext } from '../server/interface'
5
- import type { DevWabeTypes } from '../utils/helper'
6
- import { DatabaseController } from './DatabaseController'
7
-
8
- describe('DatabaseController', () => {
9
- const mockGetObject = mock(() => {})
10
- const mockGetObjects = mock(() => {})
11
- const mockCreateObject = mock(() => {})
12
- const mockCreateObjects = mock(() => {})
13
- const mockUpdateObject = mock(() => {})
14
- const mockUpdateObjects = mock(() => {})
15
- const mockDeleteObject = mock(() => {})
16
- const mockDeleteObjects = mock(() => {})
17
- const mockClearDatabase = mock(() => {})
18
- const mockCount = mock(() => {})
19
-
20
- const mockRunOnSingleObject = mock(() => ({ newData: {} }) as never)
21
- const mockRunOnMultipleObject = mock(() => {})
22
-
23
- const mockInitializeHook = spyOn(hooks, 'initializeHook').mockReturnValue({
24
- runOnSingleObject: mockRunOnSingleObject,
25
- runOnMultipleObjects: mockRunOnMultipleObject,
26
- } as never)
27
-
28
- const mockAdapter = mock(() => ({
29
- getObject: mockGetObject,
30
- getObjects: mockGetObjects,
31
- createObject: mockCreateObject,
32
- createObjects: mockCreateObjects,
33
- updateObject: mockUpdateObject,
34
- updateObjects: mockUpdateObjects,
35
- deleteObject: mockDeleteObject,
36
- deleteObjects: mockDeleteObjects,
37
- clearDatabase: mockClearDatabase,
38
- count: mockCount,
39
- }))
40
-
41
- const config = {
42
- schema: {
43
- classes: [
44
- {
45
- name: 'TestClass',
46
- fields: {
47
- fieldX: {
48
- type: 'String',
49
- },
50
- pointerToAnotherClass: {
51
- type: 'Pointer',
52
- class: 'AnotherClass',
53
- },
54
- pointerToAnotherClass2: {
55
- type: 'Pointer',
56
- class: 'AnotherClass2',
57
- },
58
- },
59
- },
60
- {
61
- name: 'AnotherClass',
62
- fields: {
63
- field1: {
64
- type: 'String',
65
- },
66
- },
67
- },
68
- {
69
- name: 'AnotherClass2',
70
- fields: {
71
- field3: {
72
- type: 'String',
73
- },
74
- },
75
- },
76
- {
77
- name: 'AnotherClass3',
78
- fields: {
79
- field4: {
80
- type: 'String',
81
- },
82
- },
83
- },
84
- {
85
- name: 'AnotherClass4',
86
- fields: {
87
- relationToAnotherClass3: {
88
- type: 'Relation',
89
- class: 'AnotherClass3',
90
- },
91
- },
92
- },
93
- {
94
- name: 'ClassWithObject',
95
- fields: {
96
- object: {
97
- type: 'Object',
98
- object: {
99
- name: 'ObjectName',
100
- fields: {
101
- objectField: {
102
- type: 'String',
103
- },
104
- },
105
- },
106
- },
107
- },
108
- },
109
- ],
110
- },
111
- } as any
112
-
113
- const context = {
114
- isRoot: true,
115
- wabe: { config },
116
- sessionId: 'sessionId',
117
- } as any
118
-
119
- afterAll(() => {
120
- mockInitializeHook.mockRestore()
121
- mockRunOnSingleObject.mockRestore()
122
- mockRunOnMultipleObject.mockRestore()
123
- })
124
-
125
- afterEach(() => {
126
- mockGetObject.mockClear()
127
- mockGetObjects.mockClear()
128
- mockInitializeHook.mockClear()
129
- mockRunOnSingleObject.mockClear()
130
- mockRunOnMultipleObject.mockClear()
131
- mockClearDatabase.mockClear()
132
- mockCount.mockClear()
133
- })
134
-
135
- it('should call adapter count', async () => {
136
- const databaseController = new DatabaseController(mockAdapter() as any)
137
-
138
- await databaseController.count({
139
- className: 'User',
140
- context,
141
- where: { age: { equalTo: 20 } },
142
- })
143
-
144
- expect(mockCount).toHaveBeenCalledTimes(1)
145
- expect(mockCount).toHaveBeenCalledWith({
146
- className: 'User',
147
- context,
148
- where: { age: { equalTo: 20 } },
149
- })
150
- })
151
-
152
- it('should call adapter clearDatabase', async () => {
153
- const databaseController = new DatabaseController(mockAdapter() as any)
154
-
155
- await databaseController.clearDatabase()
156
-
157
- expect(mockClearDatabase).toHaveBeenCalledTimes(1)
158
- })
159
-
160
- it('should create new where include the ACL from context when isRoot = true', () => {
161
- const databaseController = new DatabaseController(mockAdapter() as any)
162
-
163
- const where: WhereType<any, any> = {
164
- id: { equalTo: 'id' },
165
- }
166
-
167
- const context: WabeContext<any> = {
168
- isRoot: true,
169
- wabe: {} as any,
170
- user: {
171
- id: 'userId',
172
- role: {
173
- id: 'roleId',
174
- } as any,
175
- } as any,
176
- }
177
-
178
- const newWhere = databaseController._buildWhereWithACL(where, context, 'read')
179
-
180
- expect(newWhere).toEqual(where)
181
- })
182
-
183
- it('should create new where include the ACL from context on read operation', () => {
184
- const databaseController = new DatabaseController(mockAdapter() as any)
185
-
186
- const where: WhereType<DevWabeTypes, any> = {
187
- id: { equalTo: 'id' },
188
- }
189
-
190
- const context: WabeContext<any> = {
191
- isRoot: false,
192
- wabe: {} as any,
193
- user: {
194
- id: 'userId',
195
- role: {
196
- id: 'roleId',
197
- } as any,
198
- } as any,
199
- }
200
-
201
- const newWhere = databaseController._buildWhereWithACL(where, context, 'read')
202
-
203
- // Soit user y est donc read doit etre à true soit user y est pas et donc role read doit etre à true
204
-
205
- expect(newWhere).toEqual({
206
- AND: [
207
- { id: { equalTo: 'id' } },
208
- {
209
- OR: [
210
- {
211
- acl: { equalTo: null },
212
- },
213
- {
214
- acl: {
215
- users: { contains: { userId: 'userId', read: true } },
216
- },
217
- },
218
- {
219
- AND: [
220
- {
221
- acl: {
222
- users: {
223
- notContains: { userId: 'userId' },
224
- },
225
- },
226
- },
227
- {
228
- acl: {
229
- roles: { contains: { roleId: 'roleId', read: true } },
230
- },
231
- },
232
- ],
233
- },
234
- ],
235
- },
236
- ],
237
- } as any)
238
- })
239
-
240
- it('should create new where include the ACL from context with undefined roleId', () => {
241
- const databaseController = new DatabaseController(mockAdapter() as any)
242
-
243
- const where: WhereType<any, any> = {
244
- id: { equalTo: 'id' },
245
- }
246
-
247
- const context: WabeContext<any> = {
248
- isRoot: false,
249
- wabe: {} as any,
250
- user: {
251
- id: 'userId',
252
- } as any,
253
- }
254
-
255
- const newWhere = databaseController._buildWhereWithACL(where, context, 'write')
256
-
257
- expect(newWhere).toEqual({
258
- AND: [
259
- { id: { equalTo: 'id' } },
260
- {
261
- OR: [
262
- {
263
- acl: { equalTo: null },
264
- },
265
- {
266
- acl: {
267
- users: { contains: { userId: 'userId', write: true } },
268
- },
269
- },
270
- ],
271
- },
272
- ],
273
- } as any)
274
- })
275
-
276
- it('should create new where include the ACL from context with undefined userId and roleId', () => {
277
- const databaseController = new DatabaseController(mockAdapter() as any)
278
-
279
- const where: WhereType<any, any> = {
280
- id: { equalTo: 'id' },
281
- }
282
-
283
- const context: WabeContext<any> = {
284
- isRoot: false,
285
- wabe: {} as any,
286
- user: {} as any,
287
- }
288
-
289
- const newWhere = databaseController._buildWhereWithACL(where, context, 'read')
290
-
291
- expect(newWhere).toEqual({
292
- AND: [{ id: { equalTo: 'id' } }, { acl: { equalTo: null } }],
293
- } as any)
294
- })
295
-
296
- it('should not call createObjects adapter when the data array is empty', async () => {
297
- const databaseController = new DatabaseController(mockAdapter() as any)
298
-
299
- await databaseController.createObjects({
300
- className: 'TestClass',
301
- context,
302
- data: [],
303
- })
304
-
305
- expect(mockCreateObjects).toHaveBeenCalledTimes(0)
306
- })
307
-
308
- it('should call hooks on getObject', async () => {
309
- mockGetObject.mockResolvedValue({} as never)
310
- const databaseController = new DatabaseController(mockAdapter() as any)
311
-
312
- await databaseController.getObject({
313
- className: 'TestClass',
314
- context,
315
- id: 'id',
316
- select: { id: true },
317
- })
318
-
319
- expect(mockInitializeHook).toHaveBeenCalledTimes(1)
320
- expect(mockInitializeHook).toHaveBeenCalledWith({
321
- className: 'TestClass',
322
- context: {
323
- sessionId: 'sessionId',
324
- wabe: { config },
325
- isRoot: true,
326
- },
327
- select: { id: true },
328
- objectLoader: expect.any(Function),
329
- objectsLoader: expect.any(Function),
330
- })
331
-
332
- expect(mockRunOnSingleObject).toHaveBeenCalledTimes(2)
333
- expect(mockRunOnSingleObject).toHaveBeenNthCalledWith(1, {
334
- operationType: hooks.OperationType.BeforeRead,
335
- id: 'id',
336
- })
337
- expect(mockRunOnSingleObject).toHaveBeenNthCalledWith(2, {
338
- operationType: hooks.OperationType.AfterRead,
339
- id: 'id',
340
- object: {},
341
- })
342
- })
343
-
344
- it('should call hooks on getObjects', async () => {
345
- mockGetObjects.mockResolvedValue([] as never)
346
-
347
- const databaseController = new DatabaseController(mockAdapter() as any)
348
-
349
- await databaseController.getObjects({
350
- className: 'TestClass',
351
- context,
352
- where: { id: { equalTo: 'id' } },
353
- select: { id: true },
354
- })
355
-
356
- expect(mockInitializeHook).toHaveBeenCalledTimes(1)
357
- expect(mockInitializeHook).toHaveBeenCalledWith({
358
- className: 'TestClass',
359
- context: {
360
- sessionId: 'sessionId',
361
- wabe: { config },
362
- isRoot: true,
363
- },
364
- select: { id: true },
365
- objectLoader: expect.any(Function),
366
- objectsLoader: expect.any(Function),
367
- })
368
-
369
- expect(mockRunOnMultipleObject).toHaveBeenCalledTimes(2)
370
- expect(mockRunOnMultipleObject).toHaveBeenNthCalledWith(1, {
371
- operationType: hooks.OperationType.BeforeRead,
372
- where: { id: { equalTo: 'id' } },
373
- })
374
- expect(mockRunOnMultipleObject).toHaveBeenNthCalledWith(2, {
375
- operationType: hooks.OperationType.AfterRead,
376
- objects: [],
377
- })
378
- })
379
-
380
- it('should call hooks on updateObject', async () => {
381
- mockRunOnSingleObject.mockResolvedValue({
382
- object: undefined,
383
- } as never)
384
- mockUpdateObject.mockResolvedValue({ id: 'id' } as never)
385
- mockGetObject.mockResolvedValue({ id: 'id' } as never)
386
-
387
- const databaseController = new DatabaseController(mockAdapter() as any)
388
-
389
- await databaseController.updateObject({
390
- className: 'TestClass',
391
- context,
392
- id: 'id',
393
- data: { name: 'test' },
394
- select: { id: true },
395
- })
396
-
397
- expect(mockInitializeHook).toHaveBeenCalledTimes(2)
398
- expect(mockInitializeHook).toHaveBeenCalledWith({
399
- className: 'TestClass',
400
- context: {
401
- sessionId: 'sessionId',
402
- wabe: { config },
403
- isRoot: true,
404
- },
405
- newData: { name: 'test' },
406
- select: { id: true },
407
- objectLoader: expect.any(Function),
408
- objectsLoader: expect.any(Function),
409
- })
410
-
411
- expect(mockRunOnSingleObject).toHaveBeenCalledTimes(4)
412
- expect(mockRunOnSingleObject).toHaveBeenNthCalledWith(1, {
413
- operationType: hooks.OperationType.BeforeUpdate,
414
- id: 'id',
415
- })
416
- expect(mockRunOnSingleObject).toHaveBeenNthCalledWith(2, {
417
- operationType: hooks.OperationType.AfterUpdate,
418
- id: 'id',
419
- })
420
- })
421
-
422
- it('should call hooks on updateObjects', async () => {
423
- mockRunOnMultipleObject.mockResolvedValue({
424
- newData: {},
425
- objects: [],
426
- } as never)
427
- mockUpdateObjects.mockResolvedValue([] as never)
428
-
429
- const databaseController = new DatabaseController(mockAdapter() as any)
430
-
431
- await databaseController.updateObjects({
432
- className: 'TestClass',
433
- context,
434
- where: { id: { equalTo: 'id' } },
435
- data: { name: 'test' },
436
- select: { id: true },
437
- })
438
-
439
- expect(mockInitializeHook).toHaveBeenCalledTimes(2)
440
- expect(mockInitializeHook).toHaveBeenCalledWith(
441
- expect.objectContaining({
442
- className: 'TestClass',
443
- newData: { name: 'test' },
444
- select: { id: true },
445
- }),
446
- )
447
-
448
- expect(mockRunOnMultipleObject).toHaveBeenCalledTimes(4)
449
- expect(mockRunOnMultipleObject).toHaveBeenNthCalledWith(1, {
450
- operationType: hooks.OperationType.BeforeUpdate,
451
- where: { id: { equalTo: 'id' } },
452
- })
453
- expect(mockRunOnMultipleObject).toHaveBeenNthCalledWith(2, {
454
- operationType: hooks.OperationType.AfterUpdate,
455
- ids: [],
456
- originalObjects: [],
457
- })
458
- })
459
-
460
- it('should call hooks on createObject', async () => {
461
- mockCreateObject.mockResolvedValue({ id: 'id' } as never)
462
-
463
- const databaseController = new DatabaseController(mockAdapter() as any)
464
-
465
- await databaseController.createObject({
466
- className: 'TestClass',
467
- context,
468
- data: { name: 'test' },
469
- select: { id: true },
470
- })
471
-
472
- expect(mockInitializeHook).toHaveBeenCalledTimes(2)
473
- expect(mockInitializeHook).toHaveBeenCalledWith({
474
- className: 'TestClass',
475
- context: {
476
- sessionId: 'sessionId',
477
- wabe: { config },
478
- isRoot: true,
479
- },
480
- newData: { name: 'test' },
481
- select: { id: true },
482
- objectLoader: expect.any(Function),
483
- objectsLoader: expect.any(Function),
484
- })
485
-
486
- expect(mockRunOnSingleObject).toHaveBeenCalledTimes(4)
487
- expect(mockRunOnSingleObject).toHaveBeenNthCalledWith(1, {
488
- operationType: hooks.OperationType.BeforeCreate,
489
- })
490
- expect(mockRunOnSingleObject).toHaveBeenNthCalledWith(2, {
491
- operationType: hooks.OperationType.AfterCreate,
492
- id: 'id',
493
- })
494
- })
495
-
496
- it('should call hooks on createObjects', async () => {
497
- mockGetObjects.mockResolvedValue([{ id: 'id' }] as never)
498
- mockCreateObjects.mockResolvedValue([{ id: 'id' }] as never)
499
- mockRunOnMultipleObject.mockResolvedValue({
500
- objects: [],
501
- newData: [{ name: 'test' }],
502
- } as never)
503
-
504
- const databaseController = new DatabaseController(mockAdapter() as any)
505
-
506
- await databaseController.createObjects({
507
- className: 'TestClass',
508
- context,
509
- data: [{ name: 'test' }],
510
- select: { id: true },
511
- })
512
-
513
- expect(mockInitializeHook).toHaveBeenCalledTimes(2)
514
- expect(mockInitializeHook).toHaveBeenCalledWith({
515
- className: 'TestClass',
516
- context: {
517
- sessionId: 'sessionId',
518
- wabe: { config },
519
- isRoot: true,
520
- },
521
- newData: { name: 'test' },
522
- select: { id: true },
523
- objectLoader: expect.any(Function),
524
- objectsLoader: expect.any(Function),
525
- })
526
-
527
- expect(mockRunOnMultipleObject).toHaveBeenCalledTimes(4)
528
- expect(mockRunOnMultipleObject).toHaveBeenNthCalledWith(1, {
529
- operationType: hooks.OperationType.BeforeCreate,
530
- })
531
- expect(mockRunOnMultipleObject).toHaveBeenNthCalledWith(2, {
532
- operationType: hooks.OperationType.AfterCreate,
533
- ids: ['id'],
534
- })
535
-
536
- mockRunOnMultipleObject.mockClear()
537
- })
538
-
539
- it('should call hooks on deleteObject', async () => {
540
- const databaseController = new DatabaseController(mockAdapter() as any)
541
-
542
- await databaseController.deleteObject({
543
- className: 'TestClass',
544
- context,
545
- select: { id: true },
546
- id: 'id',
547
- })
548
-
549
- expect(mockInitializeHook).toHaveBeenCalledTimes(2)
550
- expect(mockInitializeHook).toHaveBeenCalledWith({
551
- className: 'TestClass',
552
- context: {
553
- sessionId: 'sessionId',
554
- wabe: { config },
555
- isRoot: true,
556
- },
557
- select: { id: true },
558
- objectLoader: expect.any(Function),
559
- objectsLoader: expect.any(Function),
560
- })
561
-
562
- // 4 because we have a getObject before the delete
563
- expect(mockRunOnSingleObject).toHaveBeenCalledTimes(4)
564
- expect(mockRunOnSingleObject).toHaveBeenNthCalledWith(1, {
565
- operationType: hooks.OperationType.BeforeDelete,
566
- id: 'id',
567
- })
568
- expect(mockRunOnSingleObject).toHaveBeenNthCalledWith(4, {
569
- operationType: hooks.OperationType.AfterDelete,
570
- id: 'id',
571
- originalObject: undefined,
572
- })
573
- })
574
-
575
- it('should call hooks on deleteObjects', async () => {
576
- mockGetObjects.mockResolvedValue([{ id: 'id' }] as never)
577
- mockRunOnMultipleObject.mockResolvedValue({} as never)
578
-
579
- const databaseController = new DatabaseController(mockAdapter() as any)
580
-
581
- await databaseController.deleteObjects({
582
- className: 'TestClass',
583
- context,
584
- where: { id: { equalTo: 'id' } },
585
- select: { id: true },
586
- })
587
-
588
- expect(mockInitializeHook).toHaveBeenCalledTimes(2)
589
- expect(mockInitializeHook).toHaveBeenCalledWith({
590
- className: 'TestClass',
591
- context: {
592
- sessionId: 'sessionId',
593
- wabe: { config },
594
- isRoot: true,
595
- },
596
- select: { id: true },
597
- objectLoader: expect.any(Function),
598
- objectsLoader: expect.any(Function),
599
- })
600
-
601
- // 4 because we have a getObject before the delete
602
- expect(mockRunOnMultipleObject).toHaveBeenCalledTimes(4)
603
- expect(mockRunOnMultipleObject).toHaveBeenNthCalledWith(3, {
604
- operationType: hooks.OperationType.BeforeDelete,
605
- where: { id: { equalTo: 'id' } },
606
- })
607
- expect(mockRunOnMultipleObject).toHaveBeenNthCalledWith(4, {
608
- operationType: hooks.OperationType.AfterDelete,
609
- })
610
-
611
- mockRunOnMultipleObject.mockClear()
612
- })
613
- })