@intuned/browser-dev 0.1.4-dev.1 → 0.1.5-dev.1
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 -1
- package/dist/ai/export.d.ts +1 -1
- package/dist/ai/index.d.ts +1 -1
- package/dist/ai/isPageLoaded.js +14 -3
- package/dist/ai/tests/testIsPageLoaded.spec.js +3 -3
- package/dist/helpers/downloadFile.js +37 -0
- package/dist/helpers/export.d.ts +10 -7
- package/dist/helpers/frame_utils/constants.js +8 -0
- package/dist/helpers/frame_utils/findAllIframes.js +79 -0
- package/dist/helpers/frame_utils/getContainerFrame.js +22 -0
- package/dist/helpers/frame_utils/index.js +44 -0
- package/dist/helpers/frame_utils/tests/testFindAllIframes.spec.js +170 -0
- package/dist/helpers/gotoUrl.js +1 -1
- package/dist/helpers/index.d.ts +10 -7
- package/dist/helpers/index.js +0 -19
- package/dist/helpers/tests/testDownloadFile.spec.js +41 -6
- package/dist/helpers/tests/testInjectAttachmentType.spec.js +482 -0
- package/dist/helpers/tests/testValidateDataUsingSchema.spec.js +35 -31
- package/dist/helpers/tests/testWithDomSettledWait.spec.js +119 -0
- package/dist/helpers/types/Attachment.js +11 -6
- package/dist/helpers/types/index.js +1 -20
- package/dist/helpers/uploadFileToS3.js +2 -2
- package/dist/helpers/validateDataUsingSchema.js +30 -71
- package/dist/helpers/waitForDomSettled.js +57 -40
- package/dist/intunedServices/ApiGateway/tests/testApiGateway.spec.js +4 -4
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/testArrayExtractorFromPage.spec.js +271 -2
- package/dist/optimized-extractors/listExtractionHelpers/runAiExtraction.js +55 -8
- package/generated-docs/ai/functions/extractStructuredData.mdx +5 -5
- package/generated-docs/ai/functions/isPageLoaded.mdx +1 -0
- package/generated-docs/helpers/functions/clickButtonAndWait.mdx +63 -0
- package/generated-docs/helpers/functions/clickUntilExhausted.mdx +112 -0
- package/generated-docs/helpers/functions/scrollToLoadContent.mdx +1 -7
- package/generated-docs/helpers/functions/validateDataUsingSchema.mdx +5 -5
- package/how-to-generate-docs.md +1 -0
- package/package.json +2 -2
- package/dist/helpers/types/CustomTypeRegistry.js +0 -48
|
@@ -37,6 +37,16 @@ const content = `
|
|
|
37
37
|
<a href="https://intuned-docs-public-images.s3.us-west-2.amazonaws.com/large_pdf.pdf">Download Text File</a>
|
|
38
38
|
</div>
|
|
39
39
|
|
|
40
|
+
<div>
|
|
41
|
+
<h3>Print Dialog Download</h3>
|
|
42
|
+
<button id="print-button">Print Document</button>
|
|
43
|
+
<script>
|
|
44
|
+
document.getElementById('print-button').addEventListener('click', function() {
|
|
45
|
+
window.print();
|
|
46
|
+
});
|
|
47
|
+
</script>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
40
50
|
</body>
|
|
41
51
|
</html>
|
|
42
52
|
`;
|
|
@@ -56,14 +66,14 @@ async function createUserDirWithPreferences() {
|
|
|
56
66
|
await (0, _promises.writeFile)(preferencesPath, JSON.stringify(preferences));
|
|
57
67
|
return (0, _path.resolve)(userDir);
|
|
58
68
|
}
|
|
59
|
-
_extendedTest.describe
|
|
69
|
+
(0, _extendedTest.describe)("TestNotInGeneration", () => {
|
|
60
70
|
let context;
|
|
61
71
|
let page;
|
|
62
72
|
(0, _extendedTest.beforeAll)(async () => {
|
|
63
73
|
const dir = await createUserDirWithPreferences();
|
|
64
74
|
process.env.MODE = "";
|
|
65
75
|
context = await _playwrightCore.chromium.launchPersistentContext(dir, {
|
|
66
|
-
headless:
|
|
76
|
+
headless: false,
|
|
67
77
|
args: ["--no-first-run", "--disable-sync", "--disable-translate", "--disable-features=TranslateUI", "--disable-features=NetworkService", "--lang=en", "--disable-blink-features=AutomationControlled"],
|
|
68
78
|
acceptDownloads: true
|
|
69
79
|
});
|
|
@@ -97,7 +107,7 @@ _extendedTest.describe.skip("TestNotInGeneration", () => {
|
|
|
97
107
|
(0, _extendedTest.expect)(path).toBeDefined();
|
|
98
108
|
(0, _extendedTest.expect)(String(path)).toContain("/var/folders/");
|
|
99
109
|
});
|
|
100
|
-
_extendedTest.test
|
|
110
|
+
(0, _extendedTest.test)("should upload image to s3", async () => {
|
|
101
111
|
await page.setContent(content);
|
|
102
112
|
const downloadedImage = await (0, _.downloadFile)({
|
|
103
113
|
page,
|
|
@@ -120,7 +130,7 @@ _extendedTest.describe.skip("TestNotInGeneration", () => {
|
|
|
120
130
|
(0, _extendedTest.expect)(uploadedFile.suggestedFileName).toBeDefined();
|
|
121
131
|
(0, _extendedTest.expect)(uploadedFile.bucket).toBe(process.env.INTUNED_S3_BUCKET);
|
|
122
132
|
});
|
|
123
|
-
_extendedTest.test
|
|
133
|
+
(0, _extendedTest.test)("should upload file to s3", async () => {
|
|
124
134
|
await page.setContent(content);
|
|
125
135
|
const download = await (0, _.downloadFile)({
|
|
126
136
|
page,
|
|
@@ -133,6 +143,18 @@ _extendedTest.describe.skip("TestNotInGeneration", () => {
|
|
|
133
143
|
(0, _extendedTest.expect)(uploadedFile.suggestedFileName).toBeDefined();
|
|
134
144
|
(0, _extendedTest.expect)(uploadedFile.bucket).toBe(process.env.INTUNED_S3_BUCKET);
|
|
135
145
|
});
|
|
146
|
+
(0, _extendedTest.test)("should download from print dialog", async () => {
|
|
147
|
+
await page.setContent(content);
|
|
148
|
+
const printButton = page.locator("#print-button");
|
|
149
|
+
const download = await (0, _.downloadFile)({
|
|
150
|
+
page,
|
|
151
|
+
trigger: printButton
|
|
152
|
+
});
|
|
153
|
+
(0, _extendedTest.expect)(download).toBeDefined();
|
|
154
|
+
const downloadPath = await download.path();
|
|
155
|
+
(0, _extendedTest.expect)(downloadPath).toBeDefined();
|
|
156
|
+
(0, _extendedTest.expect)(download.suggestedFilename()).toContain(".pdf");
|
|
157
|
+
});
|
|
136
158
|
});
|
|
137
159
|
(0, _extendedTest.describe)("TestInGeneration", () => {
|
|
138
160
|
let context;
|
|
@@ -141,7 +163,7 @@ _extendedTest.describe.skip("TestNotInGeneration", () => {
|
|
|
141
163
|
process.env.MODE = "generate_code";
|
|
142
164
|
const dir = await createUserDirWithPreferences();
|
|
143
165
|
context = await _playwrightCore.chromium.launchPersistentContext(dir, {
|
|
144
|
-
headless:
|
|
166
|
+
headless: false,
|
|
145
167
|
userAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
|
|
146
168
|
args: ["--no-first-run", "--disable-sync", "--disable-translate", "--disable-features=TranslateUI", "--disable-features=NetworkService", "--lang=en", "--disable-blink-features=AutomationControlled"],
|
|
147
169
|
acceptDownloads: true
|
|
@@ -188,7 +210,7 @@ _extendedTest.describe.skip("TestNotInGeneration", () => {
|
|
|
188
210
|
});
|
|
189
211
|
(0, _extendedTest.expect)(downloadedImage.path).toBeDefined();
|
|
190
212
|
});
|
|
191
|
-
_extendedTest.test
|
|
213
|
+
(0, _extendedTest.test)("should upload file to s3", async () => {
|
|
192
214
|
await page.setContent(content);
|
|
193
215
|
const download = await (0, _.downloadFile)({
|
|
194
216
|
page,
|
|
@@ -203,4 +225,17 @@ _extendedTest.describe.skip("TestNotInGeneration", () => {
|
|
|
203
225
|
(0, _extendedTest.expect)(uploadedFile.bucket).toBe("testing_bucket");
|
|
204
226
|
(0, _extendedTest.expect)(uploadedFile.region).toBe("testing_region");
|
|
205
227
|
});
|
|
228
|
+
(0, _extendedTest.test)("should download from print dialog", async () => {
|
|
229
|
+
await page.setContent(content);
|
|
230
|
+
const printButton = page.locator("#print-button");
|
|
231
|
+
const download = await (0, _.downloadFile)({
|
|
232
|
+
page,
|
|
233
|
+
trigger: printButton
|
|
234
|
+
});
|
|
235
|
+
(0, _extendedTest.expect)(download).toBeDefined();
|
|
236
|
+
const cancelled = await download.failure();
|
|
237
|
+
if (cancelled) {
|
|
238
|
+
(0, _extendedTest.expect)(cancelled).toContain("canceled");
|
|
239
|
+
}
|
|
240
|
+
});
|
|
206
241
|
});
|
|
@@ -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
|
+
});
|