diff --git a/package-lock.json b/package-lock.json index 6c3a05f..89bbc23 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "change-case": "^4.1.2" }, "devDependencies": { - "@prismicio/client": "^7.0.1", + "@prismicio/client": "^7.4.0", "@size-limit/preset-small-lib": "^8.2.4", "@types/node": "^20.3.0", "@typescript-eslint/eslint-plugin": "^5.59.8", @@ -1097,39 +1097,17 @@ } }, "node_modules/@prismicio/client": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/@prismicio/client/-/client-7.0.1.tgz", - "integrity": "sha512-f4SDcDwVB2T73QKJJtzXd8LsfvDgIqOQNhC78bwsKLb1BjfPZNucsyIcRI9jGZdGxcU7lA+HStkYHw6z98ofKQ==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@prismicio/client/-/client-7.4.0.tgz", + "integrity": "sha512-CNUSffXDcBXWb8lRko8cW/975hPFKsT0lxziXUOHfsGZ/AOYkQlW9LOO04UBPzHGqWxt0PU45k7kpT692JoKTw==", "dev": true, "dependencies": { - "@prismicio/richtext": "^2.1.5", - "imgix-url-builder": "^0.0.3" + "imgix-url-builder": "^0.0.4" }, "engines": { "node": ">=14.15.0" } }, - "node_modules/@prismicio/richtext": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/@prismicio/richtext/-/richtext-2.1.5.tgz", - "integrity": "sha512-Sf6iCsciPmfK3uQeFmeY9RTRSuhrCVzyU39OkiJ1VJn8O0531pKapGoWS+5WGxouJtE5+jGqV8L+L2mKP7NkXQ==", - "dev": true, - "dependencies": { - "@prismicio/types": "^0.2.7" - }, - "engines": { - "node": ">=12.7.0" - } - }, - "node_modules/@prismicio/types": { - "version": "0.2.8", - "resolved": "https://registry.npmjs.org/@prismicio/types/-/types-0.2.8.tgz", - "integrity": "sha512-EmuYYil56U+UtEifMD/9TmLzpWliV+X6kypwPq47GNXmIXyFK1JsP3z872fUziXwoBjd2YILj28DNdYXlLOpXg==", - "dev": true, - "engines": { - "node": ">=12.7.0" - } - }, "node_modules/@rollup/plugin-typescript": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-10.0.1.tgz", @@ -3990,9 +3968,9 @@ } }, "node_modules/imgix-url-builder": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/imgix-url-builder/-/imgix-url-builder-0.0.3.tgz", - "integrity": "sha512-8Oc2Cn4+jF06sEfJcVPlWYfD2F6RjrwIMbk1xEzux8unoB5LsvFc/GL1BQ47HPaeE12ReX2nMUcjUslGYWLxHA==", + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/imgix-url-builder/-/imgix-url-builder-0.0.4.tgz", + "integrity": "sha512-JRLydfxGTTbSSOG82ewuCgnmw/CzIPzoDqpP3UYD7RE+QWS8ZZbpF87ZuRqtcbEKdxahRsExinuKRxPZVvukWA==", "dev": true, "engines": { "node": ">=12.7.0" @@ -8869,30 +8847,14 @@ } }, "@prismicio/client": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/@prismicio/client/-/client-7.0.1.tgz", - "integrity": "sha512-f4SDcDwVB2T73QKJJtzXd8LsfvDgIqOQNhC78bwsKLb1BjfPZNucsyIcRI9jGZdGxcU7lA+HStkYHw6z98ofKQ==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@prismicio/client/-/client-7.4.0.tgz", + "integrity": "sha512-CNUSffXDcBXWb8lRko8cW/975hPFKsT0lxziXUOHfsGZ/AOYkQlW9LOO04UBPzHGqWxt0PU45k7kpT692JoKTw==", "dev": true, "requires": { - "@prismicio/richtext": "^2.1.5", - "imgix-url-builder": "^0.0.3" + "imgix-url-builder": "^0.0.4" } }, - "@prismicio/richtext": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/@prismicio/richtext/-/richtext-2.1.5.tgz", - "integrity": "sha512-Sf6iCsciPmfK3uQeFmeY9RTRSuhrCVzyU39OkiJ1VJn8O0531pKapGoWS+5WGxouJtE5+jGqV8L+L2mKP7NkXQ==", - "dev": true, - "requires": { - "@prismicio/types": "^0.2.7" - } - }, - "@prismicio/types": { - "version": "0.2.8", - "resolved": "https://registry.npmjs.org/@prismicio/types/-/types-0.2.8.tgz", - "integrity": "sha512-EmuYYil56U+UtEifMD/9TmLzpWliV+X6kypwPq47GNXmIXyFK1JsP3z872fUziXwoBjd2YILj28DNdYXlLOpXg==", - "dev": true - }, "@rollup/plugin-typescript": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-10.0.1.tgz", @@ -10990,9 +10952,9 @@ "dev": true }, "imgix-url-builder": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/imgix-url-builder/-/imgix-url-builder-0.0.3.tgz", - "integrity": "sha512-8Oc2Cn4+jF06sEfJcVPlWYfD2F6RjrwIMbk1xEzux8unoB5LsvFc/GL1BQ47HPaeE12ReX2nMUcjUslGYWLxHA==", + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/imgix-url-builder/-/imgix-url-builder-0.0.4.tgz", + "integrity": "sha512-JRLydfxGTTbSSOG82ewuCgnmw/CzIPzoDqpP3UYD7RE+QWS8ZZbpF87ZuRqtcbEKdxahRsExinuKRxPZVvukWA==", "dev": true }, "import-fresh": { diff --git a/package.json b/package.json index 92cc79c..2b09e75 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "change-case": "^4.1.2" }, "devDependencies": { - "@prismicio/client": "^7.0.1", + "@prismicio/client": "^7.4.0", "@size-limit/preset-small-lib": "^8.2.4", "@types/node": "^20.3.0", "@typescript-eslint/eslint-plugin": "^5.59.8", diff --git a/src/model/customType.ts b/src/model/customType.ts index da11b6c..f4de966 100644 --- a/src/model/customType.ts +++ b/src/model/customType.ts @@ -16,6 +16,7 @@ export type MockCustomTypeModelConfig< label?: string; status?: boolean; repeatable?: boolean; + format?: prismic.CustomTypeModel["format"]; } & ( | { fields?: Definition; @@ -57,6 +58,8 @@ export const customType = < id = changeCase.snakeCase(config.label); } + const format = config.format ?? faker.randomElement(["page", "custom"]); + let json = {} as MockCustomTypeModel["json"]; if ("fields" in config && config.fields) { @@ -70,6 +73,7 @@ export const customType = < label, status: config.status ?? faker.boolean(), repeatable: config.repeatable ?? faker.boolean(), + format, json, } as MockCustomTypeModel; }; diff --git a/test/model-customType.test.ts b/test/model-customType.test.ts index 8e8ec30..097d2fa 100644 --- a/test/model-customType.test.ts +++ b/test/model-customType.test.ts @@ -36,3 +36,12 @@ test("can be configured for specific tabs", (t) => { t.is(actual.json.Main.boolean.type, prismic.CustomTypeModelFieldType.Boolean); }); + +test("can be configured for a specific format", (t) => { + const actual = prismicM.model.customType({ + seed: t.title, + format: "page", + }); + + t.is(actual.format, "page"); +}); diff --git a/test/snapshots/model-customType.test.ts.md b/test/snapshots/model-customType.test.ts.md index e21a00e..89a0d97 100644 --- a/test/snapshots/model-customType.test.ts.md +++ b/test/snapshots/model-customType.test.ts.md @@ -10,18 +10,20 @@ Generated by [AVA](https://avajs.dev). [ { + format: 'page', id: 'id', json: {}, label: 'Id', repeatable: true, - status: false, + status: true, }, { + format: 'page', id: 'id', json: {}, label: 'Id', repeatable: true, - status: false, + status: true, }, ] @@ -31,6 +33,7 @@ Generated by [AVA](https://avajs.dev). [ { + format: 'custom', id: 'ut', json: {}, label: 'Ut', @@ -38,6 +41,7 @@ Generated by [AVA](https://avajs.dev). status: true, }, { + format: 'custom', id: 'ut', json: {}, label: 'Ut', diff --git a/test/snapshots/model-customType.test.ts.snap b/test/snapshots/model-customType.test.ts.snap index 75bb8cb..9fba542 100644 Binary files a/test/snapshots/model-customType.test.ts.snap and b/test/snapshots/model-customType.test.ts.snap differ diff --git a/test/snapshots/value-contentRelationship.test.ts.md b/test/snapshots/value-contentRelationship.test.ts.md index d69a6ed..e37c7af 100644 --- a/test/snapshots/value-contentRelationship.test.ts.md +++ b/test/snapshots/value-contentRelationship.test.ts.md @@ -10,26 +10,26 @@ Generated by [AVA](https://avajs.dev). [ { - id: '8b62bcd', + id: 'f3c898f', isBroken: false, - lang: 'non', + lang: 'accumsan', link_type: 'Document', slug: undefined, tags: [], - type: 'morbi_tristique', + type: 'eget', uid: undefined, - url: 'https://accumsan.example', + url: 'https://cursus.example', }, { - id: '8b62bcd', + id: 'f3c898f', isBroken: false, - lang: 'non', + lang: 'accumsan', link_type: 'Document', slug: undefined, tags: [], - type: 'morbi_tristique', + type: 'eget', uid: undefined, - url: 'https://accumsan.example', + url: 'https://cursus.example', }, ] @@ -39,29 +39,25 @@ Generated by [AVA](https://avajs.dev). [ { - id: '98a8a9e', + id: 'be1d2fe', isBroken: false, - lang: 'tristique', + lang: 'sed', link_type: 'Document', slug: undefined, - tags: [ - 'Nisl', - ], - type: 'leo_duis', + tags: [], + type: 'viverra', uid: undefined, - url: 'https://nibh.example', + url: 'https://sit.example', }, { - id: '98a8a9e', + id: 'be1d2fe', isBroken: false, - lang: 'tristique', + lang: 'sed', link_type: 'Document', slug: undefined, - tags: [ - 'Nisl', - ], - type: 'leo_duis', + tags: [], + type: 'viverra', uid: undefined, - url: 'https://nibh.example', + url: 'https://sit.example', }, ] diff --git a/test/snapshots/value-contentRelationship.test.ts.snap b/test/snapshots/value-contentRelationship.test.ts.snap index 01d941b..796b81b 100644 Binary files a/test/snapshots/value-contentRelationship.test.ts.snap and b/test/snapshots/value-contentRelationship.test.ts.snap differ diff --git a/test/snapshots/value-customType.test.ts.md b/test/snapshots/value-customType.test.ts.md index 7f75566..5cf92cc 100644 --- a/test/snapshots/value-customType.test.ts.md +++ b/test/snapshots/value-customType.test.ts.md @@ -12,32 +12,36 @@ Generated by [AVA](https://avajs.dev). { alternate_languages: [], data: {}, - first_publication_date: '2023-06-16T08:11:27.583Z', - href: 'https://blandit.example', - id: 'ed1cced', - lang: 'id', - last_publication_date: '2020-04-28T02:02:17.347Z', + first_publication_date: '2020-05-15T13:19:44.171Z', + href: 'https://id.example', + id: 'da659ff', + lang: 'velit', + last_publication_date: '2024-03-26T12:40:04.647Z', linked_documents: [], slugs: [], - tags: [], + tags: [ + 'Eget', + ], type: 'viverra', uid: null, - url: 'https://odio.example', + url: 'https://blandit.example', }, { alternate_languages: [], data: {}, - first_publication_date: '2023-06-16T08:11:27.583Z', - href: 'https://blandit.example', - id: 'ed1cced', - lang: 'id', - last_publication_date: '2020-04-28T02:02:17.347Z', + first_publication_date: '2020-05-15T13:19:44.171Z', + href: 'https://id.example', + id: 'da659ff', + lang: 'velit', + last_publication_date: '2024-03-26T12:40:04.647Z', linked_documents: [], slugs: [], - tags: [], + tags: [ + 'Eget', + ], type: 'viverra', uid: null, - url: 'https://odio.example', + url: 'https://blandit.example', }, ] @@ -49,31 +53,35 @@ Generated by [AVA](https://avajs.dev). { alternate_languages: [], data: {}, - first_publication_date: '2024-09-20T09:25:17.265Z', - href: 'https://nulla.example', - id: 'd98a8a9', - lang: 'nibh', - last_publication_date: '2019-05-24T09:29:21.573Z', + first_publication_date: '2020-06-01T20:23:59.940Z', + href: 'https://nibh.example', + id: 'bbe1d2f', + lang: 'sit', + last_publication_date: '2023-08-23T09:11:23.239Z', linked_documents: [], slugs: [], - tags: [], + tags: [ + 'Nec', + ], type: 'ut', uid: null, - url: 'https://quam.example', + url: 'https://nulla.example', }, { alternate_languages: [], data: {}, - first_publication_date: '2024-09-20T09:25:17.265Z', - href: 'https://nulla.example', - id: 'd98a8a9', - lang: 'nibh', - last_publication_date: '2019-05-24T09:29:21.573Z', + first_publication_date: '2020-06-01T20:23:59.940Z', + href: 'https://nibh.example', + id: 'bbe1d2f', + lang: 'sit', + last_publication_date: '2023-08-23T09:11:23.239Z', linked_documents: [], slugs: [], - tags: [], + tags: [ + 'Nec', + ], type: 'ut', uid: null, - url: 'https://quam.example', + url: 'https://nulla.example', }, ] diff --git a/test/snapshots/value-customType.test.ts.snap b/test/snapshots/value-customType.test.ts.snap index 50ae679..3a73917 100644 Binary files a/test/snapshots/value-customType.test.ts.snap and b/test/snapshots/value-customType.test.ts.snap differ