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.
- package/dist/authentication/Session.d.ts +10 -12
- package/dist/authentication/cookies.d.ts +1 -0
- package/dist/authentication/index.d.ts +1 -0
- package/dist/authentication/interface.d.ts +20 -0
- package/dist/authentication/security.d.ts +18 -0
- package/dist/database/DatabaseController.d.ts +57 -3
- package/dist/database/interface.d.ts +5 -0
- package/dist/file/interface.d.ts +23 -0
- package/dist/file/security.d.ts +6 -0
- package/dist/graphql/GraphQLSchema.d.ts +1 -1
- package/dist/graphql/resolvers.d.ts +1 -0
- package/dist/hooks/protected.d.ts +3 -0
- package/dist/hooks/virtualFields.d.ts +3 -0
- package/dist/index.js +1757 -818
- package/dist/schema/Schema.d.ts +66 -7
- package/dist/server/index.d.ts +2 -1
- package/dist/server/routes/index.d.ts +4 -1
- package/dist/utils/database.d.ts +1 -0
- package/dist/utils/export.d.ts +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +7 -4
- package/bucket/b.txt +0 -1
- package/dev/index.ts +0 -215
- package/generated/schema.graphql +0 -1892
- package/generated/wabe.ts +0 -439
- package/src/authentication/OTP.test.ts +0 -69
- package/src/authentication/OTP.ts +0 -64
- package/src/authentication/Session.test.ts +0 -629
- package/src/authentication/Session.ts +0 -493
- package/src/authentication/defaultAuthentication.ts +0 -209
- package/src/authentication/index.ts +0 -3
- package/src/authentication/interface.ts +0 -155
- package/src/authentication/oauth/GitHub.test.ts +0 -91
- package/src/authentication/oauth/GitHub.ts +0 -121
- package/src/authentication/oauth/Google.test.ts +0 -91
- package/src/authentication/oauth/Google.ts +0 -101
- package/src/authentication/oauth/Oauth2Client.test.ts +0 -219
- package/src/authentication/oauth/Oauth2Client.ts +0 -135
- package/src/authentication/oauth/index.ts +0 -2
- package/src/authentication/oauth/utils.test.ts +0 -33
- package/src/authentication/oauth/utils.ts +0 -27
- package/src/authentication/providers/EmailOTP.test.ts +0 -127
- package/src/authentication/providers/EmailOTP.ts +0 -84
- package/src/authentication/providers/EmailPassword.test.ts +0 -176
- package/src/authentication/providers/EmailPassword.ts +0 -116
- package/src/authentication/providers/EmailPasswordSRP.test.ts +0 -208
- package/src/authentication/providers/EmailPasswordSRP.ts +0 -179
- package/src/authentication/providers/GitHub.ts +0 -24
- package/src/authentication/providers/Google.ts +0 -24
- package/src/authentication/providers/OAuth.test.ts +0 -185
- package/src/authentication/providers/OAuth.ts +0 -106
- package/src/authentication/providers/PhonePassword.test.ts +0 -176
- package/src/authentication/providers/PhonePassword.ts +0 -115
- package/src/authentication/providers/QRCodeOTP.test.ts +0 -77
- package/src/authentication/providers/QRCodeOTP.ts +0 -58
- package/src/authentication/providers/index.ts +0 -6
- package/src/authentication/resolvers/refreshResolver.test.ts +0 -30
- package/src/authentication/resolvers/refreshResolver.ts +0 -19
- package/src/authentication/resolvers/signInWithResolver.inte.test.ts +0 -59
- package/src/authentication/resolvers/signInWithResolver.test.ts +0 -293
- package/src/authentication/resolvers/signInWithResolver.ts +0 -92
- package/src/authentication/resolvers/signOutResolver.test.ts +0 -38
- package/src/authentication/resolvers/signOutResolver.ts +0 -18
- package/src/authentication/resolvers/signUpWithResolver.test.ts +0 -180
- package/src/authentication/resolvers/signUpWithResolver.ts +0 -65
- package/src/authentication/resolvers/verifyChallenge.test.ts +0 -133
- package/src/authentication/resolvers/verifyChallenge.ts +0 -62
- package/src/authentication/roles.test.ts +0 -49
- package/src/authentication/roles.ts +0 -40
- package/src/authentication/utils.test.ts +0 -97
- package/src/authentication/utils.ts +0 -39
- package/src/cache/InMemoryCache.test.ts +0 -62
- package/src/cache/InMemoryCache.ts +0 -45
- package/src/cron/index.test.ts +0 -17
- package/src/cron/index.ts +0 -43
- package/src/database/DatabaseController.test.ts +0 -613
- package/src/database/DatabaseController.ts +0 -1007
- package/src/database/index.test.ts +0 -1372
- package/src/database/index.ts +0 -9
- package/src/database/interface.ts +0 -302
- package/src/email/DevAdapter.ts +0 -7
- package/src/email/EmailController.test.ts +0 -29
- package/src/email/EmailController.ts +0 -13
- package/src/email/index.ts +0 -2
- package/src/email/interface.ts +0 -36
- package/src/email/templates/sendOtpCode.ts +0 -120
- package/src/file/FileController.ts +0 -28
- package/src/file/FileDevAdapter.ts +0 -51
- package/src/file/hookDeleteFile.ts +0 -25
- package/src/file/hookReadFile.ts +0 -66
- package/src/file/hookUploadFile.ts +0 -50
- package/src/file/index.test.ts +0 -932
- package/src/file/index.ts +0 -2
- package/src/file/interface.ts +0 -39
- package/src/graphql/GraphQLSchema.test.ts +0 -4408
- package/src/graphql/GraphQLSchema.ts +0 -880
- package/src/graphql/index.ts +0 -2
- package/src/graphql/parseGraphqlSchema.ts +0 -85
- package/src/graphql/parser.test.ts +0 -203
- package/src/graphql/parser.ts +0 -542
- package/src/graphql/pointerAndRelationFunction.ts +0 -191
- package/src/graphql/resolvers.ts +0 -442
- package/src/graphql/tests/aggregation.test.ts +0 -1115
- package/src/graphql/tests/e2e.test.ts +0 -590
- package/src/graphql/tests/scalars.test.ts +0 -250
- package/src/graphql/types.ts +0 -227
- package/src/hooks/HookObject.test.ts +0 -122
- package/src/hooks/HookObject.ts +0 -165
- package/src/hooks/authentication.ts +0 -67
- package/src/hooks/createUser.test.ts +0 -77
- package/src/hooks/createUser.ts +0 -10
- package/src/hooks/defaultFields.test.ts +0 -176
- package/src/hooks/defaultFields.ts +0 -32
- package/src/hooks/deleteSession.test.ts +0 -181
- package/src/hooks/deleteSession.ts +0 -20
- package/src/hooks/hashFieldHook.test.ts +0 -152
- package/src/hooks/hashFieldHook.ts +0 -89
- package/src/hooks/index.test.ts +0 -258
- package/src/hooks/index.ts +0 -414
- package/src/hooks/permissions.test.ts +0 -412
- package/src/hooks/permissions.ts +0 -93
- package/src/hooks/protected.test.ts +0 -551
- package/src/hooks/protected.ts +0 -60
- package/src/hooks/searchableFields.test.ts +0 -147
- package/src/hooks/searchableFields.ts +0 -86
- package/src/hooks/session.test.ts +0 -134
- package/src/hooks/session.ts +0 -76
- package/src/hooks/setEmail.test.ts +0 -216
- package/src/hooks/setEmail.ts +0 -33
- package/src/hooks/setupAcl.test.ts +0 -618
- package/src/hooks/setupAcl.ts +0 -25
- package/src/index.ts +0 -9
- package/src/schema/Schema.test.ts +0 -482
- package/src/schema/Schema.ts +0 -757
- package/src/schema/defaultResolvers.ts +0 -93
- package/src/schema/index.ts +0 -1
- package/src/schema/resolvers/meResolver.test.ts +0 -62
- package/src/schema/resolvers/meResolver.ts +0 -10
- package/src/schema/resolvers/resetPassword.test.ts +0 -341
- package/src/schema/resolvers/resetPassword.ts +0 -63
- package/src/schema/resolvers/sendEmail.test.ts +0 -118
- package/src/schema/resolvers/sendEmail.ts +0 -21
- package/src/schema/resolvers/sendOtpCode.test.ts +0 -141
- package/src/schema/resolvers/sendOtpCode.ts +0 -52
- package/src/security.test.ts +0 -3434
- package/src/server/defaultSessionHandler.test.ts +0 -62
- package/src/server/defaultSessionHandler.ts +0 -105
- package/src/server/generateCodegen.ts +0 -433
- package/src/server/index.test.ts +0 -532
- package/src/server/index.ts +0 -334
- package/src/server/interface.ts +0 -11
- package/src/server/routes/authHandler.ts +0 -169
- package/src/server/routes/index.ts +0 -39
- package/src/utils/crypto.test.ts +0 -41
- package/src/utils/crypto.ts +0 -105
- package/src/utils/export.ts +0 -11
- package/src/utils/helper.ts +0 -204
- package/src/utils/index.test.ts +0 -11
- package/src/utils/index.ts +0 -189
- package/src/utils/preload.ts +0 -8
- package/src/utils/testHelper.ts +0 -116
- package/tsconfig.json +0 -32
|
@@ -1,1372 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
afterAll,
|
|
3
|
-
beforeAll,
|
|
4
|
-
describe,
|
|
5
|
-
expect,
|
|
6
|
-
it,
|
|
7
|
-
mock,
|
|
8
|
-
spyOn,
|
|
9
|
-
beforeEach,
|
|
10
|
-
type Mock,
|
|
11
|
-
} from 'bun:test'
|
|
12
|
-
import type { Wabe } from '../server'
|
|
13
|
-
import {
|
|
14
|
-
type DevWabeTypes,
|
|
15
|
-
getAdminUserClient,
|
|
16
|
-
getAnonymousClient,
|
|
17
|
-
getGraphqlClient,
|
|
18
|
-
} from '../utils/helper'
|
|
19
|
-
import { setupTests, closeTests } from '../utils/testHelper'
|
|
20
|
-
import type { WabeContext } from '../server/interface'
|
|
21
|
-
import { OperationType, getDefaultHooks } from '../hooks'
|
|
22
|
-
import { gql } from 'graphql-request'
|
|
23
|
-
import { contextWithRoot } from '../utils/export'
|
|
24
|
-
|
|
25
|
-
describe('Database', () => {
|
|
26
|
-
let wabe: Wabe<DevWabeTypes>
|
|
27
|
-
let context: WabeContext<any>
|
|
28
|
-
|
|
29
|
-
const mockUpdateObject = mock(async () => {
|
|
30
|
-
await context.wabe.controllers.database.updateObjects({
|
|
31
|
-
className: 'User',
|
|
32
|
-
where: {
|
|
33
|
-
name: { equalTo: 'Lucas' },
|
|
34
|
-
},
|
|
35
|
-
data: { age: 21 },
|
|
36
|
-
context,
|
|
37
|
-
select: {},
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
const mockAfterUpdate = mock(async () => {
|
|
42
|
-
await context.wabe.controllers.database.createObjects({
|
|
43
|
-
className: 'Test2',
|
|
44
|
-
data: [{ name: 'test' }],
|
|
45
|
-
context,
|
|
46
|
-
select: {},
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
let spyGetObjects: Mock<any>
|
|
51
|
-
let spyGetObject: Mock<any>
|
|
52
|
-
|
|
53
|
-
beforeAll(async () => {
|
|
54
|
-
const setup = await setupTests([
|
|
55
|
-
{
|
|
56
|
-
name: 'Test',
|
|
57
|
-
fields: {
|
|
58
|
-
name: { type: 'String' },
|
|
59
|
-
},
|
|
60
|
-
permissions: {
|
|
61
|
-
read: {
|
|
62
|
-
authorizedRoles: [],
|
|
63
|
-
requireAuthentication: true,
|
|
64
|
-
},
|
|
65
|
-
create: {
|
|
66
|
-
authorizedRoles: ['Client'],
|
|
67
|
-
requireAuthentication: true,
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
name: 'Test2',
|
|
73
|
-
fields: {
|
|
74
|
-
name: { type: 'String' },
|
|
75
|
-
age: { type: 'Int' },
|
|
76
|
-
userTest: { type: 'Relation', class: 'User' },
|
|
77
|
-
userTest2: { type: 'Pointer', class: 'User' },
|
|
78
|
-
test3: { type: 'Relation', class: 'Test3' },
|
|
79
|
-
},
|
|
80
|
-
permissions: {
|
|
81
|
-
read: {
|
|
82
|
-
authorizedRoles: ['Client2'],
|
|
83
|
-
requireAuthentication: true,
|
|
84
|
-
},
|
|
85
|
-
create: {
|
|
86
|
-
authorizedRoles: [],
|
|
87
|
-
requireAuthentication: true,
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
name: 'Test3',
|
|
93
|
-
fields: {
|
|
94
|
-
name: { type: 'String' },
|
|
95
|
-
test2: { type: 'Pointer', class: 'Test2' },
|
|
96
|
-
},
|
|
97
|
-
permissions: {
|
|
98
|
-
read: {
|
|
99
|
-
authorizedRoles: ['Client2'],
|
|
100
|
-
requireAuthentication: true,
|
|
101
|
-
},
|
|
102
|
-
create: {
|
|
103
|
-
authorizedRoles: [],
|
|
104
|
-
requireAuthentication: true,
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
])
|
|
109
|
-
wabe = setup.wabe
|
|
110
|
-
|
|
111
|
-
context = {
|
|
112
|
-
isRoot: true,
|
|
113
|
-
wabe: {
|
|
114
|
-
controllers: { database: wabe.controllers.database },
|
|
115
|
-
config: wabe.config,
|
|
116
|
-
},
|
|
117
|
-
} as WabeContext<any>
|
|
118
|
-
|
|
119
|
-
spyGetObjects = spyOn(wabe.controllers.database, 'getObjects')
|
|
120
|
-
spyGetObject = spyOn(wabe.controllers.database, 'getObject')
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
afterAll(async () => {
|
|
124
|
-
await closeTests(wabe)
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
beforeEach(async () => {
|
|
128
|
-
await wabe.controllers.database.adapter.clearDatabase()
|
|
129
|
-
|
|
130
|
-
wabe.config.hooks = getDefaultHooks()
|
|
131
|
-
|
|
132
|
-
mockUpdateObject.mockClear()
|
|
133
|
-
mockAfterUpdate.mockClear()
|
|
134
|
-
spyGetObject.mockClear()
|
|
135
|
-
spyGetObjects.mockClear()
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
it('should allow to signUp with anonymous user and read his own data', async () => {
|
|
139
|
-
const setup = await setupTests([
|
|
140
|
-
{
|
|
141
|
-
name: 'User',
|
|
142
|
-
fields: {},
|
|
143
|
-
searchableFields: ['email', 'firstName', 'lastName'],
|
|
144
|
-
permissions: {
|
|
145
|
-
read: {
|
|
146
|
-
authorizedRoles: ['Admin', 'Client'],
|
|
147
|
-
requireAuthentication: true,
|
|
148
|
-
},
|
|
149
|
-
update: {
|
|
150
|
-
authorizedRoles: ['Admin', 'Client'],
|
|
151
|
-
requireAuthentication: true,
|
|
152
|
-
},
|
|
153
|
-
delete: {
|
|
154
|
-
authorizedRoles: ['Admin', 'Client'],
|
|
155
|
-
requireAuthentication: true,
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
])
|
|
160
|
-
|
|
161
|
-
const client = getAnonymousClient(setup.port)
|
|
162
|
-
|
|
163
|
-
const res = await client.request<any>(
|
|
164
|
-
gql`
|
|
165
|
-
mutation signUpWith($input: SignUpWithInput!) {
|
|
166
|
-
signUpWith(input: $input) {
|
|
167
|
-
id
|
|
168
|
-
accessToken
|
|
169
|
-
refreshToken
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
`,
|
|
173
|
-
{
|
|
174
|
-
input: {
|
|
175
|
-
authentication: {
|
|
176
|
-
emailPassword: {
|
|
177
|
-
email: 'test@example.com',
|
|
178
|
-
password: 'password',
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
expect(res.signUpWith.id).toBeDefined()
|
|
186
|
-
expect(res.signUpWith.accessToken).toBeDefined()
|
|
187
|
-
expect(res.signUpWith.refreshToken).toBeDefined()
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
it('should return id of a relation if set to true in select on getObject', async () => {
|
|
191
|
-
const rootClient = getGraphqlClient(wabe.config.port)
|
|
192
|
-
|
|
193
|
-
const createdObject = await rootClient.request<any>(gql`
|
|
194
|
-
mutation createTest2 {
|
|
195
|
-
createTest2(input: { fields: { test3: { createAndAdd: [{ name: "test" }] } } }) {
|
|
196
|
-
test2 {
|
|
197
|
-
id
|
|
198
|
-
test3 {
|
|
199
|
-
edges {
|
|
200
|
-
node {
|
|
201
|
-
name
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
`)
|
|
209
|
-
|
|
210
|
-
const res = await wabe.controllers.database.getObject({
|
|
211
|
-
// @ts-expect-error
|
|
212
|
-
className: 'Test2',
|
|
213
|
-
context,
|
|
214
|
-
id: createdObject.createTest2.test2.id,
|
|
215
|
-
select: {
|
|
216
|
-
id: true,
|
|
217
|
-
// @ts-expect-error
|
|
218
|
-
test3: true,
|
|
219
|
-
},
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
// @ts-expect-error
|
|
223
|
-
expect(res.test3[0]).toEqual(
|
|
224
|
-
expect.objectContaining({
|
|
225
|
-
id: expect.any(String),
|
|
226
|
-
}),
|
|
227
|
-
)
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
it('should be able to create an object with a relation and a pointer', async () => {
|
|
231
|
-
const rootClient = getGraphqlClient(wabe.config.port)
|
|
232
|
-
|
|
233
|
-
const res = await rootClient.request<any>(gql`
|
|
234
|
-
mutation createTest2 {
|
|
235
|
-
createTest2(input: { fields: { userTest: { createAndAdd: [{ name: "test" }] } } }) {
|
|
236
|
-
test2 {
|
|
237
|
-
id
|
|
238
|
-
userTest {
|
|
239
|
-
edges {
|
|
240
|
-
node {
|
|
241
|
-
name
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
`)
|
|
249
|
-
|
|
250
|
-
expect(res.createTest2.test2.userTest.edges[0].node.name).toEqual('test')
|
|
251
|
-
|
|
252
|
-
const res2 = await rootClient.request<any>(gql`
|
|
253
|
-
mutation createTest2 {
|
|
254
|
-
createTest2(input: { fields: { userTest2: { createAndLink: { name: "test" } } } }) {
|
|
255
|
-
test2 {
|
|
256
|
-
id
|
|
257
|
-
userTest2 {
|
|
258
|
-
name
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
`)
|
|
264
|
-
|
|
265
|
-
expect(res2.createTest2.test2.userTest2.name).toEqual('test')
|
|
266
|
-
})
|
|
267
|
-
|
|
268
|
-
it('should not return point data whe no pointer is present on the object', async () => {
|
|
269
|
-
const rootClient = getGraphqlClient(wabe.config.port)
|
|
270
|
-
|
|
271
|
-
await rootClient.request<any>(gql`
|
|
272
|
-
mutation createTest2 {
|
|
273
|
-
createTest2(input: { fields: { age: 20 } }) {
|
|
274
|
-
test2 {
|
|
275
|
-
id
|
|
276
|
-
userTest2 {
|
|
277
|
-
id
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
`)
|
|
283
|
-
|
|
284
|
-
await rootClient.request<any>(gql`
|
|
285
|
-
mutation createTest2 {
|
|
286
|
-
createTest2(input: { fields: { userTest2: { createAndLink: { name: "test" } } } }) {
|
|
287
|
-
test2 {
|
|
288
|
-
id
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
`)
|
|
293
|
-
|
|
294
|
-
const res = await rootClient.request<any>(gql`
|
|
295
|
-
query test2s {
|
|
296
|
-
test2s {
|
|
297
|
-
edges {
|
|
298
|
-
node {
|
|
299
|
-
id
|
|
300
|
-
userTest2 {
|
|
301
|
-
id
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
`)
|
|
308
|
-
|
|
309
|
-
expect(res.test2s.edges[0].node.userTest2).toBeNull()
|
|
310
|
-
expect(res.test2s.edges[1].node.userTest2.id).toBeDefined()
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
it('should not return all relation when no array of id is present on the object', async () => {
|
|
314
|
-
const rootClient = getGraphqlClient(wabe.config.port)
|
|
315
|
-
|
|
316
|
-
await rootClient.request<any>(gql`
|
|
317
|
-
mutation createTest2 {
|
|
318
|
-
createTest2(input: { fields: { age: 20 } }) {
|
|
319
|
-
test2 {
|
|
320
|
-
id
|
|
321
|
-
userTest {
|
|
322
|
-
edges {
|
|
323
|
-
node {
|
|
324
|
-
name
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
`)
|
|
332
|
-
|
|
333
|
-
await rootClient.request<any>(gql`
|
|
334
|
-
mutation createTest2 {
|
|
335
|
-
createTest2(input: { fields: { userTest: { createAndAdd: [{ name: "test" }] } } }) {
|
|
336
|
-
test2 {
|
|
337
|
-
id
|
|
338
|
-
userTest {
|
|
339
|
-
edges {
|
|
340
|
-
node {
|
|
341
|
-
name
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
`)
|
|
349
|
-
|
|
350
|
-
const res = await rootClient.request<any>(gql`
|
|
351
|
-
query test2s {
|
|
352
|
-
test2s {
|
|
353
|
-
edges {
|
|
354
|
-
node {
|
|
355
|
-
id
|
|
356
|
-
userTest {
|
|
357
|
-
edges {
|
|
358
|
-
node {
|
|
359
|
-
name
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
`)
|
|
368
|
-
|
|
369
|
-
expect(res.test2s.edges[0].node.userTest).toBeNull()
|
|
370
|
-
expect(res.test2s.edges[1].node.userTest.edges.length).toEqual(1)
|
|
371
|
-
})
|
|
372
|
-
|
|
373
|
-
it('should return correct data and type for relation with databaseController with created object', async () => {
|
|
374
|
-
const createdUserObject = await wabe.controllers.database.createObject({
|
|
375
|
-
className: 'User',
|
|
376
|
-
context,
|
|
377
|
-
data: {
|
|
378
|
-
name: 'test',
|
|
379
|
-
},
|
|
380
|
-
})
|
|
381
|
-
|
|
382
|
-
await wabe.controllers.database.createObject({
|
|
383
|
-
// @ts-expect-error
|
|
384
|
-
className: 'Test2',
|
|
385
|
-
select: {},
|
|
386
|
-
context,
|
|
387
|
-
data: {
|
|
388
|
-
// @ts-expect-error
|
|
389
|
-
userTest: [createdUserObject?.id],
|
|
390
|
-
},
|
|
391
|
-
})
|
|
392
|
-
|
|
393
|
-
const res = await wabe.controllers.database.getObjects({
|
|
394
|
-
// @ts-expect-error
|
|
395
|
-
className: 'Test2',
|
|
396
|
-
context,
|
|
397
|
-
select: {
|
|
398
|
-
id: true,
|
|
399
|
-
// @ts-expect-error
|
|
400
|
-
userTest: {
|
|
401
|
-
id: true,
|
|
402
|
-
name: true,
|
|
403
|
-
},
|
|
404
|
-
},
|
|
405
|
-
})
|
|
406
|
-
|
|
407
|
-
// @ts-expect-error
|
|
408
|
-
expect(res[0].userTest).toEqual([{ name: 'test', id: expect.any(String) }])
|
|
409
|
-
})
|
|
410
|
-
|
|
411
|
-
it("should return null on a pointer if the pointer doesn't exist", async () => {
|
|
412
|
-
await getGraphqlClient(wabe.config.port).request<any>(graphql.signUpWith, {
|
|
413
|
-
input: {
|
|
414
|
-
authentication: {
|
|
415
|
-
emailPassword: {
|
|
416
|
-
email: 'email@test.com',
|
|
417
|
-
password: 'password,',
|
|
418
|
-
},
|
|
419
|
-
},
|
|
420
|
-
},
|
|
421
|
-
})
|
|
422
|
-
|
|
423
|
-
const res = await wabe.controllers.database.getObjects({
|
|
424
|
-
className: 'User',
|
|
425
|
-
context,
|
|
426
|
-
select: {
|
|
427
|
-
id: true,
|
|
428
|
-
role: true,
|
|
429
|
-
},
|
|
430
|
-
})
|
|
431
|
-
|
|
432
|
-
expect(res[0]?.role).toBeNull()
|
|
433
|
-
})
|
|
434
|
-
|
|
435
|
-
it('should return all the pointer data when we set the relation class to true in select', async () => {
|
|
436
|
-
await getAdminUserClient(context.wabe.config.port, context.wabe, {
|
|
437
|
-
email: 'email@test.fr',
|
|
438
|
-
password: 'password',
|
|
439
|
-
})
|
|
440
|
-
|
|
441
|
-
const res = await wabe.controllers.database.getObjects({
|
|
442
|
-
className: 'User',
|
|
443
|
-
context,
|
|
444
|
-
select: {
|
|
445
|
-
id: true,
|
|
446
|
-
role: true,
|
|
447
|
-
},
|
|
448
|
-
})
|
|
449
|
-
|
|
450
|
-
expect(res[0]?.role).toEqual(
|
|
451
|
-
expect.objectContaining({
|
|
452
|
-
name: 'Admin',
|
|
453
|
-
id: expect.any(String),
|
|
454
|
-
}),
|
|
455
|
-
)
|
|
456
|
-
})
|
|
457
|
-
|
|
458
|
-
it('should have access to original object in afterDelete hook with deleteObject', async () => {
|
|
459
|
-
const mockInsideCallback = mock(() => {})
|
|
460
|
-
wabe.config.hooks = [
|
|
461
|
-
{
|
|
462
|
-
className: 'User',
|
|
463
|
-
operationType: OperationType.AfterDelete,
|
|
464
|
-
priority: 1,
|
|
465
|
-
callback: (hookObject) => {
|
|
466
|
-
mockInsideCallback()
|
|
467
|
-
|
|
468
|
-
expect(hookObject.originalObject).toEqual(
|
|
469
|
-
expect.objectContaining({
|
|
470
|
-
name: 'John',
|
|
471
|
-
age: 20,
|
|
472
|
-
}),
|
|
473
|
-
)
|
|
474
|
-
},
|
|
475
|
-
},
|
|
476
|
-
]
|
|
477
|
-
|
|
478
|
-
const object = await wabe.controllers.database.createObject({
|
|
479
|
-
className: 'User',
|
|
480
|
-
data: {
|
|
481
|
-
name: 'John',
|
|
482
|
-
age: 20,
|
|
483
|
-
},
|
|
484
|
-
select: { id: true },
|
|
485
|
-
context,
|
|
486
|
-
})
|
|
487
|
-
|
|
488
|
-
await wabe.controllers.database.deleteObject({
|
|
489
|
-
className: 'User',
|
|
490
|
-
context,
|
|
491
|
-
select: { id: true },
|
|
492
|
-
id: object?.id || '',
|
|
493
|
-
})
|
|
494
|
-
|
|
495
|
-
expect(mockInsideCallback).toHaveBeenCalledTimes(1)
|
|
496
|
-
})
|
|
497
|
-
|
|
498
|
-
it('should have access to original object in afterDelete hook with deleteObjects', async () => {
|
|
499
|
-
const mockInsideCallback = mock(() => {})
|
|
500
|
-
wabe.config.hooks = [
|
|
501
|
-
{
|
|
502
|
-
className: 'User',
|
|
503
|
-
operationType: OperationType.AfterDelete,
|
|
504
|
-
priority: 1,
|
|
505
|
-
callback: (hookObject) => {
|
|
506
|
-
mockInsideCallback()
|
|
507
|
-
|
|
508
|
-
expect(hookObject.originalObject).toEqual(
|
|
509
|
-
expect.objectContaining({
|
|
510
|
-
name: 'John',
|
|
511
|
-
age: 20,
|
|
512
|
-
}),
|
|
513
|
-
)
|
|
514
|
-
},
|
|
515
|
-
},
|
|
516
|
-
]
|
|
517
|
-
|
|
518
|
-
const object = await wabe.controllers.database.createObject({
|
|
519
|
-
className: 'User',
|
|
520
|
-
data: {
|
|
521
|
-
name: 'John',
|
|
522
|
-
age: 20,
|
|
523
|
-
},
|
|
524
|
-
select: { id: true },
|
|
525
|
-
context,
|
|
526
|
-
})
|
|
527
|
-
|
|
528
|
-
await wabe.controllers.database.deleteObjects({
|
|
529
|
-
className: 'User',
|
|
530
|
-
context,
|
|
531
|
-
select: { id: true },
|
|
532
|
-
where: { id: { equalTo: object?.id || '' } },
|
|
533
|
-
})
|
|
534
|
-
|
|
535
|
-
expect(mockInsideCallback).toHaveBeenCalledTimes(1)
|
|
536
|
-
})
|
|
537
|
-
|
|
538
|
-
it('should have access to original object in afterUpdate hook with updateObject', async () => {
|
|
539
|
-
const mockInsideCallback = mock(() => {})
|
|
540
|
-
wabe.config.hooks = [
|
|
541
|
-
{
|
|
542
|
-
className: 'User',
|
|
543
|
-
operationType: OperationType.AfterUpdate,
|
|
544
|
-
priority: 1,
|
|
545
|
-
callback: (hookObject) => {
|
|
546
|
-
mockInsideCallback()
|
|
547
|
-
|
|
548
|
-
expect(hookObject.originalObject).toEqual(
|
|
549
|
-
expect.objectContaining({
|
|
550
|
-
name: 'John',
|
|
551
|
-
age: 20,
|
|
552
|
-
}),
|
|
553
|
-
)
|
|
554
|
-
},
|
|
555
|
-
},
|
|
556
|
-
]
|
|
557
|
-
|
|
558
|
-
const object = await wabe.controllers.database.createObject({
|
|
559
|
-
className: 'User',
|
|
560
|
-
data: {
|
|
561
|
-
name: 'John',
|
|
562
|
-
age: 20,
|
|
563
|
-
},
|
|
564
|
-
select: { id: true },
|
|
565
|
-
context,
|
|
566
|
-
})
|
|
567
|
-
|
|
568
|
-
await wabe.controllers.database.updateObject({
|
|
569
|
-
className: 'User',
|
|
570
|
-
context,
|
|
571
|
-
select: { id: true },
|
|
572
|
-
data: { name: 'John2' },
|
|
573
|
-
id: object?.id || '',
|
|
574
|
-
})
|
|
575
|
-
|
|
576
|
-
expect(mockInsideCallback).toHaveBeenCalledTimes(1)
|
|
577
|
-
})
|
|
578
|
-
|
|
579
|
-
it('should have access to original object in afterUpdate hook with updateObjects', async () => {
|
|
580
|
-
const mockInsideCallback = mock(() => {})
|
|
581
|
-
wabe.config.hooks = [
|
|
582
|
-
{
|
|
583
|
-
className: 'User',
|
|
584
|
-
operationType: OperationType.AfterUpdate,
|
|
585
|
-
priority: 1,
|
|
586
|
-
callback: (hookObject) => {
|
|
587
|
-
mockInsideCallback()
|
|
588
|
-
|
|
589
|
-
expect(hookObject.originalObject).toEqual(
|
|
590
|
-
expect.objectContaining({
|
|
591
|
-
name: 'John',
|
|
592
|
-
age: 20,
|
|
593
|
-
}),
|
|
594
|
-
)
|
|
595
|
-
},
|
|
596
|
-
},
|
|
597
|
-
]
|
|
598
|
-
|
|
599
|
-
const object = await wabe.controllers.database.createObject({
|
|
600
|
-
className: 'User',
|
|
601
|
-
data: {
|
|
602
|
-
name: 'John',
|
|
603
|
-
age: 20,
|
|
604
|
-
},
|
|
605
|
-
select: { id: true },
|
|
606
|
-
context,
|
|
607
|
-
})
|
|
608
|
-
|
|
609
|
-
await wabe.controllers.database.updateObjects({
|
|
610
|
-
className: 'User',
|
|
611
|
-
context,
|
|
612
|
-
select: { id: true },
|
|
613
|
-
data: { name: 'John2' },
|
|
614
|
-
where: { id: { equalTo: object?.id || '' } },
|
|
615
|
-
})
|
|
616
|
-
|
|
617
|
-
expect(mockInsideCallback).toHaveBeenCalledTimes(1)
|
|
618
|
-
})
|
|
619
|
-
|
|
620
|
-
it('should get all the objects with limit', async () => {
|
|
621
|
-
const res = await wabe.controllers.database.createObjects({
|
|
622
|
-
className: 'User',
|
|
623
|
-
data: [
|
|
624
|
-
{
|
|
625
|
-
name: 'John',
|
|
626
|
-
age: 20,
|
|
627
|
-
},
|
|
628
|
-
{
|
|
629
|
-
name: 'John1',
|
|
630
|
-
age: 20,
|
|
631
|
-
},
|
|
632
|
-
{
|
|
633
|
-
name: 'John2',
|
|
634
|
-
age: 20,
|
|
635
|
-
},
|
|
636
|
-
{
|
|
637
|
-
name: 'John3',
|
|
638
|
-
age: 20,
|
|
639
|
-
},
|
|
640
|
-
{
|
|
641
|
-
name: 'John4',
|
|
642
|
-
age: 20,
|
|
643
|
-
},
|
|
644
|
-
],
|
|
645
|
-
select: { name: true, id: true },
|
|
646
|
-
first: 2,
|
|
647
|
-
context,
|
|
648
|
-
})
|
|
649
|
-
|
|
650
|
-
expect(res.length).toEqual(2)
|
|
651
|
-
})
|
|
652
|
-
|
|
653
|
-
it('should get all the objects with negative limit and offset', async () => {
|
|
654
|
-
const res = await wabe.controllers.database.createObjects({
|
|
655
|
-
className: 'User',
|
|
656
|
-
data: [
|
|
657
|
-
{
|
|
658
|
-
name: 'John',
|
|
659
|
-
age: 20,
|
|
660
|
-
},
|
|
661
|
-
{
|
|
662
|
-
name: 'John1',
|
|
663
|
-
age: 20,
|
|
664
|
-
},
|
|
665
|
-
{
|
|
666
|
-
name: 'John2',
|
|
667
|
-
age: 20,
|
|
668
|
-
},
|
|
669
|
-
{
|
|
670
|
-
name: 'John3',
|
|
671
|
-
age: 20,
|
|
672
|
-
},
|
|
673
|
-
{
|
|
674
|
-
name: 'John4',
|
|
675
|
-
age: 20,
|
|
676
|
-
},
|
|
677
|
-
],
|
|
678
|
-
select: { name: true, id: true },
|
|
679
|
-
context,
|
|
680
|
-
})
|
|
681
|
-
|
|
682
|
-
expect(res.length).toEqual(5)
|
|
683
|
-
|
|
684
|
-
expect(
|
|
685
|
-
wabe.controllers.database.createObjects({
|
|
686
|
-
className: 'User',
|
|
687
|
-
data: [
|
|
688
|
-
{
|
|
689
|
-
name: 'John',
|
|
690
|
-
age: 20,
|
|
691
|
-
},
|
|
692
|
-
{
|
|
693
|
-
name: 'John1',
|
|
694
|
-
age: 20,
|
|
695
|
-
},
|
|
696
|
-
{
|
|
697
|
-
name: 'John2',
|
|
698
|
-
age: 20,
|
|
699
|
-
},
|
|
700
|
-
{
|
|
701
|
-
name: 'John3',
|
|
702
|
-
age: 20,
|
|
703
|
-
},
|
|
704
|
-
{
|
|
705
|
-
name: 'John4',
|
|
706
|
-
age: 20,
|
|
707
|
-
},
|
|
708
|
-
],
|
|
709
|
-
select: { name: true, id: true },
|
|
710
|
-
offset: -2,
|
|
711
|
-
context,
|
|
712
|
-
}),
|
|
713
|
-
).rejects.toThrow()
|
|
714
|
-
})
|
|
715
|
-
|
|
716
|
-
it('should createObjects and deleteObjects with offset and limit', async () => {
|
|
717
|
-
const res = await wabe.controllers.database.createObjects({
|
|
718
|
-
className: 'User',
|
|
719
|
-
data: [
|
|
720
|
-
{
|
|
721
|
-
name: 'John',
|
|
722
|
-
age: 20,
|
|
723
|
-
},
|
|
724
|
-
{
|
|
725
|
-
name: 'John1',
|
|
726
|
-
age: 20,
|
|
727
|
-
},
|
|
728
|
-
{
|
|
729
|
-
name: 'John2',
|
|
730
|
-
age: 20,
|
|
731
|
-
},
|
|
732
|
-
{
|
|
733
|
-
name: 'John3',
|
|
734
|
-
age: 20,
|
|
735
|
-
},
|
|
736
|
-
{
|
|
737
|
-
name: 'John4',
|
|
738
|
-
age: 20,
|
|
739
|
-
},
|
|
740
|
-
],
|
|
741
|
-
select: { name: true, id: true },
|
|
742
|
-
first: 2,
|
|
743
|
-
offset: 2,
|
|
744
|
-
order: { name: 'ASC' },
|
|
745
|
-
context,
|
|
746
|
-
})
|
|
747
|
-
|
|
748
|
-
expect(res.length).toEqual(2)
|
|
749
|
-
expect(res[0]?.name).toEqual('John2')
|
|
750
|
-
expect(res[1]?.name).toEqual('John3')
|
|
751
|
-
|
|
752
|
-
await wabe.controllers.database.deleteObjects({
|
|
753
|
-
className: 'User',
|
|
754
|
-
where: {
|
|
755
|
-
OR: [
|
|
756
|
-
{ name: { equalTo: 'John2' } },
|
|
757
|
-
{ name: { equalTo: 'John3' } },
|
|
758
|
-
{ name: { equalTo: 'John4' } },
|
|
759
|
-
],
|
|
760
|
-
},
|
|
761
|
-
select: { name: true },
|
|
762
|
-
first: 2,
|
|
763
|
-
offset: 1,
|
|
764
|
-
context,
|
|
765
|
-
})
|
|
766
|
-
|
|
767
|
-
const res2 = await wabe.controllers.database.getObjects({
|
|
768
|
-
className: 'User',
|
|
769
|
-
where: {
|
|
770
|
-
OR: [
|
|
771
|
-
{ name: { equalTo: 'John2' } },
|
|
772
|
-
{ name: { equalTo: 'John3' } },
|
|
773
|
-
{ name: { equalTo: 'John4' } },
|
|
774
|
-
],
|
|
775
|
-
},
|
|
776
|
-
context,
|
|
777
|
-
})
|
|
778
|
-
|
|
779
|
-
expect(res2.length).toEqual(0)
|
|
780
|
-
})
|
|
781
|
-
|
|
782
|
-
it('should return null on createObject when no fields are provided', async () => {
|
|
783
|
-
const res = await wabe.controllers.database.createObject({
|
|
784
|
-
className: 'User',
|
|
785
|
-
context,
|
|
786
|
-
data: { name: 'Lucas' },
|
|
787
|
-
select: {},
|
|
788
|
-
})
|
|
789
|
-
|
|
790
|
-
expect(res).toBeNull()
|
|
791
|
-
})
|
|
792
|
-
|
|
793
|
-
it('should return empty array on createObjects when no fields are provided', async () => {
|
|
794
|
-
const res = await wabe.controllers.database.createObjects({
|
|
795
|
-
className: 'User',
|
|
796
|
-
context,
|
|
797
|
-
data: [{ name: 'Lucas' }],
|
|
798
|
-
select: {},
|
|
799
|
-
})
|
|
800
|
-
|
|
801
|
-
expect(res).toBeEmpty()
|
|
802
|
-
})
|
|
803
|
-
|
|
804
|
-
it('should return null on updateObject when no fields are provided', async () => {
|
|
805
|
-
const createdObject = await wabe.controllers.database.createObject({
|
|
806
|
-
className: 'User',
|
|
807
|
-
context,
|
|
808
|
-
data: { name: 'Lucas' },
|
|
809
|
-
select: { id: true },
|
|
810
|
-
})
|
|
811
|
-
|
|
812
|
-
const res = await wabe.controllers.database.updateObject({
|
|
813
|
-
className: 'User',
|
|
814
|
-
context,
|
|
815
|
-
data: { name: 'Lucas' },
|
|
816
|
-
select: {},
|
|
817
|
-
id: createdObject?.id || '',
|
|
818
|
-
})
|
|
819
|
-
|
|
820
|
-
expect(res).toBeNull()
|
|
821
|
-
})
|
|
822
|
-
|
|
823
|
-
it('should return empty array on updateObjects when no fields are provided', async () => {
|
|
824
|
-
await wabe.controllers.database.createObject({
|
|
825
|
-
className: 'User',
|
|
826
|
-
context,
|
|
827
|
-
data: { name: 'Lucas' },
|
|
828
|
-
select: { id: true },
|
|
829
|
-
})
|
|
830
|
-
|
|
831
|
-
const res = await wabe.controllers.database.updateObjects({
|
|
832
|
-
className: 'User',
|
|
833
|
-
context,
|
|
834
|
-
data: { name: 'Lucas2' },
|
|
835
|
-
select: {},
|
|
836
|
-
where: { name: { equalTo: 'Lucas' } },
|
|
837
|
-
})
|
|
838
|
-
|
|
839
|
-
expect(res).toBeEmpty()
|
|
840
|
-
})
|
|
841
|
-
|
|
842
|
-
it('should return null on deleteObject when no fields are provided', async () => {
|
|
843
|
-
const createdObject = await wabe.controllers.database.createObject({
|
|
844
|
-
className: 'User',
|
|
845
|
-
context,
|
|
846
|
-
data: { name: 'Lucas' },
|
|
847
|
-
select: { id: true },
|
|
848
|
-
})
|
|
849
|
-
|
|
850
|
-
const res = await wabe.controllers.database.deleteObject({
|
|
851
|
-
className: 'User',
|
|
852
|
-
context,
|
|
853
|
-
select: {},
|
|
854
|
-
id: createdObject?.id || '',
|
|
855
|
-
})
|
|
856
|
-
|
|
857
|
-
expect(res).toBeNull()
|
|
858
|
-
})
|
|
859
|
-
|
|
860
|
-
it('should return empty array on deleteObjects when no fields are provided', async () => {
|
|
861
|
-
await wabe.controllers.database.createObject({
|
|
862
|
-
className: 'User',
|
|
863
|
-
context,
|
|
864
|
-
data: { name: 'Lucas' },
|
|
865
|
-
select: { id: true },
|
|
866
|
-
})
|
|
867
|
-
|
|
868
|
-
const res = await wabe.controllers.database.deleteObjects({
|
|
869
|
-
className: 'User',
|
|
870
|
-
context,
|
|
871
|
-
select: {},
|
|
872
|
-
where: { name: { equalTo: 'Lucas' } },
|
|
873
|
-
})
|
|
874
|
-
|
|
875
|
-
expect(res).toBeEmpty()
|
|
876
|
-
})
|
|
877
|
-
|
|
878
|
-
it("should return all elements of a class when the object doesn't have ACL but the user is connected", async () => {
|
|
879
|
-
const adminClient = await getAdminUserClient(context.wabe.config.port, context.wabe, {
|
|
880
|
-
email: 'email@test.fr',
|
|
881
|
-
password: 'password',
|
|
882
|
-
})
|
|
883
|
-
|
|
884
|
-
await wabe.controllers.database.createObject({
|
|
885
|
-
className: 'User',
|
|
886
|
-
context: contextWithRoot(context),
|
|
887
|
-
data: {
|
|
888
|
-
name: 'Doe',
|
|
889
|
-
},
|
|
890
|
-
select: {},
|
|
891
|
-
})
|
|
892
|
-
|
|
893
|
-
const {
|
|
894
|
-
users: { edges },
|
|
895
|
-
} = await adminClient.request<any>(graphql.users)
|
|
896
|
-
|
|
897
|
-
expect(edges.length).toEqual(1)
|
|
898
|
-
expect(edges[0]?.node?.email).toEqual('email@test.fr')
|
|
899
|
-
expect(edges[0]?.node?.role?.name).toEqual('Admin')
|
|
900
|
-
})
|
|
901
|
-
|
|
902
|
-
it('should order the element in the query by name ASC using order enum', async () => {
|
|
903
|
-
await wabe.controllers.database.createObjects({
|
|
904
|
-
className: 'User',
|
|
905
|
-
context,
|
|
906
|
-
data: [{ name: 'test1' }, { name: 'test2' }, { name: 'test3' }, { name: 'test4' }],
|
|
907
|
-
select: {},
|
|
908
|
-
})
|
|
909
|
-
|
|
910
|
-
const res = await wabe.controllers.database.getObjects({
|
|
911
|
-
className: 'User',
|
|
912
|
-
context,
|
|
913
|
-
select: { name: true },
|
|
914
|
-
order: { name: 'ASC' },
|
|
915
|
-
})
|
|
916
|
-
|
|
917
|
-
expect(res[0]?.name).toBe('test1')
|
|
918
|
-
expect(res[1]?.name).toBe('test2')
|
|
919
|
-
})
|
|
920
|
-
|
|
921
|
-
it('should create object with subobject (hooks default call authentication before create user)', async () => {
|
|
922
|
-
const res = await wabe.controllers.database.createObject({
|
|
923
|
-
className: 'User',
|
|
924
|
-
context,
|
|
925
|
-
select: { authentication: true },
|
|
926
|
-
data: {
|
|
927
|
-
provider: 'Google',
|
|
928
|
-
isOauth: true,
|
|
929
|
-
authentication: {
|
|
930
|
-
google: {
|
|
931
|
-
email: 'email@test.fr',
|
|
932
|
-
verifiedEmail: true,
|
|
933
|
-
},
|
|
934
|
-
},
|
|
935
|
-
},
|
|
936
|
-
})
|
|
937
|
-
|
|
938
|
-
expect(res?.authentication?.google).toEqual({
|
|
939
|
-
email: 'email@test.fr',
|
|
940
|
-
verifiedEmail: true,
|
|
941
|
-
})
|
|
942
|
-
})
|
|
943
|
-
|
|
944
|
-
it('should not computeObject in runOnSingleObject if there is no hooks to execute on createObject', async () => {
|
|
945
|
-
wabe.config.hooks = []
|
|
946
|
-
|
|
947
|
-
await wabe.controllers.database.createObject({
|
|
948
|
-
className: 'User',
|
|
949
|
-
context,
|
|
950
|
-
data: { name: 'Lucas' },
|
|
951
|
-
select: { id: true },
|
|
952
|
-
})
|
|
953
|
-
|
|
954
|
-
expect(spyGetObject).toHaveBeenCalledTimes(1)
|
|
955
|
-
})
|
|
956
|
-
|
|
957
|
-
it('should not computeObjects in runOnMultipleObjects if there is no hooks to execute on createObjects', async () => {
|
|
958
|
-
wabe.config.hooks = []
|
|
959
|
-
|
|
960
|
-
await wabe.controllers.database.createObjects({
|
|
961
|
-
className: 'User',
|
|
962
|
-
context,
|
|
963
|
-
data: [{ name: 'Lucas' }],
|
|
964
|
-
select: { id: true },
|
|
965
|
-
})
|
|
966
|
-
|
|
967
|
-
expect(spyGetObjects).toHaveBeenCalledTimes(1)
|
|
968
|
-
})
|
|
969
|
-
|
|
970
|
-
it('should not computeObject in runOnSingleObject if there is no hooks to execute on updateObject', async () => {
|
|
971
|
-
wabe.config.hooks = []
|
|
972
|
-
|
|
973
|
-
const res = await wabe.controllers.database.createObject({
|
|
974
|
-
className: 'User',
|
|
975
|
-
context,
|
|
976
|
-
data: { name: 'Lucas' },
|
|
977
|
-
select: { id: true },
|
|
978
|
-
})
|
|
979
|
-
|
|
980
|
-
spyGetObject.mockClear()
|
|
981
|
-
|
|
982
|
-
await wabe.controllers.database.updateObject({
|
|
983
|
-
className: 'User',
|
|
984
|
-
context,
|
|
985
|
-
data: { name: 'Lucas' },
|
|
986
|
-
select: { id: true },
|
|
987
|
-
id: res?.id || '',
|
|
988
|
-
})
|
|
989
|
-
|
|
990
|
-
expect(spyGetObject).toHaveBeenCalledTimes(1)
|
|
991
|
-
})
|
|
992
|
-
|
|
993
|
-
it('should not computeObject in runOnMultipleObject if there is no hooks to execute on updateObjects', async () => {
|
|
994
|
-
wabe.config.hooks = []
|
|
995
|
-
|
|
996
|
-
const res = await wabe.controllers.database.createObject({
|
|
997
|
-
className: 'User',
|
|
998
|
-
context,
|
|
999
|
-
data: { name: 'Lucas' },
|
|
1000
|
-
select: { id: true },
|
|
1001
|
-
})
|
|
1002
|
-
|
|
1003
|
-
spyGetObjects.mockClear()
|
|
1004
|
-
|
|
1005
|
-
await wabe.controllers.database.updateObjects({
|
|
1006
|
-
className: 'User',
|
|
1007
|
-
context,
|
|
1008
|
-
data: { name: 'Lucas' },
|
|
1009
|
-
select: { id: true },
|
|
1010
|
-
where: { id: { equalTo: res?.id || '' } },
|
|
1011
|
-
})
|
|
1012
|
-
|
|
1013
|
-
// Mongo adapter call 2 times getObjects in updateObjects
|
|
1014
|
-
expect(spyGetObjects).toHaveBeenCalledTimes(2)
|
|
1015
|
-
})
|
|
1016
|
-
|
|
1017
|
-
it('should not computeObject in runOnSingleObject if there is no hooks to execute on updateObject', async () => {
|
|
1018
|
-
wabe.config.hooks = []
|
|
1019
|
-
|
|
1020
|
-
const res = await wabe.controllers.database.createObject({
|
|
1021
|
-
className: 'User',
|
|
1022
|
-
context,
|
|
1023
|
-
data: { name: 'Lucas' },
|
|
1024
|
-
select: { id: true },
|
|
1025
|
-
})
|
|
1026
|
-
|
|
1027
|
-
spyGetObject.mockClear()
|
|
1028
|
-
|
|
1029
|
-
await wabe.controllers.database.deleteObject({
|
|
1030
|
-
className: 'User',
|
|
1031
|
-
context,
|
|
1032
|
-
select: { id: true },
|
|
1033
|
-
id: res?.id || '',
|
|
1034
|
-
})
|
|
1035
|
-
|
|
1036
|
-
expect(spyGetObject).toHaveBeenCalledTimes(1)
|
|
1037
|
-
})
|
|
1038
|
-
|
|
1039
|
-
it('should not computeObject in runOnMultipleObject if there is no hooks to execute on updateObjects', async () => {
|
|
1040
|
-
wabe.config.hooks = []
|
|
1041
|
-
|
|
1042
|
-
const res = await wabe.controllers.database.createObject({
|
|
1043
|
-
className: 'User',
|
|
1044
|
-
context,
|
|
1045
|
-
data: { name: 'Lucas' },
|
|
1046
|
-
select: { id: true },
|
|
1047
|
-
})
|
|
1048
|
-
|
|
1049
|
-
spyGetObjects.mockClear()
|
|
1050
|
-
|
|
1051
|
-
await wabe.controllers.database.deleteObjects({
|
|
1052
|
-
className: 'User',
|
|
1053
|
-
context,
|
|
1054
|
-
select: { id: true },
|
|
1055
|
-
where: { id: { equalTo: res?.id || '' } },
|
|
1056
|
-
})
|
|
1057
|
-
|
|
1058
|
-
expect(spyGetObjects).toHaveBeenCalledTimes(1)
|
|
1059
|
-
})
|
|
1060
|
-
|
|
1061
|
-
it('should get the good value in output of createObject after mutation on after hook', async () => {
|
|
1062
|
-
wabe.config.hooks = [
|
|
1063
|
-
{
|
|
1064
|
-
className: 'User',
|
|
1065
|
-
operationType: OperationType.AfterCreate,
|
|
1066
|
-
callback: mockUpdateObject,
|
|
1067
|
-
priority: 1,
|
|
1068
|
-
},
|
|
1069
|
-
{
|
|
1070
|
-
className: 'Test2',
|
|
1071
|
-
operationType: OperationType.AfterUpdate,
|
|
1072
|
-
callback: mockAfterUpdate,
|
|
1073
|
-
priority: 1,
|
|
1074
|
-
},
|
|
1075
|
-
]
|
|
1076
|
-
const res = await context.wabe.controllers.database.createObject({
|
|
1077
|
-
className: 'User',
|
|
1078
|
-
data: { name: 'Lucas', age: 20 },
|
|
1079
|
-
context,
|
|
1080
|
-
select: { age: true },
|
|
1081
|
-
})
|
|
1082
|
-
|
|
1083
|
-
expect(res?.age).toEqual(21)
|
|
1084
|
-
|
|
1085
|
-
expect(mockUpdateObject).toHaveBeenCalledTimes(1)
|
|
1086
|
-
})
|
|
1087
|
-
|
|
1088
|
-
it('should apply afterRead hook mutations to returned object', async () => {
|
|
1089
|
-
wabe.config.hooks = [
|
|
1090
|
-
...getDefaultHooks(),
|
|
1091
|
-
{
|
|
1092
|
-
className: 'User',
|
|
1093
|
-
operationType: OperationType.AfterRead,
|
|
1094
|
-
priority: 2,
|
|
1095
|
-
callback: (hookObject) => {
|
|
1096
|
-
// Mutate the object to ensure the returned value is affected by AfterRead
|
|
1097
|
-
// @ts-expect-error
|
|
1098
|
-
hookObject.object.name = 'mutated-by-after-read'
|
|
1099
|
-
},
|
|
1100
|
-
},
|
|
1101
|
-
]
|
|
1102
|
-
|
|
1103
|
-
const created = await context.wabe.controllers.database.createObject({
|
|
1104
|
-
className: 'User',
|
|
1105
|
-
context,
|
|
1106
|
-
data: { name: 'original-name' },
|
|
1107
|
-
select: { id: true },
|
|
1108
|
-
})
|
|
1109
|
-
|
|
1110
|
-
const res = await context.wabe.controllers.database.getObject({
|
|
1111
|
-
className: 'User',
|
|
1112
|
-
context,
|
|
1113
|
-
id: created?.id || '',
|
|
1114
|
-
select: { id: true, name: true },
|
|
1115
|
-
})
|
|
1116
|
-
|
|
1117
|
-
expect(res?.name).toEqual('mutated-by-after-read')
|
|
1118
|
-
})
|
|
1119
|
-
|
|
1120
|
-
it('should apply afterRead hook mutations to returned objects list', async () => {
|
|
1121
|
-
wabe.config.hooks = [
|
|
1122
|
-
...getDefaultHooks(),
|
|
1123
|
-
{
|
|
1124
|
-
className: 'User',
|
|
1125
|
-
operationType: OperationType.AfterRead,
|
|
1126
|
-
priority: 2,
|
|
1127
|
-
callback: (hookObject) => {
|
|
1128
|
-
// @ts-expect-error
|
|
1129
|
-
hookObject.object.name = 'mutated-by-after-read-list'
|
|
1130
|
-
},
|
|
1131
|
-
},
|
|
1132
|
-
]
|
|
1133
|
-
|
|
1134
|
-
await context.wabe.controllers.database.createObjects({
|
|
1135
|
-
className: 'User',
|
|
1136
|
-
context,
|
|
1137
|
-
select: { id: true },
|
|
1138
|
-
data: [{ name: 'original-name' }],
|
|
1139
|
-
})
|
|
1140
|
-
|
|
1141
|
-
const res = await context.wabe.controllers.database.getObjects({
|
|
1142
|
-
className: 'User',
|
|
1143
|
-
context,
|
|
1144
|
-
select: { id: true, name: true },
|
|
1145
|
-
})
|
|
1146
|
-
|
|
1147
|
-
expect(res[0]?.name).toEqual('mutated-by-after-read-list')
|
|
1148
|
-
})
|
|
1149
|
-
|
|
1150
|
-
it('should get the good value in output of createObjects after mutation on after hook', async () => {
|
|
1151
|
-
wabe.config.hooks = [
|
|
1152
|
-
{
|
|
1153
|
-
className: 'User',
|
|
1154
|
-
operationType: OperationType.AfterCreate,
|
|
1155
|
-
callback: mockUpdateObject,
|
|
1156
|
-
priority: 1,
|
|
1157
|
-
},
|
|
1158
|
-
{
|
|
1159
|
-
className: 'Test2',
|
|
1160
|
-
operationType: OperationType.AfterUpdate,
|
|
1161
|
-
callback: mockAfterUpdate,
|
|
1162
|
-
priority: 1,
|
|
1163
|
-
},
|
|
1164
|
-
]
|
|
1165
|
-
const res = await context.wabe.controllers.database.createObjects({
|
|
1166
|
-
className: 'User',
|
|
1167
|
-
data: [{ name: 'Lucas', age: 20 }],
|
|
1168
|
-
context,
|
|
1169
|
-
select: { age: true },
|
|
1170
|
-
})
|
|
1171
|
-
|
|
1172
|
-
expect(res[0]?.age).toEqual(21)
|
|
1173
|
-
|
|
1174
|
-
expect(mockUpdateObject).toHaveBeenCalledTimes(1)
|
|
1175
|
-
})
|
|
1176
|
-
|
|
1177
|
-
it('should get the good value in output of updateObjects after mutation on after hook', async () => {
|
|
1178
|
-
wabe.config.hooks = [
|
|
1179
|
-
{
|
|
1180
|
-
className: 'User',
|
|
1181
|
-
operationType: OperationType.AfterCreate,
|
|
1182
|
-
callback: mockUpdateObject,
|
|
1183
|
-
priority: 1,
|
|
1184
|
-
},
|
|
1185
|
-
{
|
|
1186
|
-
className: 'Test2',
|
|
1187
|
-
operationType: OperationType.AfterUpdate,
|
|
1188
|
-
callback: mockAfterUpdate,
|
|
1189
|
-
priority: 1,
|
|
1190
|
-
},
|
|
1191
|
-
]
|
|
1192
|
-
await context.wabe.controllers.database.createObjects({
|
|
1193
|
-
className: 'Test2',
|
|
1194
|
-
data: [{ name: 'test', age: 20 }],
|
|
1195
|
-
context,
|
|
1196
|
-
select: {},
|
|
1197
|
-
})
|
|
1198
|
-
|
|
1199
|
-
const res = await context.wabe.controllers.database.updateObjects({
|
|
1200
|
-
className: 'Test2',
|
|
1201
|
-
context,
|
|
1202
|
-
select: { name: true },
|
|
1203
|
-
where: { name: { equalTo: 'test' } },
|
|
1204
|
-
data: { name: 20 },
|
|
1205
|
-
})
|
|
1206
|
-
|
|
1207
|
-
expect(res.length).toEqual(1)
|
|
1208
|
-
|
|
1209
|
-
expect(mockAfterUpdate).toHaveBeenCalledTimes(1)
|
|
1210
|
-
})
|
|
1211
|
-
|
|
1212
|
-
it('should get the good value in output of updateObject after mutation on after hook', async () => {
|
|
1213
|
-
wabe.config.hooks = [
|
|
1214
|
-
{
|
|
1215
|
-
className: 'User',
|
|
1216
|
-
operationType: OperationType.AfterCreate,
|
|
1217
|
-
callback: mockUpdateObject,
|
|
1218
|
-
priority: 1,
|
|
1219
|
-
},
|
|
1220
|
-
{
|
|
1221
|
-
className: 'Test2',
|
|
1222
|
-
operationType: OperationType.AfterUpdate,
|
|
1223
|
-
callback: mockAfterUpdate,
|
|
1224
|
-
priority: 1,
|
|
1225
|
-
},
|
|
1226
|
-
]
|
|
1227
|
-
const res = await context.wabe.controllers.database.createObjects({
|
|
1228
|
-
className: 'Test2',
|
|
1229
|
-
data: [{ name: 'test', age: 20 }],
|
|
1230
|
-
context,
|
|
1231
|
-
select: { id: true },
|
|
1232
|
-
})
|
|
1233
|
-
|
|
1234
|
-
const res2 = await context.wabe.controllers.database.updateObject({
|
|
1235
|
-
className: 'Test2',
|
|
1236
|
-
context,
|
|
1237
|
-
select: { name: true },
|
|
1238
|
-
data: { age: 20 },
|
|
1239
|
-
id: res[0]?.id,
|
|
1240
|
-
})
|
|
1241
|
-
|
|
1242
|
-
expect(res2?.name).toEqual('test')
|
|
1243
|
-
|
|
1244
|
-
expect(mockAfterUpdate).toHaveBeenCalledTimes(1)
|
|
1245
|
-
})
|
|
1246
|
-
|
|
1247
|
-
it("should empty array if equalTo value is undefined and don't match with any object in database", async () => {
|
|
1248
|
-
const roles = await context.wabe.controllers.database.getObjects({
|
|
1249
|
-
className: 'Role',
|
|
1250
|
-
context: contextWithRoot(context),
|
|
1251
|
-
select: { id: true, name: true },
|
|
1252
|
-
where: {
|
|
1253
|
-
name: { equalTo: undefined },
|
|
1254
|
-
},
|
|
1255
|
-
})
|
|
1256
|
-
|
|
1257
|
-
expect(roles).toEqual([])
|
|
1258
|
-
})
|
|
1259
|
-
|
|
1260
|
-
it('should filter objects where field exists (exists: true)', async () => {
|
|
1261
|
-
await context.wabe.controllers.database.createObjects({
|
|
1262
|
-
className: 'Test',
|
|
1263
|
-
data: [
|
|
1264
|
-
{ name: 'Object with name', otherField: 'other' },
|
|
1265
|
-
{ name: 'Another object with name', otherField: 'other' },
|
|
1266
|
-
// @ts-expect-error
|
|
1267
|
-
{ otherField: 'No name field' },
|
|
1268
|
-
],
|
|
1269
|
-
context,
|
|
1270
|
-
select: {},
|
|
1271
|
-
})
|
|
1272
|
-
|
|
1273
|
-
// Test exists: true - should return only objects with name field
|
|
1274
|
-
const objectsWithName = await context.wabe.controllers.database.getObjects({
|
|
1275
|
-
className: 'Test',
|
|
1276
|
-
where: { name: { exists: true } },
|
|
1277
|
-
context,
|
|
1278
|
-
select: { name: true },
|
|
1279
|
-
})
|
|
1280
|
-
|
|
1281
|
-
expect(objectsWithName.length).toBe(2)
|
|
1282
|
-
expect(objectsWithName.every((obj) => obj?.name)).toBe(true)
|
|
1283
|
-
})
|
|
1284
|
-
|
|
1285
|
-
it('should filter objects where field does not exist (exists: false)', async () => {
|
|
1286
|
-
await context.wabe.controllers.database.createObjects({
|
|
1287
|
-
className: 'Test',
|
|
1288
|
-
data: [
|
|
1289
|
-
{
|
|
1290
|
-
name: 'Object with name',
|
|
1291
|
-
otherField: 'other',
|
|
1292
|
-
anotherField: 'another',
|
|
1293
|
-
},
|
|
1294
|
-
// @ts-expect-error
|
|
1295
|
-
{ otherField: 'No name field' },
|
|
1296
|
-
// @ts-expect-error
|
|
1297
|
-
{ anotherField: 'Also no name' },
|
|
1298
|
-
],
|
|
1299
|
-
context,
|
|
1300
|
-
select: {},
|
|
1301
|
-
})
|
|
1302
|
-
|
|
1303
|
-
// Test exists: false - should return only objects without name field
|
|
1304
|
-
const objectsWithoutName = await context.wabe.controllers.database.getObjects({
|
|
1305
|
-
className: 'Test',
|
|
1306
|
-
where: { name: { exists: false } },
|
|
1307
|
-
context,
|
|
1308
|
-
select: { name: true },
|
|
1309
|
-
})
|
|
1310
|
-
|
|
1311
|
-
expect(objectsWithoutName.length).toBe(2)
|
|
1312
|
-
expect(objectsWithoutName.every((obj) => !obj?.name)).toBe(true)
|
|
1313
|
-
})
|
|
1314
|
-
|
|
1315
|
-
it('should work with exists on AND/OR conditions', async () => {
|
|
1316
|
-
await context.wabe.controllers.database.createObjects({
|
|
1317
|
-
className: 'Test',
|
|
1318
|
-
data: [
|
|
1319
|
-
{ name: 'John', age: 25 },
|
|
1320
|
-
{ name: 'Jane', age: 30 },
|
|
1321
|
-
// @ts-expect-error
|
|
1322
|
-
{ age: 35 },
|
|
1323
|
-
// @ts-expect-error
|
|
1324
|
-
{ name: 'Bob' },
|
|
1325
|
-
],
|
|
1326
|
-
context,
|
|
1327
|
-
select: {},
|
|
1328
|
-
})
|
|
1329
|
-
|
|
1330
|
-
// Test with AND condition
|
|
1331
|
-
const objectsWithNameAndAge = await context.wabe.controllers.database.getObjects({
|
|
1332
|
-
className: 'Test',
|
|
1333
|
-
// @ts-expect-error
|
|
1334
|
-
where: {
|
|
1335
|
-
AND: [{ name: { exists: true } }, { age: { exists: true } }],
|
|
1336
|
-
},
|
|
1337
|
-
context,
|
|
1338
|
-
select: { name: true, age: true },
|
|
1339
|
-
})
|
|
1340
|
-
|
|
1341
|
-
expect(objectsWithNameAndAge.length).toBe(2)
|
|
1342
|
-
expect(objectsWithNameAndAge.every((obj) => obj?.name && obj?.age)).toBe(true)
|
|
1343
|
-
})
|
|
1344
|
-
})
|
|
1345
|
-
|
|
1346
|
-
const graphql = {
|
|
1347
|
-
signUpWith: gql`
|
|
1348
|
-
mutation signUpWith($input: SignUpWithInput!) {
|
|
1349
|
-
signUpWith(input: $input) {
|
|
1350
|
-
id
|
|
1351
|
-
accessToken
|
|
1352
|
-
refreshToken
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
`,
|
|
1356
|
-
users: gql`
|
|
1357
|
-
query users {
|
|
1358
|
-
users {
|
|
1359
|
-
edges {
|
|
1360
|
-
node {
|
|
1361
|
-
id
|
|
1362
|
-
email
|
|
1363
|
-
role {
|
|
1364
|
-
id
|
|
1365
|
-
name
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
`,
|
|
1372
|
-
}
|