Skip to content

Commit

Permalink
Fix model.mergeDeep tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JaapRood committed May 3, 2018
1 parent fd803ad commit 2db2d3f
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions test/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ Test('model.merge', function(t) {
})

Test('model.mergeDeep', function(t) {
t.plan(3 + 8)
t.plan(2 + 8)

const OtherModel = Model.create({
typeName: 'woo'
Expand All @@ -443,22 +443,21 @@ Test('model.mergeDeep', function(t) {
mergeDeep(existing, value, options) {
t.equal(existing, existingA, 'mergeDeep of type is called with the current value as first argument')
t.equal(value, inputA, 'mergeDeep of type is called with the to be merged value as the second argument')
t.ok(_.isPlainObject(options), 'mergeDeep of type is valled with the options passed to serialize')

return outputA
return existing + value
}
},
nested: {
b: {
mergeDeep: () => outputB
mergeDeep: (existing, value) => existing + value
}
},
multiple: [{
mergeDeep: () => outputC
}],
nestedModel: OtherModel,
notInstance: {
mergeDeep() { return 'never seen' },
mergeDeep: (existing, value) => existing + value,
instanceOf() { return false }
},
notIncluded: {
Expand Down Expand Up @@ -494,7 +493,7 @@ Test('model.mergeDeep', function(t) {
'a': existingA,
'b': existingB
},
notInstance: 'not-what-we-expect-it-to-be',
notInstance: existingA,
notTouched: existingA,

multiple: ['values', 'array'],
Expand All @@ -514,7 +513,7 @@ Test('model.mergeDeep', function(t) {
'a': 'aaa',
'b': 'bbb'
},
notInstance: 'wicked',
notInstance: inputA,
nestedList: [outputA, outputB],
nestedSet: [outputA, outputB],
nestedOrderedSet: [outputC, outputB, outputA]
Expand All @@ -523,7 +522,7 @@ Test('model.mergeDeep', function(t) {
t.equal(merged.get('a'), outputA, 'value returned by mergeDeep of schema is used as value')
t.equal(merged.getIn(['nested', 'b']), outputB, 'nested schema is applied to nested attributes')
t.ok(OtherModel.instanceOf(merged.get('nestedModel')), 'Model definitions are valid type definitions for merging deep')
t.equal(merged.get('notInstance'), existing.get('notInstance'), 'mergeDeep of schema definition not applied when schema has instanceOf method that returns falsey')
t.equal(merged.get('notInstance'), outputA, 'mergeDeep of schema definition is still applied when schema has instanceOf method that returns falsey')

t.ok(Immutable.List([outputA, outputB]).equals(merged.get('nestedList')), 'schema generated with `Schema.listOf` return only the new values as Lists merging is ambiguous')
t.ok(Immutable.Set([outputA, outputB]).equals(merged.get('nestedSet')), 'schema generated with `Schema.setOf` return only then new values as Sets merging is ambiguous')
Expand Down

0 comments on commit 2db2d3f

Please sign in to comment.