arkos 1.0.3-alpha → 1.0.4-alpha
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/README.md +0 -32
- package/package.json +1 -1
- package/dist/cjs/modules/auth/__tests__/auth.controller.test.js +0 -494
- package/dist/cjs/modules/auth/__tests__/auth.controller.test.js.map +0 -1
- package/dist/cjs/modules/auth/__tests__/auth.service.test.js +0 -470
- package/dist/cjs/modules/auth/__tests__/auth.service.test.js.map +0 -1
- package/dist/cjs/modules/auth/utils/helpers/__tests__/auth.helpers.test.js +0 -43
- package/dist/cjs/modules/auth/utils/helpers/__tests__/auth.helpers.test.js.map +0 -1
- package/dist/cjs/modules/base/utils/helpers/__tests__/base.helpers.test.js +0 -754
- package/dist/cjs/modules/base/utils/helpers/__tests__/base.helpers.test.js.map +0 -1
- package/dist/cjs/modules/file-upload/file-upload.controller.js +0 -226
- package/dist/cjs/modules/file-upload/file-upload.controller.js.map +0 -1
- package/dist/cjs/modules/file-upload/file-upload.router.js +0 -50
- package/dist/cjs/modules/file-upload/file-upload.router.js.map +0 -1
- package/dist/cjs/modules/file-upload/file-upload.service.js +0 -353
- package/dist/cjs/modules/file-upload/file-upload.service.js.map +0 -1
- package/dist/cjs/modules/file-uploader/__tests__/file-uploader.service.test.js +0 -402
- package/dist/cjs/modules/file-uploader/__tests__/file-uploader.service.test.js.map +0 -1
- package/dist/cjs/modules/file-uploader/utils/helpers/__tests__/file-uploader.helpers.test.js +0 -164
- package/dist/cjs/modules/file-uploader/utils/helpers/__tests__/file-uploader.helpers.test.js.map +0 -1
- package/dist/es2020/modules/file-upload/file-upload.controller.js +0 -220
- package/dist/es2020/modules/file-upload/file-upload.controller.js.map +0 -1
- package/dist/es2020/modules/file-upload/file-upload.router.js +0 -44
- package/dist/es2020/modules/file-upload/file-upload.router.js.map +0 -1
- package/dist/es2020/modules/file-upload/file-upload.service.js +0 -345
- package/dist/es2020/modules/file-upload/file-upload.service.js.map +0 -1
- package/dist/types/modules/file-upload/file-upload.controller.d.ts +0 -3
- package/dist/types/modules/file-upload/file-upload.router.d.ts +0 -3
- package/dist/types/modules/file-upload/file-upload.service.d.ts +0 -30
|
@@ -1,754 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base_helpers_1 = require("../base.helpers");
|
|
4
|
-
jest.mock("../../../../../utils/helpers/models.helpers", () => ({
|
|
5
|
-
getPrismaModelRelations: jest.fn((type) => {
|
|
6
|
-
if (type === "Post") {
|
|
7
|
-
return {
|
|
8
|
-
singular: [{ name: "category", type: "Category" }],
|
|
9
|
-
list: [
|
|
10
|
-
{ name: "tags", type: "Tag" },
|
|
11
|
-
{ name: "comments", type: "Comment" },
|
|
12
|
-
],
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
if (type === "User") {
|
|
16
|
-
return {
|
|
17
|
-
singular: [{ name: "profile", type: "Profile" }],
|
|
18
|
-
list: [{ name: "posts", type: "Post" }],
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
if (type === "Comment") {
|
|
22
|
-
return {
|
|
23
|
-
singular: [{ name: "author", type: "User" }],
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
27
|
-
}),
|
|
28
|
-
getModelUniqueFields: jest.fn((modelName) => {
|
|
29
|
-
if (modelName === "Category") {
|
|
30
|
-
return [{ name: "name" }];
|
|
31
|
-
}
|
|
32
|
-
if (modelName === "Tag") {
|
|
33
|
-
return [{ name: "name" }];
|
|
34
|
-
}
|
|
35
|
-
if (modelName === "User") {
|
|
36
|
-
return [{ name: "email" }, { name: "username" }];
|
|
37
|
-
}
|
|
38
|
-
return [];
|
|
39
|
-
}),
|
|
40
|
-
RelationField: {},
|
|
41
|
-
RelationFields: {},
|
|
42
|
-
}));
|
|
43
|
-
describe("handleRelationFieldsInBody", () => {
|
|
44
|
-
describe("Singular Relations", () => {
|
|
45
|
-
it("should handle create operation for singular relation without id", () => {
|
|
46
|
-
const body = {
|
|
47
|
-
name: "John Doe",
|
|
48
|
-
profile: {
|
|
49
|
-
bio: "Software Engineer",
|
|
50
|
-
avatarUrl: "https://example.com/avatar.jpg",
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
const relationFields = {
|
|
54
|
-
singular: [{ name: "profile", type: "Profile" }],
|
|
55
|
-
list: [],
|
|
56
|
-
};
|
|
57
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
58
|
-
expect(result).toEqual({
|
|
59
|
-
name: "John Doe",
|
|
60
|
-
profile: {
|
|
61
|
-
create: {
|
|
62
|
-
bio: "Software Engineer",
|
|
63
|
-
avatarUrl: "https://example.com/avatar.jpg",
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
it("should handle connect operation for singular relation with only id", () => {
|
|
69
|
-
const body = {
|
|
70
|
-
name: "John Doe",
|
|
71
|
-
profile: {
|
|
72
|
-
id: "123",
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
const relationFields = {
|
|
76
|
-
singular: [{ name: "profile", type: "Profile" }],
|
|
77
|
-
list: [],
|
|
78
|
-
};
|
|
79
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
80
|
-
expect(result).toEqual({
|
|
81
|
-
name: "John Doe",
|
|
82
|
-
profile: {
|
|
83
|
-
connect: {
|
|
84
|
-
id: "123",
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
it("should handle connect operation for singular relation with unique field", () => {
|
|
90
|
-
const body = {
|
|
91
|
-
name: "John Doe",
|
|
92
|
-
category: {
|
|
93
|
-
name: "Technology",
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
const relationFields = {
|
|
97
|
-
singular: [
|
|
98
|
-
{
|
|
99
|
-
name: "category",
|
|
100
|
-
type: "Category",
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
list: [],
|
|
104
|
-
};
|
|
105
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
106
|
-
expect(result).toEqual({
|
|
107
|
-
name: "John Doe",
|
|
108
|
-
category: {
|
|
109
|
-
connect: {
|
|
110
|
-
name: "Technology",
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
it("should handle update operation for singular relation with id and other fields", () => {
|
|
116
|
-
const body = {
|
|
117
|
-
name: "John Doe",
|
|
118
|
-
profile: {
|
|
119
|
-
id: "123",
|
|
120
|
-
bio: "Updated Bio",
|
|
121
|
-
avatarUrl: "https://example.com/new-avatar.jpg",
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
const relationFields = {
|
|
125
|
-
singular: [{ name: "profile", type: "Profile" }],
|
|
126
|
-
list: [],
|
|
127
|
-
};
|
|
128
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
129
|
-
expect(result).toEqual({
|
|
130
|
-
name: "John Doe",
|
|
131
|
-
profile: {
|
|
132
|
-
update: {
|
|
133
|
-
data: {
|
|
134
|
-
bio: "Updated Bio",
|
|
135
|
-
avatarUrl: "https://example.com/new-avatar.jpg",
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
it("should handle explicit connect operation with apiAction", () => {
|
|
142
|
-
const body = {
|
|
143
|
-
name: "John Doe",
|
|
144
|
-
profile: {
|
|
145
|
-
id: "123",
|
|
146
|
-
apiAction: "connect",
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
const relationFields = {
|
|
150
|
-
singular: [{ name: "profile", type: "Profile" }],
|
|
151
|
-
list: [],
|
|
152
|
-
};
|
|
153
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
154
|
-
expect(result).toEqual({
|
|
155
|
-
name: "John Doe",
|
|
156
|
-
profile: {
|
|
157
|
-
connect: {
|
|
158
|
-
id: "123",
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
describe("List Relations", () => {
|
|
165
|
-
it("should handle create operation for list relation items without ids", () => {
|
|
166
|
-
const body = {
|
|
167
|
-
title: "My Post",
|
|
168
|
-
tags: [
|
|
169
|
-
{ name: "JavaScript", apiAction: "create" },
|
|
170
|
-
{ name: "TypeScript", apiAction: "create" },
|
|
171
|
-
],
|
|
172
|
-
};
|
|
173
|
-
const relationFields = {
|
|
174
|
-
singular: [],
|
|
175
|
-
list: [{ name: "tags", type: "Tag" }],
|
|
176
|
-
};
|
|
177
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
178
|
-
expect(result).toEqual({
|
|
179
|
-
title: "My Post",
|
|
180
|
-
tags: {
|
|
181
|
-
create: [{ name: "JavaScript" }, { name: "TypeScript" }],
|
|
182
|
-
},
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
it("should handle connect operation for list relation items with only ids", () => {
|
|
186
|
-
const body = {
|
|
187
|
-
title: "My Post",
|
|
188
|
-
tags: [{ id: "1" }, { id: "2" }],
|
|
189
|
-
};
|
|
190
|
-
const relationFields = {
|
|
191
|
-
singular: [],
|
|
192
|
-
list: [{ name: "tags", type: "Tag" }],
|
|
193
|
-
};
|
|
194
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
195
|
-
expect(result).toEqual({
|
|
196
|
-
title: "My Post",
|
|
197
|
-
tags: {
|
|
198
|
-
connect: [{ id: "1" }, { id: "2" }],
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
it("should handle connect operation for list relation items with unique fields", () => {
|
|
203
|
-
const body = {
|
|
204
|
-
title: "My Post",
|
|
205
|
-
tags: [{ name: "JavaScript" }, { name: "TypeScript" }],
|
|
206
|
-
};
|
|
207
|
-
const relationFields = {
|
|
208
|
-
singular: [],
|
|
209
|
-
list: [{ name: "tags", type: "Tag" }],
|
|
210
|
-
};
|
|
211
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
212
|
-
expect(result).toEqual({
|
|
213
|
-
title: "My Post",
|
|
214
|
-
tags: {
|
|
215
|
-
connect: [{ name: "JavaScript" }, { name: "TypeScript" }],
|
|
216
|
-
},
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
it("should handle update operation for list relation items with ids and other fields", () => {
|
|
220
|
-
const body = {
|
|
221
|
-
title: "My Post",
|
|
222
|
-
tags: [
|
|
223
|
-
{ id: "1", name: "Updated JavaScript" },
|
|
224
|
-
{ id: "2", name: "Updated TypeScript" },
|
|
225
|
-
],
|
|
226
|
-
};
|
|
227
|
-
const relationFields = {
|
|
228
|
-
singular: [],
|
|
229
|
-
list: [{ name: "tags", type: "Tag" }],
|
|
230
|
-
};
|
|
231
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
232
|
-
expect(result).toEqual({
|
|
233
|
-
title: "My Post",
|
|
234
|
-
tags: {
|
|
235
|
-
update: [
|
|
236
|
-
{ where: { id: "1" }, data: { name: "Updated JavaScript" } },
|
|
237
|
-
{ where: { id: "2" }, data: { name: "Updated TypeScript" } },
|
|
238
|
-
],
|
|
239
|
-
},
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
it('should handle deleteMany operation for list relation items with apiAction: "delete"', () => {
|
|
243
|
-
const body = {
|
|
244
|
-
title: "My Post",
|
|
245
|
-
tags: [
|
|
246
|
-
{ id: "1", apiAction: "delete" },
|
|
247
|
-
{ id: "2", apiAction: "delete" },
|
|
248
|
-
],
|
|
249
|
-
};
|
|
250
|
-
const relationFields = {
|
|
251
|
-
singular: [],
|
|
252
|
-
list: [{ name: "tags", type: "Tag" }],
|
|
253
|
-
};
|
|
254
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
255
|
-
expect(result).toEqual({
|
|
256
|
-
title: "My Post",
|
|
257
|
-
tags: {
|
|
258
|
-
deleteMany: {
|
|
259
|
-
id: { in: ["1", "2"] },
|
|
260
|
-
},
|
|
261
|
-
},
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
it('should handle disconnect operation for list relation items with apiAction: "disconnect"', () => {
|
|
265
|
-
const body = {
|
|
266
|
-
title: "My Post",
|
|
267
|
-
tags: [
|
|
268
|
-
{ id: "1", apiAction: "disconnect" },
|
|
269
|
-
{ id: "2", apiAction: "disconnect" },
|
|
270
|
-
],
|
|
271
|
-
};
|
|
272
|
-
const relationFields = {
|
|
273
|
-
singular: [],
|
|
274
|
-
list: [{ name: "tags", type: "Tag" }],
|
|
275
|
-
};
|
|
276
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
277
|
-
expect(result).toEqual({
|
|
278
|
-
title: "My Post",
|
|
279
|
-
tags: {
|
|
280
|
-
disconnect: [{ id: "1" }, { id: "2" }],
|
|
281
|
-
},
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
it("should handle mixed operations for list relation items", () => {
|
|
285
|
-
const body = {
|
|
286
|
-
title: "My Post",
|
|
287
|
-
tags: [
|
|
288
|
-
{ name: "New Tag", apiAction: "create" },
|
|
289
|
-
{ id: "1" },
|
|
290
|
-
{ id: "2", name: "Updated Tag" },
|
|
291
|
-
{ id: "3", apiAction: "delete" },
|
|
292
|
-
{ id: "4", apiAction: "disconnect" },
|
|
293
|
-
],
|
|
294
|
-
};
|
|
295
|
-
const relationFields = {
|
|
296
|
-
singular: [],
|
|
297
|
-
list: [{ name: "tags", type: "Tag" }],
|
|
298
|
-
};
|
|
299
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
300
|
-
expect(result).toEqual({
|
|
301
|
-
title: "My Post",
|
|
302
|
-
tags: {
|
|
303
|
-
create: [{ name: "New Tag" }],
|
|
304
|
-
connect: [{ id: "1" }],
|
|
305
|
-
update: [{ where: { id: "2" }, data: { name: "Updated Tag" } }],
|
|
306
|
-
disconnect: [{ id: "4" }],
|
|
307
|
-
deleteMany: { id: { in: ["3"] } },
|
|
308
|
-
},
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
describe("Nested Relations", () => {
|
|
313
|
-
it("should handle nested relations recursively", () => {
|
|
314
|
-
const body = {
|
|
315
|
-
name: "John Doe",
|
|
316
|
-
posts: [
|
|
317
|
-
{
|
|
318
|
-
title: "My First Post",
|
|
319
|
-
category: { name: "Technology" },
|
|
320
|
-
tags: [{ name: "JavaScript" }],
|
|
321
|
-
},
|
|
322
|
-
],
|
|
323
|
-
};
|
|
324
|
-
const relationFields = {
|
|
325
|
-
singular: [],
|
|
326
|
-
list: [{ name: "posts", type: "Post" }],
|
|
327
|
-
};
|
|
328
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
329
|
-
expect(result).toEqual({
|
|
330
|
-
name: "John Doe",
|
|
331
|
-
posts: {
|
|
332
|
-
create: [
|
|
333
|
-
{
|
|
334
|
-
title: "My First Post",
|
|
335
|
-
category: {
|
|
336
|
-
connect: { name: "Technology" },
|
|
337
|
-
},
|
|
338
|
-
tags: {
|
|
339
|
-
connect: [{ name: "JavaScript" }],
|
|
340
|
-
},
|
|
341
|
-
},
|
|
342
|
-
],
|
|
343
|
-
},
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
it("should handle deep nested relations", () => {
|
|
347
|
-
const body = {
|
|
348
|
-
name: "John Doe",
|
|
349
|
-
posts: [
|
|
350
|
-
{
|
|
351
|
-
title: "My First Post",
|
|
352
|
-
comments: [
|
|
353
|
-
{
|
|
354
|
-
content: "Great post!",
|
|
355
|
-
author: { email: "user@example.com", apiAction: "create" },
|
|
356
|
-
},
|
|
357
|
-
],
|
|
358
|
-
},
|
|
359
|
-
],
|
|
360
|
-
};
|
|
361
|
-
const relationFields = {
|
|
362
|
-
singular: [],
|
|
363
|
-
list: [{ name: "posts", type: "Post" }],
|
|
364
|
-
};
|
|
365
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
366
|
-
expect(result).toEqual({
|
|
367
|
-
name: "John Doe",
|
|
368
|
-
posts: {
|
|
369
|
-
create: [
|
|
370
|
-
{
|
|
371
|
-
title: "My First Post",
|
|
372
|
-
comments: {
|
|
373
|
-
create: [
|
|
374
|
-
{
|
|
375
|
-
content: "Great post!",
|
|
376
|
-
author: { create: { email: "user@example.com" } },
|
|
377
|
-
},
|
|
378
|
-
],
|
|
379
|
-
},
|
|
380
|
-
},
|
|
381
|
-
],
|
|
382
|
-
},
|
|
383
|
-
});
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
describe("Edge Cases", () => {
|
|
387
|
-
it("should handle empty arrays for list relation fields", () => {
|
|
388
|
-
const body = {
|
|
389
|
-
name: "John Doe",
|
|
390
|
-
posts: [],
|
|
391
|
-
};
|
|
392
|
-
const relationFields = {
|
|
393
|
-
singular: [],
|
|
394
|
-
list: [{ name: "posts", type: "Post" }],
|
|
395
|
-
};
|
|
396
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
397
|
-
expect(result).toEqual({
|
|
398
|
-
name: "John Doe",
|
|
399
|
-
posts: {},
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
it("should handle null values for relation fields", () => {
|
|
403
|
-
const body = {
|
|
404
|
-
name: "John Doe",
|
|
405
|
-
profile: null,
|
|
406
|
-
posts: null,
|
|
407
|
-
};
|
|
408
|
-
const relationFields = {
|
|
409
|
-
singular: [{ name: "profile", type: "Profile" }],
|
|
410
|
-
list: [{ name: "posts", type: "Post" }],
|
|
411
|
-
};
|
|
412
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
413
|
-
expect(result).toEqual({
|
|
414
|
-
name: "John Doe",
|
|
415
|
-
profile: null,
|
|
416
|
-
posts: null,
|
|
417
|
-
});
|
|
418
|
-
});
|
|
419
|
-
});
|
|
420
|
-
});
|
|
421
|
-
describe("canBeUsedToConnect", () => {
|
|
422
|
-
it("should return true for objects with only an id", () => {
|
|
423
|
-
const modelName = "User";
|
|
424
|
-
const bodyField = { id: "123" };
|
|
425
|
-
expect((0, base_helpers_1.canBeUsedToConnect)(modelName, bodyField)).toBe(true);
|
|
426
|
-
});
|
|
427
|
-
it("should return true for objects with a single unique field", () => {
|
|
428
|
-
const modelName = "User";
|
|
429
|
-
const bodyField = { email: "test@example.com" };
|
|
430
|
-
expect((0, base_helpers_1.canBeUsedToConnect)(modelName, bodyField)).toBe(true);
|
|
431
|
-
});
|
|
432
|
-
it("should return true for objects with a single field from uniqueFields list", () => {
|
|
433
|
-
const modelName = "User";
|
|
434
|
-
const bodyField = { username: "testuser" };
|
|
435
|
-
expect((0, base_helpers_1.canBeUsedToConnect)(modelName, bodyField)).toBe(true);
|
|
436
|
-
});
|
|
437
|
-
it("should return true for objects with apiAction set to connect", () => {
|
|
438
|
-
const modelName = "User";
|
|
439
|
-
const bodyField = { id: "123", apiAction: "connect" };
|
|
440
|
-
expect((0, base_helpers_1.canBeUsedToConnect)(modelName, bodyField)).toBe(true);
|
|
441
|
-
});
|
|
442
|
-
it("should return false for objects with multiple fields", () => {
|
|
443
|
-
const modelName = "User";
|
|
444
|
-
const bodyField = { id: "123", name: "John" };
|
|
445
|
-
expect((0, base_helpers_1.canBeUsedToConnect)(modelName, bodyField)).toBe(false);
|
|
446
|
-
});
|
|
447
|
-
it("should return false for objects with a single field that is not unique", () => {
|
|
448
|
-
const modelName = "User";
|
|
449
|
-
const bodyField = { name: "John" };
|
|
450
|
-
expect((0, base_helpers_1.canBeUsedToConnect)(modelName, bodyField)).toBe(false);
|
|
451
|
-
});
|
|
452
|
-
it("should return false for objects with apiAction set to something other than connect", () => {
|
|
453
|
-
const modelName = "User";
|
|
454
|
-
const bodyField = { id: "123", apiAction: "delete" };
|
|
455
|
-
expect((0, base_helpers_1.canBeUsedToConnect)(modelName, bodyField)).toBe(false);
|
|
456
|
-
});
|
|
457
|
-
it("should return false for null or undefined values", () => {
|
|
458
|
-
const modelName = "User";
|
|
459
|
-
expect((0, base_helpers_1.canBeUsedToConnect)(modelName, null)).toBe(false);
|
|
460
|
-
expect((0, base_helpers_1.canBeUsedToConnect)(modelName, undefined)).toBe(false);
|
|
461
|
-
});
|
|
462
|
-
});
|
|
463
|
-
describe("isListFieldAnArray", () => {
|
|
464
|
-
it("should return true for arrays", () => {
|
|
465
|
-
expect((0, base_helpers_1.isListFieldAnArray)([])).toBe(true);
|
|
466
|
-
expect((0, base_helpers_1.isListFieldAnArray)([1, 2, 3])).toBe(true);
|
|
467
|
-
expect((0, base_helpers_1.isListFieldAnArray)(new Array())).toBe(true);
|
|
468
|
-
});
|
|
469
|
-
it("should return false for non-arrays", () => {
|
|
470
|
-
expect((0, base_helpers_1.isListFieldAnArray)({})).toBe(false);
|
|
471
|
-
expect((0, base_helpers_1.isListFieldAnArray)("array")).toBe(false);
|
|
472
|
-
expect((0, base_helpers_1.isListFieldAnArray)(123)).toBe(false);
|
|
473
|
-
expect((0, base_helpers_1.isListFieldAnArray)(null)).toBe(false);
|
|
474
|
-
expect((0, base_helpers_1.isListFieldAnArray)(undefined)).toBe(false);
|
|
475
|
-
});
|
|
476
|
-
});
|
|
477
|
-
describe("isPrismaRelationFormat", () => {
|
|
478
|
-
it("should return true for objects with Prisma operations", () => {
|
|
479
|
-
expect((0, base_helpers_1.isPrismaRelationFormat)({ create: { name: "Test" } })).toBe(true);
|
|
480
|
-
expect((0, base_helpers_1.isPrismaRelationFormat)({ connect: { id: 1 } })).toBe(true);
|
|
481
|
-
expect((0, base_helpers_1.isPrismaRelationFormat)({
|
|
482
|
-
update: { where: { id: 1 }, data: { name: "Test" } },
|
|
483
|
-
})).toBe(true);
|
|
484
|
-
expect((0, base_helpers_1.isPrismaRelationFormat)({ delete: { id: 1 } })).toBe(true);
|
|
485
|
-
expect((0, base_helpers_1.isPrismaRelationFormat)({ disconnect: { id: 1 } })).toBe(true);
|
|
486
|
-
expect((0, base_helpers_1.isPrismaRelationFormat)({ deleteMany: { id: { in: [1, 2, 3] } } })).toBe(true);
|
|
487
|
-
expect((0, base_helpers_1.isPrismaRelationFormat)({
|
|
488
|
-
connectOrCreate: {
|
|
489
|
-
where: { email: "test@example.com" },
|
|
490
|
-
create: { email: "test@example.com", name: "Test" },
|
|
491
|
-
},
|
|
492
|
-
})).toBe(true);
|
|
493
|
-
expect((0, base_helpers_1.isPrismaRelationFormat)({
|
|
494
|
-
upsert: {
|
|
495
|
-
where: { id: 1 },
|
|
496
|
-
update: { name: "Updated" },
|
|
497
|
-
create: { name: "New" },
|
|
498
|
-
},
|
|
499
|
-
})).toBe(true);
|
|
500
|
-
expect((0, base_helpers_1.isPrismaRelationFormat)({ set: [{ id: 1 }, { id: 2 }] })).toBe(true);
|
|
501
|
-
});
|
|
502
|
-
it("should return false for objects without Prisma operations", () => {
|
|
503
|
-
expect((0, base_helpers_1.isPrismaRelationFormat)({ name: "Test" })).toBe(false);
|
|
504
|
-
expect((0, base_helpers_1.isPrismaRelationFormat)({ id: 1, title: "Test" })).toBe(false);
|
|
505
|
-
expect((0, base_helpers_1.isPrismaRelationFormat)([])).toBe(false);
|
|
506
|
-
expect((0, base_helpers_1.isPrismaRelationFormat)({ apiAction: "create" })).toBe(false);
|
|
507
|
-
});
|
|
508
|
-
});
|
|
509
|
-
describe("handleRelationFieldsInBody with pre-formatted relations", () => {
|
|
510
|
-
describe("Pre-formatted Singular Relations", () => {
|
|
511
|
-
it("should preserve pre-formatted create operation", () => {
|
|
512
|
-
const body = {
|
|
513
|
-
name: "John Doe",
|
|
514
|
-
profile: {
|
|
515
|
-
create: {
|
|
516
|
-
bio: "Software Engineer",
|
|
517
|
-
avatarUrl: "https://example.com/avatar.jpg",
|
|
518
|
-
},
|
|
519
|
-
},
|
|
520
|
-
};
|
|
521
|
-
const relationFields = {
|
|
522
|
-
singular: [{ name: "profile", type: "Profile" }],
|
|
523
|
-
list: [],
|
|
524
|
-
};
|
|
525
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
526
|
-
expect(result).toEqual({
|
|
527
|
-
name: "John Doe",
|
|
528
|
-
profile: {
|
|
529
|
-
create: {
|
|
530
|
-
bio: "Software Engineer",
|
|
531
|
-
avatarUrl: "https://example.com/avatar.jpg",
|
|
532
|
-
},
|
|
533
|
-
},
|
|
534
|
-
});
|
|
535
|
-
});
|
|
536
|
-
it("should preserve pre-formatted connect operation", () => {
|
|
537
|
-
const body = {
|
|
538
|
-
name: "John Doe",
|
|
539
|
-
profile: {
|
|
540
|
-
connect: {
|
|
541
|
-
id: "123",
|
|
542
|
-
},
|
|
543
|
-
},
|
|
544
|
-
};
|
|
545
|
-
const relationFields = {
|
|
546
|
-
singular: [{ name: "profile", type: "Profile" }],
|
|
547
|
-
list: [],
|
|
548
|
-
};
|
|
549
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
550
|
-
expect(result).toEqual({
|
|
551
|
-
name: "John Doe",
|
|
552
|
-
profile: {
|
|
553
|
-
connect: {
|
|
554
|
-
id: "123",
|
|
555
|
-
},
|
|
556
|
-
},
|
|
557
|
-
});
|
|
558
|
-
});
|
|
559
|
-
it("should preserve pre-formatted upsert operation", () => {
|
|
560
|
-
const body = {
|
|
561
|
-
title: "My Post",
|
|
562
|
-
author: {
|
|
563
|
-
upsert: {
|
|
564
|
-
where: { email: "author@example.com" },
|
|
565
|
-
update: { name: "Updated Author" },
|
|
566
|
-
create: { email: "author@example.com", name: "New Author" },
|
|
567
|
-
},
|
|
568
|
-
},
|
|
569
|
-
};
|
|
570
|
-
const relationFields = {
|
|
571
|
-
singular: [{ name: "author", type: "User" }],
|
|
572
|
-
list: [],
|
|
573
|
-
};
|
|
574
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
575
|
-
expect(result).toEqual({
|
|
576
|
-
title: "My Post",
|
|
577
|
-
author: {
|
|
578
|
-
upsert: {
|
|
579
|
-
where: { email: "author@example.com" },
|
|
580
|
-
update: { name: "Updated Author" },
|
|
581
|
-
create: { email: "author@example.com", name: "New Author" },
|
|
582
|
-
},
|
|
583
|
-
},
|
|
584
|
-
});
|
|
585
|
-
});
|
|
586
|
-
});
|
|
587
|
-
describe("Pre-formatted List Relations", () => {
|
|
588
|
-
it("should preserve pre-formatted connect operations in list", () => {
|
|
589
|
-
const body = {
|
|
590
|
-
title: "My Post",
|
|
591
|
-
tags: {
|
|
592
|
-
connect: [{ id: "1" }, { id: "2" }],
|
|
593
|
-
},
|
|
594
|
-
};
|
|
595
|
-
const relationFields = {
|
|
596
|
-
singular: [],
|
|
597
|
-
list: [{ name: "tags", type: "Tag" }],
|
|
598
|
-
};
|
|
599
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
600
|
-
expect(result).toEqual({
|
|
601
|
-
title: "My Post",
|
|
602
|
-
tags: {
|
|
603
|
-
connect: [{ id: "1" }, { id: "2" }],
|
|
604
|
-
},
|
|
605
|
-
});
|
|
606
|
-
});
|
|
607
|
-
it("should preserve pre-formatted create operations in list", () => {
|
|
608
|
-
const body = {
|
|
609
|
-
title: "My Post",
|
|
610
|
-
tags: {
|
|
611
|
-
create: [{ name: "JavaScript" }, { name: "TypeScript" }],
|
|
612
|
-
},
|
|
613
|
-
};
|
|
614
|
-
const relationFields = {
|
|
615
|
-
singular: [],
|
|
616
|
-
list: [{ name: "tags", type: "Tag" }],
|
|
617
|
-
};
|
|
618
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
619
|
-
expect(result).toEqual({
|
|
620
|
-
title: "My Post",
|
|
621
|
-
tags: {
|
|
622
|
-
create: [{ name: "JavaScript" }, { name: "TypeScript" }],
|
|
623
|
-
},
|
|
624
|
-
});
|
|
625
|
-
});
|
|
626
|
-
it("should preserve pre-formatted set operation", () => {
|
|
627
|
-
const body = {
|
|
628
|
-
title: "My Post",
|
|
629
|
-
tags: {
|
|
630
|
-
set: [{ id: "1" }, { id: "2" }],
|
|
631
|
-
},
|
|
632
|
-
};
|
|
633
|
-
const relationFields = {
|
|
634
|
-
singular: [],
|
|
635
|
-
list: [{ name: "tags", type: "Tag" }],
|
|
636
|
-
};
|
|
637
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
638
|
-
expect(result).toEqual({
|
|
639
|
-
title: "My Post",
|
|
640
|
-
tags: {
|
|
641
|
-
set: [{ id: "1" }, { id: "2" }],
|
|
642
|
-
},
|
|
643
|
-
});
|
|
644
|
-
});
|
|
645
|
-
it("should preserve complex pre-formatted operations", () => {
|
|
646
|
-
const body = {
|
|
647
|
-
title: "My Post",
|
|
648
|
-
tags: {
|
|
649
|
-
create: [{ name: "New Tag" }],
|
|
650
|
-
connect: [{ id: "1" }],
|
|
651
|
-
set: [{ id: "5" }, { id: "6" }],
|
|
652
|
-
},
|
|
653
|
-
};
|
|
654
|
-
const relationFields = {
|
|
655
|
-
singular: [],
|
|
656
|
-
list: [{ name: "tags", type: "Tag" }],
|
|
657
|
-
};
|
|
658
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
659
|
-
expect(result).toEqual({
|
|
660
|
-
title: "My Post",
|
|
661
|
-
tags: {
|
|
662
|
-
create: [{ name: "New Tag" }],
|
|
663
|
-
connect: [{ id: "1" }],
|
|
664
|
-
set: [{ id: "5" }, { id: "6" }],
|
|
665
|
-
},
|
|
666
|
-
});
|
|
667
|
-
});
|
|
668
|
-
});
|
|
669
|
-
describe("Mixed Auto and Pre-formatted Relations", () => {
|
|
670
|
-
it("should handle mix of auto and pre-formatted relations", () => {
|
|
671
|
-
const body = {
|
|
672
|
-
title: "My Post",
|
|
673
|
-
category: {
|
|
674
|
-
name: "Technology",
|
|
675
|
-
},
|
|
676
|
-
tags: {
|
|
677
|
-
connect: [{ id: "1" }],
|
|
678
|
-
create: [{ name: "New Tag" }],
|
|
679
|
-
},
|
|
680
|
-
comments: [
|
|
681
|
-
{ content: "Great post!", author: { email: "user@example.com" } },
|
|
682
|
-
],
|
|
683
|
-
};
|
|
684
|
-
const relationFields = {
|
|
685
|
-
singular: [{ name: "category", type: "Category" }],
|
|
686
|
-
list: [
|
|
687
|
-
{ name: "tags", type: "Tag" },
|
|
688
|
-
{ name: "comments", type: "Comment" },
|
|
689
|
-
],
|
|
690
|
-
};
|
|
691
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
692
|
-
expect(result).toEqual({
|
|
693
|
-
title: "My Post",
|
|
694
|
-
category: {
|
|
695
|
-
connect: {
|
|
696
|
-
name: "Technology",
|
|
697
|
-
},
|
|
698
|
-
},
|
|
699
|
-
tags: {
|
|
700
|
-
connect: [{ id: "1" }],
|
|
701
|
-
create: [{ name: "New Tag" }],
|
|
702
|
-
},
|
|
703
|
-
comments: {
|
|
704
|
-
create: [
|
|
705
|
-
{
|
|
706
|
-
content: "Great post!",
|
|
707
|
-
author: {
|
|
708
|
-
connect: {
|
|
709
|
-
email: "user@example.com",
|
|
710
|
-
},
|
|
711
|
-
},
|
|
712
|
-
},
|
|
713
|
-
],
|
|
714
|
-
},
|
|
715
|
-
});
|
|
716
|
-
});
|
|
717
|
-
it("should process nested relations but preserve pre-formatted ones", () => {
|
|
718
|
-
const body = {
|
|
719
|
-
name: "John Doe",
|
|
720
|
-
posts: [
|
|
721
|
-
{
|
|
722
|
-
title: "My First Post",
|
|
723
|
-
category: {
|
|
724
|
-
connect: { name: "Preformatted Category" },
|
|
725
|
-
},
|
|
726
|
-
comments: [{ content: "Great post!" }],
|
|
727
|
-
},
|
|
728
|
-
],
|
|
729
|
-
};
|
|
730
|
-
const relationFields = {
|
|
731
|
-
singular: [],
|
|
732
|
-
list: [{ name: "posts", type: "Post" }],
|
|
733
|
-
};
|
|
734
|
-
const result = (0, base_helpers_1.handleRelationFieldsInBody)(body, relationFields);
|
|
735
|
-
expect(result).toEqual({
|
|
736
|
-
name: "John Doe",
|
|
737
|
-
posts: {
|
|
738
|
-
create: [
|
|
739
|
-
{
|
|
740
|
-
title: "My First Post",
|
|
741
|
-
category: {
|
|
742
|
-
connect: { name: "Preformatted Category" },
|
|
743
|
-
},
|
|
744
|
-
comments: {
|
|
745
|
-
create: [{ content: "Great post!" }],
|
|
746
|
-
},
|
|
747
|
-
},
|
|
748
|
-
],
|
|
749
|
-
},
|
|
750
|
-
});
|
|
751
|
-
});
|
|
752
|
-
});
|
|
753
|
-
});
|
|
754
|
-
//# sourceMappingURL=base.helpers.test.js.map
|