wabe 0.6.9 → 0.6.10

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 (158) hide show
  1. package/README.md +138 -32
  2. package/bucket/b.txt +1 -0
  3. package/dev/index.ts +215 -0
  4. package/dist/authentication/Session.d.ts +4 -1
  5. package/dist/authentication/interface.d.ts +16 -0
  6. package/dist/email/interface.d.ts +1 -1
  7. package/dist/graphql/resolvers.d.ts +4 -2
  8. package/dist/hooks/index.d.ts +1 -0
  9. package/dist/index.d.ts +0 -1
  10. package/dist/index.js +8713 -8867
  11. package/dist/server/index.d.ts +4 -2
  12. package/dist/utils/crypto.d.ts +7 -0
  13. package/dist/utils/helper.d.ts +4 -1
  14. package/generated/schema.graphql +16 -14
  15. package/generated/wabe.ts +4 -4
  16. package/package.json +15 -15
  17. package/src/authentication/OTP.test.ts +69 -0
  18. package/src/authentication/OTP.ts +66 -0
  19. package/src/authentication/Session.test.ts +665 -0
  20. package/src/authentication/Session.ts +529 -0
  21. package/src/authentication/defaultAuthentication.ts +214 -0
  22. package/src/authentication/index.ts +3 -0
  23. package/src/authentication/interface.ts +157 -0
  24. package/src/authentication/oauth/GitHub.test.ts +105 -0
  25. package/src/authentication/oauth/GitHub.ts +133 -0
  26. package/src/authentication/oauth/Google.test.ts +105 -0
  27. package/src/authentication/oauth/Google.ts +110 -0
  28. package/src/authentication/oauth/Oauth2Client.test.ts +225 -0
  29. package/src/authentication/oauth/Oauth2Client.ts +140 -0
  30. package/src/authentication/oauth/index.ts +2 -0
  31. package/src/authentication/oauth/utils.test.ts +35 -0
  32. package/src/authentication/oauth/utils.ts +28 -0
  33. package/src/authentication/providers/EmailOTP.test.ts +138 -0
  34. package/src/authentication/providers/EmailOTP.ts +93 -0
  35. package/src/authentication/providers/EmailPassword.test.ts +187 -0
  36. package/src/authentication/providers/EmailPassword.ts +130 -0
  37. package/src/authentication/providers/EmailPasswordSRP.test.ts +206 -0
  38. package/src/authentication/providers/EmailPasswordSRP.ts +184 -0
  39. package/src/authentication/providers/GitHub.ts +30 -0
  40. package/src/authentication/providers/Google.ts +30 -0
  41. package/src/authentication/providers/OAuth.test.ts +185 -0
  42. package/src/authentication/providers/OAuth.ts +112 -0
  43. package/src/authentication/providers/PhonePassword.test.ts +187 -0
  44. package/src/authentication/providers/PhonePassword.ts +129 -0
  45. package/src/authentication/providers/QRCodeOTP.test.ts +79 -0
  46. package/src/authentication/providers/QRCodeOTP.ts +65 -0
  47. package/src/authentication/providers/index.ts +6 -0
  48. package/src/authentication/resolvers/refreshResolver.test.ts +37 -0
  49. package/src/authentication/resolvers/refreshResolver.ts +20 -0
  50. package/src/authentication/resolvers/signInWithResolver.inte.test.ts +59 -0
  51. package/src/authentication/resolvers/signInWithResolver.test.ts +307 -0
  52. package/src/authentication/resolvers/signInWithResolver.ts +102 -0
  53. package/src/authentication/resolvers/signOutResolver.test.ts +41 -0
  54. package/src/authentication/resolvers/signOutResolver.ts +22 -0
  55. package/src/authentication/resolvers/signUpWithResolver.test.ts +186 -0
  56. package/src/authentication/resolvers/signUpWithResolver.ts +69 -0
  57. package/src/authentication/resolvers/verifyChallenge.test.ts +136 -0
  58. package/src/authentication/resolvers/verifyChallenge.ts +69 -0
  59. package/src/authentication/roles.test.ts +59 -0
  60. package/src/authentication/roles.ts +40 -0
  61. package/src/authentication/utils.test.ts +99 -0
  62. package/src/authentication/utils.ts +43 -0
  63. package/src/cache/InMemoryCache.test.ts +62 -0
  64. package/src/cache/InMemoryCache.ts +45 -0
  65. package/src/cron/index.test.ts +17 -0
  66. package/src/cron/index.ts +46 -0
  67. package/src/database/DatabaseController.test.ts +625 -0
  68. package/src/database/DatabaseController.ts +983 -0
  69. package/src/database/index.test.ts +1230 -0
  70. package/src/database/index.ts +9 -0
  71. package/src/database/interface.ts +312 -0
  72. package/src/email/DevAdapter.ts +8 -0
  73. package/src/email/EmailController.test.ts +29 -0
  74. package/src/email/EmailController.ts +13 -0
  75. package/src/email/index.ts +2 -0
  76. package/src/email/interface.ts +36 -0
  77. package/src/email/templates/sendOtpCode.ts +120 -0
  78. package/src/file/FileController.ts +28 -0
  79. package/src/file/FileDevAdapter.ts +54 -0
  80. package/src/file/hookDeleteFile.ts +27 -0
  81. package/src/file/hookReadFile.ts +70 -0
  82. package/src/file/hookUploadFile.ts +53 -0
  83. package/src/file/index.test.ts +979 -0
  84. package/src/file/index.ts +2 -0
  85. package/src/file/interface.ts +42 -0
  86. package/src/graphql/GraphQLSchema.test.ts +4399 -0
  87. package/src/graphql/GraphQLSchema.ts +928 -0
  88. package/src/graphql/index.ts +2 -0
  89. package/src/graphql/parseGraphqlSchema.ts +94 -0
  90. package/src/graphql/parser.test.ts +217 -0
  91. package/src/graphql/parser.ts +566 -0
  92. package/src/graphql/pointerAndRelationFunction.ts +200 -0
  93. package/src/graphql/resolvers.ts +467 -0
  94. package/src/graphql/tests/aggregation.test.ts +1123 -0
  95. package/src/graphql/tests/e2e.test.ts +596 -0
  96. package/src/graphql/tests/scalars.test.ts +250 -0
  97. package/src/graphql/types.ts +219 -0
  98. package/src/hooks/HookObject.test.ts +122 -0
  99. package/src/hooks/HookObject.ts +168 -0
  100. package/src/hooks/authentication.ts +76 -0
  101. package/src/hooks/createUser.test.ts +77 -0
  102. package/src/hooks/createUser.ts +10 -0
  103. package/src/hooks/defaultFields.test.ts +187 -0
  104. package/src/hooks/defaultFields.ts +40 -0
  105. package/src/hooks/deleteSession.test.ts +181 -0
  106. package/src/hooks/deleteSession.ts +20 -0
  107. package/src/hooks/hashFieldHook.test.ts +163 -0
  108. package/src/hooks/hashFieldHook.ts +97 -0
  109. package/src/hooks/index.test.ts +207 -0
  110. package/src/hooks/index.ts +430 -0
  111. package/src/hooks/permissions.test.ts +424 -0
  112. package/src/hooks/permissions.ts +113 -0
  113. package/src/hooks/protected.test.ts +551 -0
  114. package/src/hooks/protected.ts +72 -0
  115. package/src/hooks/searchableFields.test.ts +166 -0
  116. package/src/hooks/searchableFields.ts +98 -0
  117. package/src/hooks/session.test.ts +138 -0
  118. package/src/hooks/session.ts +78 -0
  119. package/src/hooks/setEmail.test.ts +216 -0
  120. package/src/hooks/setEmail.ts +35 -0
  121. package/src/hooks/setupAcl.test.ts +589 -0
  122. package/src/hooks/setupAcl.ts +29 -0
  123. package/src/index.ts +9 -0
  124. package/src/schema/Schema.test.ts +484 -0
  125. package/src/schema/Schema.ts +795 -0
  126. package/src/schema/defaultResolvers.ts +94 -0
  127. package/src/schema/index.ts +1 -0
  128. package/src/schema/resolvers/meResolver.test.ts +62 -0
  129. package/src/schema/resolvers/meResolver.ts +14 -0
  130. package/src/schema/resolvers/newFile.ts +0 -0
  131. package/src/schema/resolvers/resetPassword.test.ts +345 -0
  132. package/src/schema/resolvers/resetPassword.ts +64 -0
  133. package/src/schema/resolvers/sendEmail.test.ts +118 -0
  134. package/src/schema/resolvers/sendEmail.ts +21 -0
  135. package/src/schema/resolvers/sendOtpCode.test.ts +153 -0
  136. package/src/schema/resolvers/sendOtpCode.ts +52 -0
  137. package/src/security.test.ts +3461 -0
  138. package/src/server/defaultSessionHandler.test.ts +66 -0
  139. package/src/server/defaultSessionHandler.ts +115 -0
  140. package/src/server/generateCodegen.ts +476 -0
  141. package/src/server/index.test.ts +552 -0
  142. package/src/server/index.ts +354 -0
  143. package/src/server/interface.ts +11 -0
  144. package/src/server/routes/authHandler.ts +187 -0
  145. package/src/server/routes/index.ts +40 -0
  146. package/src/utils/crypto.test.ts +41 -0
  147. package/src/utils/crypto.ts +121 -0
  148. package/src/utils/export.ts +13 -0
  149. package/src/utils/helper.ts +195 -0
  150. package/src/utils/index.test.ts +11 -0
  151. package/src/utils/index.ts +201 -0
  152. package/src/utils/preload.ts +8 -0
  153. package/src/utils/testHelper.ts +117 -0
  154. package/tsconfig.json +32 -0
  155. package/bunfig.toml +0 -4
  156. package/dist/ai/index.d.ts +0 -1
  157. package/dist/ai/interface.d.ts +0 -9
  158. /package/dist/server/{defaultHandlers.d.ts → defaultSessionHandler.d.ts} +0 -0
