@intuned/browser-dev 0.1.4-dev.0 → 0.1.5-dev.0

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.
@@ -0,0 +1,482 @@
1
+ "use strict";
2
+
3
+ var _extendedTest = require("../../common/extendedTest");
4
+ var _validateDataUsingSchema = require("../validateDataUsingSchema");
5
+ (0, _extendedTest.describe)("injectAttachmentType Tests", () => {
6
+ (0, _extendedTest.describe)("Basic attachment injection", () => {
7
+ (0, _extendedTest.test)("should replace simple attachment type with $ref", async () => {
8
+ const schema = {
9
+ type: "object",
10
+ properties: {
11
+ file: {
12
+ type: "attachment"
13
+ },
14
+ name: {
15
+ type: "string"
16
+ }
17
+ }
18
+ };
19
+ const result = (0, _validateDataUsingSchema.injectAttachmentType)(schema);
20
+ (0, _extendedTest.expect)(result.$defs).toBeDefined();
21
+ (0, _extendedTest.expect)(result.$defs.attachment).toBeDefined();
22
+ (0, _extendedTest.expect)(result.$defs.attachment.type).toBe("object");
23
+ (0, _extendedTest.expect)(result.properties.file).toEqual({
24
+ $ref: "#/$defs/attachment"
25
+ });
26
+ (0, _extendedTest.expect)(result.properties.name).toEqual({
27
+ type: "string"
28
+ });
29
+ });
30
+ (0, _extendedTest.test)("should handle multiple attachment fields in same object", async () => {
31
+ const schema = {
32
+ type: "object",
33
+ properties: {
34
+ document: {
35
+ type: "attachment"
36
+ },
37
+ image: {
38
+ type: "attachment"
39
+ },
40
+ video: {
41
+ type: "attachment"
42
+ },
43
+ title: {
44
+ type: "string"
45
+ },
46
+ count: {
47
+ type: "integer"
48
+ }
49
+ },
50
+ required: ["document", "title"]
51
+ };
52
+ const result = (0, _validateDataUsingSchema.injectAttachmentType)(schema);
53
+ (0, _extendedTest.expect)(result.properties.document).toEqual({
54
+ $ref: "#/$defs/attachment"
55
+ });
56
+ (0, _extendedTest.expect)(result.properties.image).toEqual({
57
+ $ref: "#/$defs/attachment"
58
+ });
59
+ (0, _extendedTest.expect)(result.properties.video).toEqual({
60
+ $ref: "#/$defs/attachment"
61
+ });
62
+ (0, _extendedTest.expect)(result.properties.title).toEqual({
63
+ type: "string"
64
+ });
65
+ (0, _extendedTest.expect)(result.properties.count).toEqual({
66
+ type: "integer"
67
+ });
68
+ (0, _extendedTest.expect)(result.required).toEqual(["document", "title"]);
69
+ (0, _extendedTest.expect)(result.$defs.attachment).toBeDefined();
70
+ });
71
+ });
72
+ (0, _extendedTest.describe)("Nested object attachment injection", () => {
73
+ (0, _extendedTest.test)("should replace attachments in deeply nested objects", async () => {
74
+ const schema = {
75
+ type: "object",
76
+ properties: {
77
+ user: {
78
+ type: "object",
79
+ properties: {
80
+ profile: {
81
+ type: "object",
82
+ properties: {
83
+ avatar: {
84
+ type: "attachment"
85
+ },
86
+ resume: {
87
+ type: "attachment"
88
+ },
89
+ name: {
90
+ type: "string"
91
+ }
92
+ }
93
+ },
94
+ settings: {
95
+ type: "object",
96
+ properties: {
97
+ theme: {
98
+ type: "string"
99
+ }
100
+ }
101
+ }
102
+ }
103
+ },
104
+ metadata: {
105
+ type: "object",
106
+ properties: {
107
+ banner: {
108
+ type: "attachment"
109
+ }
110
+ }
111
+ }
112
+ }
113
+ };
114
+ const result = (0, _validateDataUsingSchema.injectAttachmentType)(schema);
115
+ (0, _extendedTest.expect)(result.properties.user.properties.profile.properties.avatar).toEqual({
116
+ $ref: "#/$defs/attachment"
117
+ });
118
+ (0, _extendedTest.expect)(result.properties.user.properties.profile.properties.resume).toEqual({
119
+ $ref: "#/$defs/attachment"
120
+ });
121
+ (0, _extendedTest.expect)(result.properties.metadata.properties.banner).toEqual({
122
+ $ref: "#/$defs/attachment"
123
+ });
124
+ (0, _extendedTest.expect)(result.properties.user.properties.profile.properties.name).toEqual({
125
+ type: "string"
126
+ });
127
+ (0, _extendedTest.expect)(result.properties.user.properties.settings.properties.theme).toEqual({
128
+ type: "string"
129
+ });
130
+ (0, _extendedTest.expect)(result.$defs.attachment).toBeDefined();
131
+ });
132
+ (0, _extendedTest.test)("should handle attachments in objects with complex nested structures", async () => {
133
+ const schema = {
134
+ type: "object",
135
+ properties: {
136
+ data: {
137
+ type: "object",
138
+ properties: {
139
+ files: {
140
+ type: "object",
141
+ properties: {
142
+ primary: {
143
+ type: "attachment"
144
+ },
145
+ secondary: {
146
+ type: "object",
147
+ properties: {
148
+ backup: {
149
+ type: "attachment"
150
+ },
151
+ archive: {
152
+ type: "attachment"
153
+ }
154
+ }
155
+ }
156
+ }
157
+ }
158
+ }
159
+ }
160
+ }
161
+ };
162
+ const result = (0, _validateDataUsingSchema.injectAttachmentType)(schema);
163
+ (0, _extendedTest.expect)(result.properties.data.properties.files.properties.primary).toEqual({
164
+ $ref: "#/$defs/attachment"
165
+ });
166
+ (0, _extendedTest.expect)(result.properties.data.properties.files.properties.secondary.properties.backup).toEqual({
167
+ $ref: "#/$defs/attachment"
168
+ });
169
+ (0, _extendedTest.expect)(result.properties.data.properties.files.properties.secondary.properties.archive).toEqual({
170
+ $ref: "#/$defs/attachment"
171
+ });
172
+ (0, _extendedTest.expect)(result.$defs.attachment).toBeDefined();
173
+ });
174
+ });
175
+ (0, _extendedTest.describe)("Array attachment injection", () => {
176
+ (0, _extendedTest.test)("should replace attachments in array items", async () => {
177
+ const schema = {
178
+ type: "array",
179
+ items: {
180
+ type: "object",
181
+ properties: {
182
+ file: {
183
+ type: "attachment"
184
+ },
185
+ description: {
186
+ type: "string"
187
+ }
188
+ }
189
+ }
190
+ };
191
+ const result = (0, _validateDataUsingSchema.injectAttachmentType)(schema);
192
+ (0, _extendedTest.expect)(result.items.properties.file).toEqual({
193
+ $ref: "#/$defs/attachment"
194
+ });
195
+ (0, _extendedTest.expect)(result.items.properties.description).toEqual({
196
+ type: "string"
197
+ });
198
+ (0, _extendedTest.expect)(result.$defs.attachment).toBeDefined();
199
+ });
200
+ (0, _extendedTest.test)("should handle arrays of arrays with attachments", async () => {
201
+ const schema = {
202
+ type: "array",
203
+ items: {
204
+ type: "array",
205
+ items: {
206
+ type: "object",
207
+ properties: {
208
+ media: {
209
+ type: "attachment"
210
+ },
211
+ caption: {
212
+ type: "string"
213
+ }
214
+ }
215
+ }
216
+ }
217
+ };
218
+ const result = (0, _validateDataUsingSchema.injectAttachmentType)(schema);
219
+ (0, _extendedTest.expect)(result.items.items.properties.media).toEqual({
220
+ $ref: "#/$defs/attachment"
221
+ });
222
+ (0, _extendedTest.expect)(result.items.items.properties.caption).toEqual({
223
+ type: "string"
224
+ });
225
+ (0, _extendedTest.expect)(result.$defs.attachment).toBeDefined();
226
+ });
227
+ (0, _extendedTest.test)("should handle object with array of objects containing attachments", async () => {
228
+ const schema = {
229
+ type: "object",
230
+ properties: {
231
+ documents: {
232
+ type: "array",
233
+ items: {
234
+ type: "object",
235
+ properties: {
236
+ file: {
237
+ type: "attachment"
238
+ },
239
+ metadata: {
240
+ type: "object",
241
+ properties: {
242
+ thumbnail: {
243
+ type: "attachment"
244
+ },
245
+ title: {
246
+ type: "string"
247
+ }
248
+ }
249
+ }
250
+ }
251
+ }
252
+ },
253
+ title: {
254
+ type: "string"
255
+ }
256
+ }
257
+ };
258
+ const result = (0, _validateDataUsingSchema.injectAttachmentType)(schema);
259
+ (0, _extendedTest.expect)(result.properties.documents.items.properties.file).toEqual({
260
+ $ref: "#/$defs/attachment"
261
+ });
262
+ (0, _extendedTest.expect)(result.properties.documents.items.properties.metadata.properties.thumbnail).toEqual({
263
+ $ref: "#/$defs/attachment"
264
+ });
265
+ (0, _extendedTest.expect)(result.properties.documents.items.properties.metadata.properties.title).toEqual({
266
+ type: "string"
267
+ });
268
+ (0, _extendedTest.expect)(result.properties.title).toEqual({
269
+ type: "string"
270
+ });
271
+ (0, _extendedTest.expect)(result.$defs.attachment).toBeDefined();
272
+ });
273
+ });
274
+ (0, _extendedTest.describe)("Complex mixed scenarios", () => {
275
+ (0, _extendedTest.test)("should handle oneOf/anyOf with attachments", async () => {
276
+ const schema = {
277
+ type: "object",
278
+ properties: {
279
+ content: {
280
+ oneOf: [{
281
+ type: "object",
282
+ properties: {
283
+ text: {
284
+ type: "string"
285
+ }
286
+ }
287
+ }, {
288
+ type: "object",
289
+ properties: {
290
+ file: {
291
+ type: "attachment"
292
+ }
293
+ }
294
+ }]
295
+ },
296
+ fallback: {
297
+ anyOf: [{
298
+ type: "string"
299
+ }, {
300
+ type: "object",
301
+ properties: {
302
+ backup: {
303
+ type: "attachment"
304
+ }
305
+ }
306
+ }]
307
+ }
308
+ }
309
+ };
310
+ const result = (0, _validateDataUsingSchema.injectAttachmentType)(schema);
311
+ (0, _extendedTest.expect)(result.properties.content.oneOf[0].properties.text).toEqual({
312
+ type: "string"
313
+ });
314
+ (0, _extendedTest.expect)(result.properties.content.oneOf[1].properties.file).toEqual({
315
+ $ref: "#/$defs/attachment"
316
+ });
317
+ (0, _extendedTest.expect)(result.properties.fallback.anyOf[0]).toEqual({
318
+ type: "string"
319
+ });
320
+ (0, _extendedTest.expect)(result.properties.fallback.anyOf[1].properties.backup).toEqual({
321
+ $ref: "#/$defs/attachment"
322
+ });
323
+ (0, _extendedTest.expect)(result.$defs.attachment).toBeDefined();
324
+ });
325
+ (0, _extendedTest.test)("should handle allOf with attachments", async () => {
326
+ const schema = {
327
+ type: "object",
328
+ allOf: [{
329
+ type: "object",
330
+ properties: {
331
+ baseFile: {
332
+ type: "attachment"
333
+ },
334
+ id: {
335
+ type: "string"
336
+ }
337
+ }
338
+ }, {
339
+ type: "object",
340
+ properties: {
341
+ extendedFile: {
342
+ type: "attachment"
343
+ },
344
+ metadata: {
345
+ type: "object"
346
+ }
347
+ }
348
+ }]
349
+ };
350
+ const result = (0, _validateDataUsingSchema.injectAttachmentType)(schema);
351
+ (0, _extendedTest.expect)(result.allOf[0].properties.baseFile).toEqual({
352
+ $ref: "#/$defs/attachment"
353
+ });
354
+ (0, _extendedTest.expect)(result.allOf[1].properties.extendedFile).toEqual({
355
+ $ref: "#/$defs/attachment"
356
+ });
357
+ (0, _extendedTest.expect)(result.allOf[0].properties.id).toEqual({
358
+ type: "string"
359
+ });
360
+ (0, _extendedTest.expect)(result.allOf[1].properties.metadata).toEqual({
361
+ type: "object"
362
+ });
363
+ (0, _extendedTest.expect)(result.$defs.attachment).toBeDefined();
364
+ });
365
+ });
366
+ (0, _extendedTest.describe)("Edge cases", () => {
367
+ (0, _extendedTest.test)("should handle schema without attachments", async () => {
368
+ const schema = {
369
+ type: "object",
370
+ properties: {
371
+ name: {
372
+ type: "string"
373
+ },
374
+ age: {
375
+ type: "integer"
376
+ },
377
+ active: {
378
+ type: "boolean"
379
+ }
380
+ }
381
+ };
382
+ const result = (0, _validateDataUsingSchema.injectAttachmentType)(schema);
383
+ (0, _extendedTest.expect)(result.properties.name).toEqual({
384
+ type: "string"
385
+ });
386
+ (0, _extendedTest.expect)(result.properties.age).toEqual({
387
+ type: "integer"
388
+ });
389
+ (0, _extendedTest.expect)(result.properties.active).toEqual({
390
+ type: "boolean"
391
+ });
392
+ (0, _extendedTest.expect)(result.$defs.attachment).toBeDefined();
393
+ });
394
+ (0, _extendedTest.test)("should not modify original schema (immutability)", async () => {
395
+ const schema = {
396
+ type: "object",
397
+ properties: {
398
+ file: {
399
+ type: "attachment"
400
+ },
401
+ name: {
402
+ type: "string"
403
+ }
404
+ }
405
+ };
406
+ const originalSchema = JSON.parse(JSON.stringify(schema));
407
+ const result = (0, _validateDataUsingSchema.injectAttachmentType)(schema);
408
+ (0, _extendedTest.expect)(schema).toEqual(originalSchema);
409
+ (0, _extendedTest.expect)(schema.properties.file).toEqual({
410
+ type: "attachment"
411
+ });
412
+ (0, _extendedTest.expect)(schema.$defs).toBeUndefined();
413
+ (0, _extendedTest.expect)(result.properties.file).toEqual({
414
+ $ref: "#/$defs/attachment"
415
+ });
416
+ (0, _extendedTest.expect)(result.$defs.attachment).toBeDefined();
417
+ });
418
+ (0, _extendedTest.test)("should handle schema with existing $defs", async () => {
419
+ const schema = {
420
+ type: "object",
421
+ properties: {
422
+ file: {
423
+ type: "attachment"
424
+ },
425
+ customField: {
426
+ $ref: "#/$defs/customType"
427
+ }
428
+ },
429
+ $defs: {
430
+ customType: {
431
+ type: "object",
432
+ properties: {
433
+ value: {
434
+ type: "string"
435
+ }
436
+ }
437
+ }
438
+ }
439
+ };
440
+ const result = (0, _validateDataUsingSchema.injectAttachmentType)(schema);
441
+ (0, _extendedTest.expect)(result.$defs.customType).toBeDefined();
442
+ (0, _extendedTest.expect)(result.$defs.customType.properties.value).toEqual({
443
+ type: "string"
444
+ });
445
+ (0, _extendedTest.expect)(result.$defs.attachment).toBeDefined();
446
+ (0, _extendedTest.expect)(result.properties.file).toEqual({
447
+ $ref: "#/$defs/attachment"
448
+ });
449
+ (0, _extendedTest.expect)(result.properties.customField).toEqual({
450
+ $ref: "#/$defs/customType"
451
+ });
452
+ });
453
+ });
454
+ (0, _extendedTest.describe)("Attachment definition structure", () => {
455
+ (0, _extendedTest.test)("should include proper attachment definition in $defs", async () => {
456
+ const schema = {
457
+ type: "object",
458
+ properties: {
459
+ file: {
460
+ type: "attachment"
461
+ }
462
+ }
463
+ };
464
+ const result = (0, _validateDataUsingSchema.injectAttachmentType)(schema);
465
+ (0, _extendedTest.expect)(result.$defs.attachment).toBeDefined();
466
+ (0, _extendedTest.expect)(result.$defs.attachment.type).toBe("object");
467
+ const attachmentProps = result.$defs.attachment.properties;
468
+ (0, _extendedTest.expect)(attachmentProps).toBeDefined();
469
+ (0, _extendedTest.expect)(attachmentProps.fileName).toBeDefined();
470
+ (0, _extendedTest.expect)(attachmentProps.bucket).toBeDefined();
471
+ (0, _extendedTest.expect)(attachmentProps.region).toBeDefined();
472
+ (0, _extendedTest.expect)(attachmentProps.key).toBeDefined();
473
+ (0, _extendedTest.expect)(attachmentProps.suggestedFileName).toBeDefined();
474
+ (0, _extendedTest.expect)(result.$defs.attachment.required).toBeDefined();
475
+ (0, _extendedTest.expect)(result.$defs.attachment.required).toContain("fileName");
476
+ (0, _extendedTest.expect)(result.$defs.attachment.required).toContain("bucket");
477
+ (0, _extendedTest.expect)(result.$defs.attachment.required).toContain("region");
478
+ (0, _extendedTest.expect)(result.$defs.attachment.required).toContain("key");
479
+ (0, _extendedTest.expect)(result.$defs.attachment.required).toContain("suggestedFileName");
480
+ });
481
+ });
482
+ });