-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
216 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { expect } from 'chai' | ||
import * as sinon from 'sinon' | ||
import renderSetup from './render-setup' | ||
|
||
import { renderPlan } from '../../../../src/bin/lib/render-migration' | ||
|
||
describe('Rendering', async () => { | ||
const requestBatches = await renderSetup() | ||
|
||
describe('Render Plan ', () => { | ||
let logSpy | ||
|
||
beforeEach(function () { | ||
logSpy = sinon.spy(console, 'log') | ||
}) | ||
|
||
afterEach(function () { | ||
logSpy.restore() | ||
}) | ||
|
||
describe('when --quiet option is passed', () => { | ||
it ('logs less verbose information of the execution', () => { | ||
renderPlan(requestBatches,'env-unit', true) | ||
|
||
expect(logSpy.called).to.eq(true) | ||
expect(logSpy.getCall(2).args).not.to.match(/from:/) | ||
expect(logSpy.getCall(2).args).not.to.match(/to:/) | ||
expect(logSpy.getCall(2).args).not.to.match(/via:/) | ||
}) | ||
}) | ||
|
||
describe('when --quiet option is not passed', () => { | ||
it ('logs verbose information of the execution', () => { | ||
renderPlan(requestBatches,'env-unit') | ||
|
||
expect(logSpy.called).to.eq(true) | ||
expect(logSpy.getCall(2).args).to.match(/from:/) | ||
expect(logSpy.getCall(2).args).to.match(/to:/) | ||
expect(logSpy.getCall(2).args).to.match(/via:/) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import actionCreators from '../../../../src/lib/migration-steps/action-creators' | ||
import EntryDerive from '../../../../src/lib/interfaces/entry-derive' | ||
import EntryDeriveIntent from '../../../../src/lib/intent/entry-derive' | ||
import runIntent from '../../lib/intent/run-intent' | ||
import fakeCallsite from '../../../helpers/fake-callsite' | ||
import makeApiEntry from '../../../helpers/make-api-entry' | ||
|
||
export default async function renderSetup () { | ||
const step: EntryDerive = { | ||
derivedContentType: 'author', | ||
from: ['authorName', 'authorTwitterHandle'], | ||
toReferenceField: 'author', | ||
derivedFields: ['firstName', 'lastName', 'twitterHandle'], | ||
identityKey: async (fromFields: any) => fromFields.authorTwitterHandle['en-US'], | ||
shouldPublish: true, | ||
deriveEntryForLocale: async (inputFields: any, locale: string) => { | ||
if (locale === 'de-DE') { | ||
return | ||
} | ||
const [firstName, lastName] = inputFields.authorName[locale].split(' ') | ||
const twitterHandle = inputFields.authorTwitterHandle[locale] | ||
|
||
return { | ||
firstName, | ||
lastName, | ||
twitterHandle | ||
} | ||
} | ||
} | ||
const intent: EntryDeriveIntent = actionCreators.contentType.deriveLinkedEntries('entry', 0, step, fakeCallsite()) | ||
|
||
const contentTypes = [{ | ||
name: 'Entry', | ||
sys: { | ||
id: 'entry', | ||
version: 1 | ||
}, | ||
fields: [ | ||
{ | ||
id: 'text', | ||
type: 'Text' | ||
}, { | ||
id: 'authorName', | ||
type: 'Symbol' | ||
}, { | ||
id: 'authorTwitterHandle', | ||
type: 'Symbol' | ||
}, { | ||
id: 'author', | ||
type: 'Link', | ||
linkType: 'Entry' | ||
} | ||
] | ||
}, { | ||
name: 'Author', | ||
sys: { | ||
id: 'author', | ||
version: 1 | ||
}, | ||
fields: [ | ||
{ | ||
id: 'firstName', | ||
type: 'Text' | ||
}, { | ||
id: 'lastName', | ||
type: 'Symbol' | ||
}, { | ||
id: 'twitterHandle', | ||
type: 'Symbol' | ||
} | ||
] | ||
}] | ||
const locales = ['de-DE', 'en-US'] | ||
const entries = [ | ||
makeApiEntry({ | ||
id: 'doge', | ||
contentTypeId: 'entry', | ||
version: 1, | ||
fields: { | ||
text: { | ||
'en-US': 'Such text, wow', | ||
'de-DE': 'Solch Text, wow' | ||
}, | ||
authorName: { | ||
'en-US': 'Author McAuthorface' | ||
}, | ||
authorTwitterHandle: { | ||
'en-US': 'mcauthorface' | ||
} | ||
} | ||
}), | ||
makeApiEntry({ | ||
id: 'clickbait', | ||
contentTypeId: 'entry', | ||
version: 1, | ||
fields: { | ||
text: { | ||
'en-US': 'You won\'t believe what happened next', | ||
'de-DE': 'Du wirst nicht glauben was als nächstes passierte' | ||
}, | ||
authorName: { | ||
'en-US': 'Author McAuthorface' | ||
}, | ||
authorTwitterHandle: { | ||
'en-US': 'mcauthorface' | ||
} | ||
} | ||
}), | ||
makeApiEntry({ | ||
id: 'categorical-imperative', | ||
contentTypeId: 'entry', | ||
version: 1, | ||
fields: { | ||
text: { | ||
'en-US': 'Act only according to that maxim whereby you can, at the same time, will that it should become a universal law', | ||
'de-DE': 'Handle nur nach derjenigen Maxime, durch die du zugleich wollen kannst, dass sie ein allgemeines Gesetz werde' | ||
}, | ||
authorName: { | ||
'en-US': 'Immanuel Kant' | ||
}, | ||
authorTwitterHandle: { | ||
'en-US': 'ikant' | ||
} | ||
} | ||
}) | ||
] | ||
|
||
const api = await runIntent(intent, contentTypes, entries, locales) | ||
return await api.getRequestBatches() | ||
} |