Skip to content

Commit

Permalink
fix(creation): Use createEntry when id is not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaledgarbaya committed Jun 20, 2017
1 parent 879eded commit e9fdfe2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"presets": [
["env", {
"debug": true,
"targets": {
"node": 4.7
"node": "4.7"
}
}]
],
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,5 @@ $RECYCLE.BIN/
*.lnk

# End of https://www.gitignore.io/api/node,windows,osx,linux,vim
yarn.lock
package-lock.json
4 changes: 3 additions & 1 deletion lib/push/creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ function createInDestination (context, sourceEntity) {
function createEntryInDestination (space, contentTypeId, sourceEntity) {
const id = sourceEntity.sys.id
const plainData = getPlainData(sourceEntity)
return space.createEntryWithId(contentTypeId, id, plainData)
return id
? space.createEntryWithId(contentTypeId, id, plainData)
: space.createEntry(contentTypeId, plainData)
}

/**
Expand Down
11 changes: 7 additions & 4 deletions test/push/creation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,23 @@ test('Create entries', (t) => {
setup()
const updateStub = sinon.stub().returns(Promise.resolve({sys: {type: 'Entry'}}))
const space = {
createEntryWithId: sinon.stub().returns(Promise.resolve({sys: {type: 'Entry'}}))
createEntryWithId: sinon.stub().returns(Promise.resolve({sys: {type: 'Entry'}})),
createEntry: sinon.stub().returns(Promise.resolve({sys: {type: 'Entry'}}))
}
const entries = [
{ original: { sys: {contentType: {sys: {id: 'ctid'}}} }, transformed: { sys: {id: '123'} } },
{ original: { sys: {contentType: {sys: {id: 'ctid'}}} }, transformed: { sys: {id: '456'} } }
{ original: { sys: {contentType: {sys: {id: 'ctid'}}} }, transformed: { sys: {id: '456'} } },
{ original: { sys: {contentType: {sys: {id: 'ctid'}}} }, transformed: { sys: {} } }
]
const destinationEntries = [
{sys: {id: '123', version: 6}, update: updateStub}
]
createEntries({space: space, skipContentModel: false}, entries, destinationEntries)
.then((response) => {
t.equals(space.createEntryWithId.callCount, 1, 'create entries')
t.equals(space.createEntryWithId.callCount, 1, 'create entries with the same id')
t.equals(space.createEntry.callCount, 1, 'create entries even when the id is not provided')
t.equals(updateStub.callCount, 1, 'update entries')
t.equals(logMock.info.callCount, 2, 'logs creation of two entries')
t.equals(logMock.info.callCount, 3, 'logs creation of two entries')
teardown()
t.end()
})
Expand Down

0 comments on commit e9fdfe2

Please sign in to comment.