UNPKG

@sanity/migrate

Version:

Tooling for running data migrations on Sanity.io projects

87 lines (75 loc) 2.27 kB
import {describe, expect, test} from 'vitest' import {stringToPTE} from '../stringToPTE.js' describe('#stringToPTE', () => { test('creates template with no doc types', () => { const stringToPTETemplate = stringToPTE({ documentTypes: [], migrationName: 'My Migration', }) expect(stringToPTETemplate).toMatchInlineSnapshot(` "import {pathsAreEqual, stringToPath} from 'sanity' import {defineMigration, set} from 'sanity/migrate' const targetPath = stringToPath('some.path') export default defineMigration({ title: "My Migration", migrate: { string(node, path, ctx) { if (pathsAreEqual(path, targetPath)) { return set([ { style: 'normal', _type: 'block', children: [ { _type: 'span', marks: [], text: node, }, ], markDefs: [], }, ]) } }, }, }) " `) }) test('creates template with doc types', () => { const stringToPTETemplate = stringToPTE({ documentTypes: ['document-1', 'document-2', 'document-3'], migrationName: 'My Migration', }) expect(stringToPTETemplate).toMatchInlineSnapshot(` "import {pathsAreEqual, stringToPath} from 'sanity' import {defineMigration, set} from 'sanity/migrate' const targetPath = stringToPath('some.path') export default defineMigration({ title: "My Migration", documentTypes: ["document-1", "document-2", "document-3"], migrate: { string(node, path, ctx) { if (pathsAreEqual(path, targetPath)) { return set([ { style: 'normal', _type: 'block', children: [ { _type: 'span', marks: [], text: node, }, ], markDefs: [], }, ]) } }, }, }) " `) }) })