|
| 1 | +import actionCreators from '../../../../src/lib/migration-steps/action-creators' |
| 2 | +import EntryDerive from '../../../../src/lib/interfaces/entry-derive' |
| 3 | +import EntryDeriveIntent from '../../../../src/lib/intent/entry-derive' |
| 4 | +import runIntent from '../../lib/intent/run-intent' |
| 5 | +import fakeCallsite from '../../../helpers/fake-callsite' |
| 6 | +import makeApiEntry from '../../../helpers/make-api-entry' |
| 7 | + |
| 8 | +export default async function renderSetup () { |
| 9 | + const step: EntryDerive = { |
| 10 | + derivedContentType: 'author', |
| 11 | + from: ['authorName', 'authorTwitterHandle'], |
| 12 | + toReferenceField: 'author', |
| 13 | + derivedFields: ['firstName', 'lastName', 'twitterHandle'], |
| 14 | + identityKey: async (fromFields: any) => fromFields.authorTwitterHandle['en-US'], |
| 15 | + shouldPublish: true, |
| 16 | + deriveEntryForLocale: async (inputFields: any, locale: string) => { |
| 17 | + if (locale === 'de-DE') { |
| 18 | + return |
| 19 | + } |
| 20 | + const [firstName, lastName] = inputFields.authorName[locale].split(' ') |
| 21 | + const twitterHandle = inputFields.authorTwitterHandle[locale] |
| 22 | + |
| 23 | + return { |
| 24 | + firstName, |
| 25 | + lastName, |
| 26 | + twitterHandle |
| 27 | + } |
| 28 | + } |
| 29 | + } |
| 30 | + const intent: EntryDeriveIntent = actionCreators.contentType.deriveLinkedEntries('entry', 0, step, fakeCallsite()) |
| 31 | + |
| 32 | + const contentTypes = [{ |
| 33 | + name: 'Entry', |
| 34 | + sys: { |
| 35 | + id: 'entry', |
| 36 | + version: 1 |
| 37 | + }, |
| 38 | + fields: [ |
| 39 | + { |
| 40 | + id: 'text', |
| 41 | + type: 'Text' |
| 42 | + }, { |
| 43 | + id: 'authorName', |
| 44 | + type: 'Symbol' |
| 45 | + }, { |
| 46 | + id: 'authorTwitterHandle', |
| 47 | + type: 'Symbol' |
| 48 | + }, { |
| 49 | + id: 'author', |
| 50 | + type: 'Link', |
| 51 | + linkType: 'Entry' |
| 52 | + } |
| 53 | + ] |
| 54 | + }, { |
| 55 | + name: 'Author', |
| 56 | + sys: { |
| 57 | + id: 'author', |
| 58 | + version: 1 |
| 59 | + }, |
| 60 | + fields: [ |
| 61 | + { |
| 62 | + id: 'firstName', |
| 63 | + type: 'Text' |
| 64 | + }, { |
| 65 | + id: 'lastName', |
| 66 | + type: 'Symbol' |
| 67 | + }, { |
| 68 | + id: 'twitterHandle', |
| 69 | + type: 'Symbol' |
| 70 | + } |
| 71 | + ] |
| 72 | + }] |
| 73 | + const locales = ['de-DE', 'en-US'] |
| 74 | + const entries = [ |
| 75 | + makeApiEntry({ |
| 76 | + id: 'doge', |
| 77 | + contentTypeId: 'entry', |
| 78 | + version: 1, |
| 79 | + fields: { |
| 80 | + text: { |
| 81 | + 'en-US': 'Such text, wow', |
| 82 | + 'de-DE': 'Solch Text, wow' |
| 83 | + }, |
| 84 | + authorName: { |
| 85 | + 'en-US': 'Author McAuthorface' |
| 86 | + }, |
| 87 | + authorTwitterHandle: { |
| 88 | + 'en-US': 'mcauthorface' |
| 89 | + } |
| 90 | + } |
| 91 | + }), |
| 92 | + makeApiEntry({ |
| 93 | + id: 'clickbait', |
| 94 | + contentTypeId: 'entry', |
| 95 | + version: 1, |
| 96 | + fields: { |
| 97 | + text: { |
| 98 | + 'en-US': 'You won\'t believe what happened next', |
| 99 | + 'de-DE': 'Du wirst nicht glauben was als nächstes passierte' |
| 100 | + }, |
| 101 | + authorName: { |
| 102 | + 'en-US': 'Author McAuthorface' |
| 103 | + }, |
| 104 | + authorTwitterHandle: { |
| 105 | + 'en-US': 'mcauthorface' |
| 106 | + } |
| 107 | + } |
| 108 | + }), |
| 109 | + makeApiEntry({ |
| 110 | + id: 'categorical-imperative', |
| 111 | + contentTypeId: 'entry', |
| 112 | + version: 1, |
| 113 | + fields: { |
| 114 | + text: { |
| 115 | + 'en-US': 'Act only according to that maxim whereby you can, at the same time, will that it should become a universal law', |
| 116 | + 'de-DE': 'Handle nur nach derjenigen Maxime, durch die du zugleich wollen kannst, dass sie ein allgemeines Gesetz werde' |
| 117 | + }, |
| 118 | + authorName: { |
| 119 | + 'en-US': 'Immanuel Kant' |
| 120 | + }, |
| 121 | + authorTwitterHandle: { |
| 122 | + 'en-US': 'ikant' |
| 123 | + } |
| 124 | + } |
| 125 | + }) |
| 126 | + ] |
| 127 | + |
| 128 | + const api = await runIntent(intent, contentTypes, entries, locales) |
| 129 | + return await api.getRequestBatches() |
| 130 | +} |
0 commit comments