@@ -0,0 +1,552 @@
1
+ import { describe, expect, it, spyOn } from 'bun:test'
2
+ import { v4 as uuid } from 'uuid'
3
+ import getPort from 'get-port'
4
+ import { Wabe } from '.'
5
+ import { Schema } from '../schema'
6
+ import { OperationType } from '../hooks'
7
+ import { getAnonymousClient } from '../utils/helper'
8
+ import { gql } from 'graphql-request'
9
+ import { getDatabaseAdapter } from '../utils/testHelper'
10
+ import * as WobeYoga from 'wobe-graphql-yoga'
11
+
12
+ describe('Server', () => {
13
+ it('should throw error if no jwt secret provided but cookie session choosen', async () => {
14
+ const databaseId = uuid()
15
+
16
+ const port = await getPort()
17
+ const wabe = new Wabe({
18
+ isProduction: false,
19
+ rootKey:
20
+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
21
+ database: {
22
+ // @ts-expect-error
23
+ adapter: await getDatabaseAdapter(databaseId),
24
+ },
25
+ port,
26
+ authentication: {
27
+ // @ts-expect-error
28
+ session: {
29
+ cookieSession: true,
30
+ },
31
+ },
32
+ routes: [
33
+ {
34
+ handler: (ctx) => ctx.res.send('Hello World!'),
35
+ path: '/hello',
36
+ method: 'GET',
37
+ },
38
+ ],
39
+ schema: {
40
+ classes: [
41
+ {
42
+ name: 'Collection1',
43
+ fields: { name: { type: 'String' } },
44
+ },
45
+ ],
46
+ },
47
+ })
48
+
49
+ expect(wabe.start()).rejects.toThrow(
50
+ 'Authentication session requires jwt secret',
51
+ )
52
+ })
53
+
54
+ it('should throw error if no jwt secret provided but csrf protection is enabled', async () => {
55
+ const databaseId = uuid()
56
+
57
+ const port = await getPort()
58
+ const wabe = new Wabe({
59
+ isProduction: false,
60
+ rootKey:
61
+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
62
+ database: {
63
+ // @ts-expect-error
64
+ adapter: await getDatabaseAdapter(databaseId),
65
+ },
66
+ port,
67
+ authentication: {
68
+ // @ts-expect-error
69
+ session: {},
70
+ },
71
+ security: {
72
+ disableCSRFProtection: false,
73
+ },
74
+ routes: [
75
+ {
76
+ handler: (ctx) => ctx.res.send('Hello World!'),
77
+ path: '/hello',
78
+ method: 'GET',
79
+ },
80
+ ],
81
+ schema: {
82
+ classes: [
83
+ {
84
+ name: 'Collection1',
85
+ fields: { name: { type: 'String' } },
86
+ },
87
+ ],
88
+ },
89
+ })
90
+
91
+ expect(wabe.start()).rejects.toThrow(
92
+ 'Authentication session requires jwt secret',
93
+ )
94
+ })
95
+
96
+ it('should pass graphql options to yoga plugin', async () => {
97
+ const databaseId = uuid()
98
+
99
+ const receivedOptions: any[] = []
100
+ const originalPlugin = WobeYoga.WobeGraphqlYogaPlugin
101
+ const pluginSpy = spyOn(
102
+ WobeYoga,
103
+ 'WobeGraphqlYogaPlugin',
104
+ ).mockImplementation((options: any) => {
105
+ receivedOptions.push(options)
106
+ return originalPlugin(options)
107
+ })
108
+
109
+ const port = await getPort()
110
+ const wabe = new Wabe({
111
+ isProduction: true,
112
+ rootKey:
113
+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
114
+ database: {
115
+ // @ts-expect-error
116
+ adapter: await getDatabaseAdapter(databaseId),
117
+ },
118
+ port,
119
+ authentication: {
120
+ session: {
121
+ jwtSecret: 'secret',
122
+ },
123
+ },
124
+ security: {
125
+ disableCSRFProtection: true,
126
+ allowIntrospectionInProduction: true,
127
+ maxGraphqlDepth: 60,
128
+ },
129
+ schema: {
130
+ classes: [
131
+ {
132
+ name: 'Collection1',
133
+ fields: { name: { type: 'String' } },
134
+ },
135
+ ],
136
+ },
137
+ })
138
+
139
+ try {
140
+ await wabe.start()
141
+ } finally {
142
+ await wabe.close()
143
+ pluginSpy.mockRestore()
144
+ }
145
+
146
+ expect(receivedOptions.length).toBeGreaterThan(0)
147
+ const args = receivedOptions[0]
148
+ expect(args?.allowIntrospection).toBe(true)
149
+ expect(args?.maxDepth).toBe(60)
150
+ expect(args?.allowMultipleOperations).toBe(true)
151
+ })
152
+
153
+ it('should mask graphql errors message', async () => {
154
+ spyOn(console, 'error').mockReturnValue()
155
+ const databaseId = uuid()
156
+
157
+ const port = await getPort()
158
+ const wabe = new Wabe({
159
+ isProduction: false,
160
+ rootKey:
161
+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
162
+ database: {
163
+ // @ts-expect-error
164
+ adapter: await getDatabaseAdapter(databaseId),
165
+ },
166
+ security: {
167
+ hideSensitiveErrorMessage: true,
168
+ disableCSRFProtection: true,
169
+ },
170
+ port,
171
+ schema: {
172
+ resolvers: {
173
+ queries: {
174
+ tata: {
175
+ type: 'Boolean',
176
+ resolve: () => {
177
+ throw new Error('Error message')
178
+ },
179
+ },
180
+ },
181
+ },
182
+ },
183
+ })
184
+
185
+ await wabe.start()
186
+
187
+ const graphqlClient = getAnonymousClient(port)
188
+
189
+ expect(
190
+ graphqlClient.request<any>(gql`
191
+ query tata {
192
+ tata
193
+ }
194
+ `),
195
+ ).rejects.toThrow('Unexpected error')
196
+
197
+ await wabe.close()
198
+ })
199
+
200
+ it('should load routes', async () => {
201
+ const databaseId = uuid()
202
+
203
+ const port = await getPort()
204
+ const wabe = new Wabe({
205
+ isProduction: false,
206
+ rootKey:
207
+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
208
+ database: {
209
+ // @ts-expect-error
210
+ adapter: await getDatabaseAdapter(databaseId),
211
+ },
212
+ security: {
213
+ disableCSRFProtection: true,
214
+ },
215
+ port,
216
+ routes: [
217
+ {
218
+ handler: (ctx) => ctx.res.send('Hello World!'),
219
+ path: '/hello',
220
+ method: 'GET',
221
+ },
222
+ ],
223
+ schema: {
224
+ classes: [
225
+ {
226
+ name: 'Collection1',
227
+ fields: { name: { type: 'String' } },
228
+ },
229
+ ],
230
+ },
231
+ })
232
+
233
+ await wabe.start()
234
+
235
+ const res = await fetch(`http://127.0.0.1:${port}/hello`)
236
+
237
+ expect(await res.text()).toBe('Hello World!')
238
+ await wabe.close()
239
+ })
240
+
241
+ it('should setup the root key in context if the root key is correct', async () => {
242
+ const databaseId = uuid()
243
+
244
+ const port = await getPort()
245
+ const wabe = new Wabe({
246
+ isProduction: false,
247
+ rootKey: 'thisistherootkey',
248
+ database: {
249
+ // @ts-expect-error
250
+ adapter: await getDatabaseAdapter(databaseId),
251
+ },
252
+ security: {
253
+ disableCSRFProtection: true,
254
+ },
255
+ port,
256
+ schema: {
257
+ classes: [
258
+ {
259
+ name: 'Collection1',
260
+ fields: { name: { type: 'String' } },
261
+ },
262
+ ],
263
+ },
264
+ })
265
+
266
+ await wabe.start()
267
+
268
+ const res = await fetch(`http://127.0.0.1:${port}/graphql`, {
269
+ method: 'POST',
270
+ headers: {
271
+ 'Content-Type': 'application/json',
272
+ },
273
+ body: JSON.stringify({
274
+ query: `
275
+ query {
276
+ collection1s {
277
+ edges {
278
+ node {
279
+ name
280
+ }
281
+ }
282
+ }
283
+ }
284
+ `,
285
+ }),
286
+ })
287
+
288
+ expect((await res.json()).errors[0].message).toEqual(
289
+ 'Permission denied to read class Collection1',
290
+ )
291
+
292
+ expect(res.status).toEqual(200)
293
+ await wabe.close()
294
+ })
295
+
296
+ it('should run server', async () => {
297
+ const databaseId = uuid()
298
+
299
+ const port = await getPort()
300
+ const wabe = new Wabe({
301
+ isProduction: false,
302
+ rootKey:
303
+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
304
+ database: {
305
+ // @ts-expect-error
306
+ adapter: await getDatabaseAdapter(databaseId),
307
+ },
308
+ security: {
309
+ disableCSRFProtection: true,
310
+ },
311
+ port,
312
+ schema: {
313
+ classes: [
314
+ {
315
+ name: 'Collection1',
316
+ fields: { name: { type: 'String' } },
317
+ },
318
+ ],
319
+ },
320
+ })
321
+
322
+ await wabe.start()
323
+
324
+ const res = await fetch(`http://127.0.0.1:${port}/health`)
325
+
326
+ expect(res.status).toEqual(200)
327
+ await wabe.close()
328
+ })
329
+
330
+ it('should run server on different hostname', async () => {
331
+ const databaseId = uuid()
332
+
333
+ const port = await getPort()
334
+ const wabe = new Wabe({
335
+ isProduction: false,
336
+ hostname: '0.0.0.0',
337
+ rootKey:
338
+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
339
+ database: {
340
+ // @ts-expect-error
341
+ adapter: await getDatabaseAdapter(databaseId),
342
+ },
343
+ port,
344
+ security: {
345
+ disableCSRFProtection: true,
346
+ },
347
+ schema: {
348
+ classes: [
349
+ {
350
+ name: 'Collection1',
351
+ fields: { name: { type: 'String' } },
352
+ },
353
+ ],
354
+ },
355
+ })
356
+
357
+ await wabe.start()
358
+
359
+ const res = await fetch(`http://0.0.0.0:${port}/health`)
360
+
361
+ expect(res.status).toEqual(200)
362
+ await wabe.close()
363
+ })
364
+
365
+ it('should throw an error if hook has negative value', async () => {
366
+ const databaseId = uuid()
367
+
368
+ const port = await getPort()
369
+ expect(
370
+ async () =>
371
+ new Wabe({
372
+ isProduction: false,
373
+ rootKey:
374
+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
375
+ database: {
376
+ // @ts-expect-error
377
+ adapter: await getDatabaseAdapter(databaseId),
378
+ },
379
+ security: {
380
+ disableCSRFProtection: true,
381
+ },
382
+ port,
383
+ hooks: [
384
+ {
385
+ operationType: OperationType.BeforeCreate,
386
+ callback: () => {},
387
+ priority: -1,
388
+ },
389
+ ],
390
+ }),
391
+ ).toThrow('Hook priority <= 0 is reserved for internal uses')
392
+
393
+ expect(
394
+ async () =>
395
+ new Wabe({
396
+ isProduction: false,
397
+ rootKey:
398
+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
399
+ database: {
400
+ // @ts-expect-error
401
+ adapter: await getDatabaseAdapter(databaseId),
402
+ },
403
+ security: {
404
+ disableCSRFProtection: true,
405
+ },
406
+ port,
407
+ hooks: [],
408
+ }),
409
+ ).not.toThrow()
410
+
411
+ expect(
412
+ async () =>
413
+ new Wabe({
414
+ isProduction: false,
415
+ rootKey:
416
+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
417
+ database: {
418
+ // @ts-expect-error
419
+ adapter: await getDatabaseAdapter(databaseId),
420
+ },
421
+ port,
422
+ security: {
423
+ disableCSRFProtection: true,
424
+ },
425
+ hooks: [
426
+ {
427
+ operationType: OperationType.BeforeCreate,
428
+ callback: () => {},
429
+ priority: 1,
430
+ },
431
+ ],
432
+ }),
433
+ ).not.toThrow()
434
+ })
435
+
436
+ it('should run server without schema object', async () => {
437
+ const databaseId = uuid()
438
+
439
+ const port = await getPort()
440
+ const wabe = new Wabe({
441
+ isProduction: false,
442
+ rootKey:
443
+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
444
+ database: {
445
+ // @ts-expect-error
446
+ adapter: await getDatabaseAdapter(databaseId),
447
+ },
448
+ port,
449
+ security: {
450
+ disableCSRFProtection: true,
451
+ },
452
+ })
453
+
454
+ await wabe.start()
455
+
456
+ const res = await fetch(`http://127.0.0.1:${port}/health`)
457
+
458
+ expect(res.status).toEqual(200)
459
+ await wabe.close()
460
+ })
461
+
462
+ it('should update the schema to static Wabe after the Schema initialization', async () => {
463
+ const spySchemaDefaultClass = spyOn(Schema.prototype, 'defaultClass')
464
+ const spySchemaDefaultEnum = spyOn(Schema.prototype, 'defaultEnum')
465
+
466
+ const databaseId = uuid()
467
+
468
+ const port = await getPort()
469
+
470
+ const wabe = new Wabe({
471
+ isProduction: false,
472
+ rootKey:
473
+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
474
+ database: {
475
+ // @ts-expect-error
476
+ adapter: await getDatabaseAdapter(databaseId),
477
+ },
478
+ port,
479
+ security: {
480
+ disableCSRFProtection: true,
481
+ },
482
+ schema: {
483
+ classes: [
484
+ {
485
+ name: 'Collection1',
486
+ fields: { name: { type: 'String' } },
487
+ },
488
+ ],
489
+ },
490
+ })
491
+
492
+ await wabe.start()
493
+
494
+ // _Session class is a default class so if it's present the schema is updated
495
+ const isSessionClassExist = wabe.config.schema?.classes?.find(
496
+ (schemaClass) => schemaClass.name === '_Session',
497
+ )
498
+
499
+ expect(isSessionClassExist).not.toBeUndefined()
500
+
501
+ expect(spySchemaDefaultClass).toHaveBeenCalledTimes(1)
502
+ expect(spySchemaDefaultEnum).toHaveBeenCalledTimes(1)
503
+
504
+ await wabe.close()
505
+ })
506
+
507
+ it('should load RoleEnum correctly', async () => {
508
+ const databaseId = uuid()
509
+
510
+ const port = await getPort()
511
+
512
+ const wabe = new Wabe({
513
+ isProduction: false,
514
+ rootKey:
515
+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc',
516
+ database: {
517
+ // @ts-expect-error
518
+ adapter: await getDatabaseAdapter(databaseId),
519
+ },
520
+ port,
521
+ security: {
522
+ disableCSRFProtection: true,
523
+ },
524
+ schema: {
525
+ classes: [
526
+ {
527
+ name: 'Collection1',
528
+ fields: { name: { type: 'String' } },
529
+ },
530
+ ],
531
+ },
532
+ authentication: {
533
+ roles: ['Admin', 'Client'],
534
+ },
535
+ })
536
+
537
+ await wabe.start()
538
+
539
+ const roleEnum = wabe.config.schema?.enums?.find(
540
+ (schemaEnum) => schemaEnum.name === 'RoleEnum',
541
+ )
542
+
543
+ expect(roleEnum).not.toBeUndefined()
544
+ expect(roleEnum?.values).toEqual({
545
+ Admin: 'Admin',
546
+ Client: 'Client',
547
+ DashboardAdmin: 'DashboardAdmin',
548
+ })
549
+
550
+ await wabe.close()
551
+ })
552
+ })