wabe 0.6.9 → 0.6.11

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