Comparing version 2.0.2 to 3.0.0
@@ -6,20 +6,26 @@ | ||
## [2.0.2] - 2018-06-28 | ||
## 3.0.0 - 2019-04-09 | ||
- Removed Bluebird. | ||
- Removed callback support, only promises are supported now. | ||
- Modernised code (although, I didn't go overboard). | ||
## 2.0.2 - 2018-06-28 | ||
- Installed Greenkeeper and updated all dependencies to the latest version. | ||
## [2.0.1] - 2018-06-28 | ||
## 2.0.1 - 2018-06-28 | ||
- You can now supply `keyOnly: false` in conjunction with the `key` option to have the entire object returned, rather than just the key. | ||
## [2.0.0] - 2016-03-29 | ||
## 2.0.0 - 2016-03-29 | ||
- __*Breaking change*__: `changed` and `create` values now return entire objects when working with a `key` rather than just the `key` value. | ||
## [1.0.0] - 2016-03-29 | ||
## 1.0.0 - 2016-03-29 | ||
- First complete version. | ||
## [0.0.1] - 2016-03-25 | ||
## 0.0.1 - 2016-03-25 | ||
- Created first version. Essentially, just a shell. |
127
index.js
var Promise = require('bluebird'), | ||
assert = require('assert'); | ||
const assert = require('assert'); | ||
@@ -11,3 +10,3 @@ /** | ||
*/ | ||
function comparator (objOne, objTwo) { | ||
const comparator = (objOne, objTwo) => { | ||
@@ -39,5 +38,3 @@ // Compare an object to an object. | ||
*/ | ||
function mapToKey (a, key) { | ||
return a.map(val => val[key]); | ||
}; | ||
const mapToKey = (a, key) => a.map(val => val[key]); | ||
@@ -52,21 +49,15 @@ /** | ||
*/ | ||
function findMissingValues (source, update, opts) { | ||
const findMissingValues = (source, update, opts) => source.filter(function (sourceValue) { | ||
var r = source.filter(function (sourceValue) { | ||
return update.find(function (element, index, array) { | ||
return update.find(function (element, index, array) { | ||
// If we have a key, we only want to compare the value of the keys. | ||
return opts.key ? | ||
(opts.comparator || comparator)(sourceValue[opts.key], element[opts.key]) === true : | ||
(opts.comparator || comparator)(sourceValue, element) === true; | ||
// If we have a key, we only want to compare the value of the keys. | ||
return opts.key ? | ||
(opts.comparator || comparator)(sourceValue[opts.key], element[opts.key]) === true : | ||
(opts.comparator || comparator)(sourceValue, element) === true; | ||
}) === undefined; | ||
}) === undefined; | ||
}); | ||
}); | ||
return r; | ||
} | ||
/** | ||
@@ -80,21 +71,15 @@ * Find anything that is new in the `update` array. | ||
*/ | ||
function findNewValues (source, update, opts) { | ||
const findNewValues = (source, update, opts) => update.filter(function (updateValue) { | ||
var r = update.filter(function (updateValue) { | ||
return source.find(function (element, index, array) { | ||
return source.find(function (element, index, array) { | ||
// If we have a key, we don't want to create. | ||
return opts.key ? | ||
(opts.comparator || comparator)(updateValue[opts.key], element[opts.key]) === true : | ||
(opts.comparator || comparator)(updateValue, element) === true; | ||
// If we have a key, we don't want to create. | ||
return opts.key ? | ||
(opts.comparator || comparator)(updateValue[opts.key], element[opts.key]) === true : | ||
(opts.comparator || comparator)(updateValue, element) === true; | ||
}) === undefined; | ||
}) === undefined; | ||
}); | ||
}); | ||
return r; | ||
} | ||
/** | ||
@@ -108,23 +93,17 @@ * Find anything that is exactly the same between the `source` array and the `update` array. | ||
*/ | ||
function findUnchangedValues (source, removeCreateAndChanged, opts) { | ||
const findUnchangedValues = (source, removeCreateAndChanged, opts) => source.filter(function (sourceValue) { | ||
var r = source.filter(function (sourceValue) { | ||
return removeCreateAndChanged.find(function (element, index, array) { | ||
return removeCreateAndChanged.find(function (element, index, array) { | ||
// If we have a key, we only want to compare the actual key is the same. | ||
if (opts.key) { | ||
return (opts.comparator || comparator)(sourceValue[opts.key], element[opts.key]) === true; | ||
} | ||
// If we have a key, we only want to compare the actual key is the same. | ||
if (opts.key) { | ||
return (opts.comparator || comparator)(sourceValue[opts.key], element[opts.key]) === true; | ||
} | ||
return (opts.comparator || comparator)(sourceValue, element) === true; | ||
return (opts.comparator || comparator)(sourceValue, element) === true; | ||
}) === undefined; | ||
}) === undefined; | ||
}); | ||
}); | ||
return r; | ||
} | ||
/** | ||
@@ -138,29 +117,22 @@ * Find anything that has changed between the `source` array and the `update` array. | ||
*/ | ||
function findChangedValues (source, update, opts) { | ||
const findChangedValues = (source, update, opts) => source.filter(function (sourceValue) { | ||
var r = source.filter(function (sourceValue) { | ||
return update.find(function (element, index, array) { | ||
return update.find(function (element, index, array) { | ||
// If we have a key, we only want to compare when the key is the same. | ||
return (opts.comparator || comparator)(sourceValue[opts.key], element[opts.key]) === true && (opts.comparator || comparator)(sourceValue, element, opts.key) !== true; | ||
// If we have a key, we only want to compare when the key is the same. | ||
return (opts.comparator || comparator)(sourceValue[opts.key], element[opts.key]) === true && (opts.comparator || comparator)(sourceValue, element, opts.key) !== true; | ||
}) !== undefined; | ||
}) !== undefined; | ||
// We always have a key if this function is executing, make sure we pass back the changed values, not those from the source. | ||
}).map(function (sourceValue) { | ||
// We always have a key if this function is executing, make sure we pass back the changed values, not those from the source. | ||
}).map(function (sourceValue) { | ||
return update.find(function (element, index, array) { | ||
return update.find(function (element, index, array) { | ||
return (opts.comparator || comparator)(sourceValue[opts.key], element[opts.key]) === true; | ||
return (opts.comparator || comparator)(sourceValue[opts.key], element[opts.key]) === true; | ||
}); | ||
}); | ||
}) | ||
return r; | ||
} | ||
/** | ||
@@ -171,8 +143,7 @@ * Data synchronisation module for Node.js. | ||
* @param {Array} update An updated version of the source array. | ||
* @param {Function} callback An optional callback to execute with the results. | ||
* @param {Object} opts An object of options. | ||
* @return {Promise} A promise that will be resolved or rejected with the result (unless callback was provided). | ||
* @return {Promise} A promise that will be resolved or rejected with the result. | ||
*/ | ||
module.exports = function arraySync (source, update, opts, callback) { | ||
module.exports = function arraySync (source, update, opts = {}) { | ||
@@ -187,15 +158,2 @@ if (!source) { | ||
// Support four signatures: | ||
// 1. (source, update, callback) | ||
// 2. (source, update, opts, callback) | ||
// 3, (source, update, opts) | ||
// 4. (source, update) | ||
if (typeof opts === 'function') { | ||
callback = opts; | ||
opts = {}; | ||
} | ||
// Default `opts` to an Object. | ||
opts = opts || {}; | ||
if (opts.comparator && !opts.key) { | ||
@@ -209,7 +167,6 @@ throw Error('You must provide a key when passing in a custom comparator function.') | ||
// Return a promise (which will execute the callback if provided). | ||
return new Promise(function (resolve, reject) { | ||
// Default return object. | ||
var r = { | ||
const r = { | ||
remove: [], | ||
@@ -243,4 +200,4 @@ unchanged: [], | ||
}).asCallback(callback); | ||
}); | ||
} |
{ | ||
"name": "array-sync", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"description": "Data synchronisation module for Node.js", | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">= 4.0" | ||
"node": ">= 6.0" | ||
}, | ||
@@ -33,9 +33,6 @@ "scripts": { | ||
"chai-as-promised": "7.1.1", | ||
"clone": "2.1.1", | ||
"clone": "2.1.2", | ||
"istanbul": "0.4.5", | ||
"mocha": "5.2.0" | ||
}, | ||
"dependencies": { | ||
"bluebird": "3.5.1" | ||
"mocha": "6.1.2" | ||
} | ||
} |
@@ -24,3 +24,3 @@ # array-sync | ||
### arraySync(source, updated, [options, callback]) | ||
### arraySync(source, updated, [options]) | ||
@@ -39,3 +39,3 @@ Takes a source array, and compares it against an updated version of the source array to determine what needs to be removed, created and what hasn't changed. It returns an object: | ||
array-sync will return a promise unless a `callback` function has been provided. | ||
array-sync will always return a promise. | ||
@@ -50,16 +50,2 @@ #### source | ||
#### callback | ||
An optional `callback` function. If provided will be executed with the standard Node.js callback signature `(err, result)`. If not provided a promise is returned. | ||
``` | ||
arraySync(source, updated).then( | ||
function successHandler (result) { | ||
// { remove: [], unchanged: [], create: [] } | ||
}, | ||
function failHandler (err) { | ||
} | ||
); | ||
``` | ||
#### options | ||
@@ -82,11 +68,12 @@ | ||
{ type: 'node', id: 3, label: 'three' } | ||
]).then(function (result) { | ||
]) | ||
.then(function (result) { | ||
// result = { | ||
// unchanged: [{ type: 'node', id: 1, label: 'one' }, { type: 'node', id: 3, label: 'three' }], | ||
// create: [{ type: 'node', id: 2, label: 'Two' }], | ||
// remove: [{ type: 'node', id: 2, label: 'two' }] | ||
// } | ||
// result = { | ||
// unchanged: [{ type: 'node', id: 1, label: 'one' }, { type: 'node', id: 3, label: 'three' }], | ||
// create: [{ type: 'node', id: 2, label: 'Two' }], | ||
// remove: [{ type: 'node', id: 2, label: 'two' }] | ||
// } | ||
}); | ||
}); | ||
``` | ||
@@ -105,12 +92,13 @@ | ||
{ type: 'node', id: 3, label: 'three' } | ||
], { key: 'id' }).then(function (result) { | ||
], { key: 'id' }) | ||
.then(function (result) { | ||
// result = { | ||
// unchanged: [1, 3], | ||
// changed: [{ type: 'node', id: 2, label: 'Two' }] | ||
// create: [], | ||
// remove: [] | ||
// } | ||
// result = { | ||
// unchanged: [1, 3], | ||
// changed: [{ type: 'node', id: 2, label: 'Two' }] | ||
// create: [], | ||
// remove: [] | ||
// } | ||
}); | ||
}); | ||
``` | ||
@@ -117,0 +105,0 @@ |
435
test/test.js
@@ -0,5 +1,6 @@ | ||
'use strict'; | ||
var expect = require('chai').expect, | ||
clone = require('clone'), | ||
arraySync = require('../'); | ||
const arraySync = require('../'); | ||
const clone = require('clone'); | ||
const expect = require('chai').expect; | ||
@@ -10,4 +11,4 @@ describe('arraySync', function () { | ||
var fn = function () { | ||
var middleware = arraySync(); // eslint-disable-line no-unused-vars | ||
const fn = function () { | ||
const middleware = arraySync(); // eslint-disable-line no-unused-vars | ||
}; | ||
@@ -21,4 +22,4 @@ | ||
var fn = function () { | ||
var middleware = arraySync([]); // eslint-disable-line no-unused-vars | ||
const fn = function () { | ||
const middleware = arraySync([]); // eslint-disable-line no-unused-vars | ||
}; | ||
@@ -32,4 +33,4 @@ | ||
var fn = function () { | ||
var middleware = arraySync([], [], { comparator: function () {} }); // eslint-disable-line no-unused-vars | ||
const fn = function () { | ||
const middleware = arraySync([], [], { comparator: function () {} }); // eslint-disable-line no-unused-vars | ||
}; | ||
@@ -41,24 +42,7 @@ | ||
it('can accept an opts Object', function (done) { | ||
it('can accept an opts Object', function () { | ||
arraySync([], [], {}, function (err, results) { | ||
return arraySync([], [], {}) | ||
.then(function (results) { | ||
expect(err).to.not.exist; | ||
expect(results).to.have.property('remove'); | ||
expect(results).to.have.property('unchanged'); | ||
expect(results).to.have.property('create'); | ||
expect(results).to.not.have.property('changed'); | ||
return done(err); | ||
}); | ||
}); | ||
describe('via promise', function () { | ||
it('will resolve to an object with the keys remove, unchanged, create', function (done) { | ||
arraySync([], []).then(function (results) { | ||
expect(results).to.exist; | ||
@@ -70,21 +54,12 @@ expect(results).to.have.property('remove'); | ||
return done(); | ||
}, function (err) { | ||
return done(err); | ||
}); | ||
}); | ||
}); | ||
describe('via callback', function () { | ||
it('will resolve to an object with the keys remove, unchanged, create', function () { | ||
it('returns an object with the keys remove, unchanged, create', function (done) { | ||
return arraySync([], []) | ||
.then(function (results) { | ||
arraySync([], [], function (err, results) { | ||
expect(err).to.not.exist; | ||
expect(results).to.exist; | ||
expect(results).to.have.property('remove'); | ||
@@ -95,8 +70,25 @@ expect(results).to.have.property('unchanged'); | ||
return done(err); | ||
}); | ||
}); | ||
}); | ||
it('will reject upon error', function () { | ||
return arraySync([ | ||
{ type: 'fruit', _id: 1, label: 'Apple', stats: { views: 1, purchases: 1 } }, | ||
{ type: 'fruit', _id: 2, label: 'Cucumber', stats: { views: 10, purchases: 2 } } | ||
], [ | ||
{ type: 'fruit', _id: 1, label: 'Apple', stats: { views: 20, purchases: 2 } }, | ||
{ type: 'vegetable', _id: 2, label: 'Cucumber', stats: {views: 20, purchases: 5 } } | ||
], { | ||
key: '_id', | ||
comparator: function comparator (objOne, objTwo) { | ||
throw new Error('Test error'); | ||
} | ||
}) | ||
.then( | ||
() => Promise.reject(new Error('Exepcted arraySync to reject.')), | ||
(err) => expect(err).to.be.an.instanceof(Error) | ||
); | ||
}); | ||
@@ -110,5 +102,5 @@ | ||
it('when working with strings', function (done) { | ||
it('when working with strings', function () { | ||
arraySync(['one', 'two', 'three', 'four'], ['one', 'three', 'four']).then(function (result) { | ||
return arraySync(['one', 'two', 'three', 'four'], ['one', 'three', 'four']).then(function (result) { | ||
@@ -124,8 +116,2 @@ expect(result).to.exist; | ||
return done(); | ||
}, function (err) { | ||
return done(err); | ||
}); | ||
@@ -135,5 +121,5 @@ | ||
it('when working with objects', function (done) { | ||
it('when working with objects', function () { | ||
arraySync([ | ||
return arraySync([ | ||
{ type: 'node', label: 'one' }, | ||
@@ -156,8 +142,2 @@ { type: 'node', label: 'two' }, | ||
return done(); | ||
}, function (err) { | ||
return done(err); | ||
}); | ||
@@ -171,5 +151,5 @@ | ||
it('when working with strings', function (done) { | ||
it('when working with strings', function () { | ||
arraySync(['one', 'two', 'three', 'four'], ['one', 'two', 'three', 'four', 'five']).then(function (result) { | ||
return arraySync(['one', 'two', 'three', 'four'], ['one', 'two', 'three', 'four', 'five']).then(function (result) { | ||
@@ -185,8 +165,2 @@ expect(result).to.exist; | ||
return done(); | ||
}, function (err) { | ||
return done(err); | ||
}); | ||
@@ -196,5 +170,5 @@ | ||
it('when working with objects', function (done) { | ||
it('when working with objects', function () { | ||
arraySync([ | ||
return arraySync([ | ||
{ type: 'node', label: 'one' }, | ||
@@ -217,8 +191,2 @@ { type: 'node', label: 'two' } | ||
return done(); | ||
}, function (err) { | ||
return done(err); | ||
}); | ||
@@ -232,5 +200,5 @@ | ||
it('when working with strings', function (done) { | ||
it('when working with strings', function () { | ||
arraySync(['one', 'two', 'three', 'four'], ['one', 'two', 'three', 'four', 'five']).then(function (result) { | ||
return arraySync(['one', 'two', 'three', 'four'], ['one', 'two', 'three', 'four', 'five']).then(function (result) { | ||
@@ -249,8 +217,2 @@ expect(result).to.exist; | ||
return done(); | ||
}, function (err) { | ||
return done(err); | ||
}); | ||
@@ -260,5 +222,5 @@ | ||
it('when working with objects', function (done) { | ||
it('when working with objects', function () { | ||
arraySync([ | ||
return arraySync([ | ||
{ type: 'node', label: 'one' }, | ||
@@ -282,8 +244,2 @@ { type: 'node', label: 'two' } | ||
return done(); | ||
}, function (err) { | ||
return done(err); | ||
}); | ||
@@ -297,5 +253,5 @@ | ||
it('when working with strings', function (done) { | ||
it('when working with strings', function () { | ||
arraySync(['one', 'two', 'three', 'four'], ['one', 'three', 'four', 'five']).then(function (result) { | ||
return arraySync(['one', 'two', 'three', 'four'], ['one', 'three', 'four', 'five']).then(function (result) { | ||
@@ -319,8 +275,2 @@ expect(result).to.exist; | ||
return done(); | ||
}, function (err) { | ||
return done(err); | ||
}); | ||
@@ -330,5 +280,5 @@ | ||
it('when working with objects', function (done) { | ||
it('when working with objects', function () { | ||
arraySync([ | ||
return arraySync([ | ||
{ type: 'node', label: 'one' }, | ||
@@ -362,8 +312,2 @@ { type: 'node', label: 'two' }, | ||
return done(); | ||
}, function (err) { | ||
return done(err); | ||
}); | ||
@@ -379,5 +323,5 @@ | ||
it('and determine which items are unchanged, to be removed and to be created', function (done) { | ||
it('and determine which items are unchanged, to be removed and to be created', function () { | ||
arraySync([ | ||
return arraySync([ | ||
{ type: 'fruit', _id: 'one', label: 'Apple' }, | ||
@@ -396,36 +340,32 @@ { type: 'fruit', _id: 'two', label: 'Orange' }, | ||
key: '_id' | ||
}, function (err, result) { | ||
}) | ||
.then(function (result) { | ||
expect(err).to.not.exist; | ||
expect(result).to.exist; | ||
expect(result).to.exist; | ||
expect(result).to.have.property('unchanged'); | ||
expect(result.unchanged).to.have.length(3); | ||
expect(result.unchanged[0]).to.eql('one'); | ||
expect(result.unchanged[1]).to.eql('two'); | ||
expect(result.unchanged[2]).to.eql('three'); | ||
expect(result).to.have.property('unchanged'); | ||
expect(result.unchanged).to.have.length(3); | ||
expect(result.unchanged[0]).to.eql('one'); | ||
expect(result.unchanged[1]).to.eql('two'); | ||
expect(result.unchanged[2]).to.eql('three'); | ||
expect(result).to.have.property('create'); | ||
expect(result.create).to.have.length(1); | ||
expect(result.create[0]).to.eql({ type: 'vegetable', _id: 'six', label: 'Pumpkin' }); | ||
expect(result).to.have.property('create'); | ||
expect(result.create).to.have.length(1); | ||
expect(result.create[0]).to.eql({ type: 'vegetable', _id: 'six', label: 'Pumpkin' }); | ||
expect(result).to.have.property('remove'); | ||
expect(result.remove).to.have.length(1); | ||
expect(result.remove[0]).to.eql('five'); | ||
expect(result).to.have.property('remove'); | ||
expect(result.remove).to.have.length(1); | ||
expect(result.remove[0]).to.eql('five'); | ||
expect(result).to.have.property('changed'); | ||
expect(result.changed).to.have.length(1); | ||
expect(result.changed[0]).to.eql({ type: 'vegetable', _id: 'four', label: 'Cucumber' }); | ||
expect(result).to.have.property('changed'); | ||
expect(result.changed).to.have.length(1); | ||
expect(result.changed[0]).to.eql({ type: 'vegetable', _id: 'four', label: 'Cucumber' }); | ||
}); | ||
return done(err); | ||
}); | ||
}); | ||
it('and return complete objects', function () { | ||
it('and return complete objects', function (done) { | ||
arraySync([ | ||
return arraySync([ | ||
{ type: 'fruit', _id: 'one', label: 'Apple' }, | ||
@@ -445,31 +385,27 @@ { type: 'fruit', _id: 'two', label: 'Orange' }, | ||
keyOnly: false, | ||
}, function (err, result) { | ||
}) | ||
.then(function (result) { | ||
expect(err).to.not.exist; | ||
expect(result).to.exist; | ||
expect(result).to.exist; | ||
expect(result).to.have.property('unchanged'); | ||
expect(result.unchanged).to.have.length(3); | ||
expect(result.unchanged[0]).to.eql({ type: 'fruit', _id: 'one', label: 'Apple' }); | ||
expect(result.unchanged[1]).to.eql({ type: 'fruit', _id: 'two', label: 'Orange' }); | ||
expect(result.unchanged[2]).to.eql({ type: 'fruit', _id: 'three', label: 'Grape' }); | ||
expect(result).to.have.property('unchanged'); | ||
expect(result.unchanged).to.have.length(3); | ||
expect(result.unchanged[0]).to.eql({ type: 'fruit', _id: 'one', label: 'Apple' }); | ||
expect(result.unchanged[1]).to.eql({ type: 'fruit', _id: 'two', label: 'Orange' }); | ||
expect(result.unchanged[2]).to.eql({ type: 'fruit', _id: 'three', label: 'Grape' }); | ||
expect(result).to.have.property('create'); | ||
expect(result.create).to.have.length(1); | ||
expect(result.create[0]).to.eql({ type: 'vegetable', _id: 'six', label: 'Pumpkin' }); | ||
expect(result).to.have.property('create'); | ||
expect(result.create).to.have.length(1); | ||
expect(result.create[0]).to.eql({ type: 'vegetable', _id: 'six', label: 'Pumpkin' }); | ||
expect(result).to.have.property('remove'); | ||
expect(result.remove).to.have.length(1); | ||
expect(result.remove[0]).to.eql({ type: 'fruit', _id: 'five', label: 'Plum' }); | ||
expect(result).to.have.property('remove'); | ||
expect(result.remove).to.have.length(1); | ||
expect(result.remove[0]).to.eql({ type: 'fruit', _id: 'five', label: 'Plum' }); | ||
expect(result).to.have.property('changed'); | ||
expect(result.changed).to.have.length(1); | ||
expect(result.changed[0]).to.eql({ type: 'vegetable', _id: 'four', label: 'Cucumber' }); | ||
expect(result).to.have.property('changed'); | ||
expect(result.changed).to.have.length(1); | ||
expect(result.changed[0]).to.eql({ type: 'vegetable', _id: 'four', label: 'Cucumber' }); | ||
}); | ||
return done(err); | ||
}); | ||
}); | ||
@@ -481,7 +417,7 @@ | ||
it('and determine which items are unchanged, to be removed and to be created', function (done) { | ||
it('and determine which items are unchanged, to be removed and to be created', function () { | ||
var called = false; | ||
let called = false; | ||
arraySync([ | ||
return arraySync([ | ||
{ type: 'fruit', _id: 1, label: 'Apple', stats: { views: 1, purchases: 1 } }, | ||
@@ -501,4 +437,4 @@ { type: 'fruit', _id: 2, label: 'Cucumber', stats: { views: 10, purchases: 2 } } | ||
var oOne = clone(objOne), | ||
oTwo = clone(objTwo); | ||
const oOne = clone(objOne); | ||
const oTwo = clone(objTwo); | ||
@@ -523,28 +459,25 @@ // delete keys we don't want to compare | ||
} | ||
}, function (err, result) { | ||
}) | ||
.then(function (result) { | ||
expect(err).to.not.exist; | ||
expect(result).to.exist; | ||
expect(result).to.exist; | ||
expect(result).to.have.property('unchanged'); | ||
expect(result.unchanged).to.have.length(1); | ||
expect(result.unchanged[0]).to.eql(1); | ||
expect(result).to.have.property('unchanged'); | ||
expect(result.unchanged).to.have.length(1); | ||
expect(result.unchanged[0]).to.eql(1); | ||
expect(result).to.have.property('create'); | ||
expect(result.create).to.have.length(0); | ||
expect(result).to.have.property('create'); | ||
expect(result.create).to.have.length(0); | ||
expect(result).to.have.property('remove'); | ||
expect(result.remove).to.have.length(0); | ||
expect(result).to.have.property('remove'); | ||
expect(result.remove).to.have.length(0); | ||
expect(result).to.have.property('changed'); | ||
expect(result.changed).to.have.length(1); | ||
expect(result.changed[0]).to.eql({ type: 'vegetable', _id: 2, label: 'Cucumber', stats: {views: 20, purchases: 5 } }); | ||
expect(result).to.have.property('changed'); | ||
expect(result.changed).to.have.length(1); | ||
expect(result.changed[0]).to.eql({ type: 'vegetable', _id: 2, label: 'Cucumber', stats: {views: 20, purchases: 5 } }); | ||
expect(called).to.equal(true); | ||
expect(called).to.equal(true); | ||
}); | ||
return done(err); | ||
}); | ||
}); | ||
@@ -556,33 +489,30 @@ | ||
it('numbers', function (done) { | ||
it('numbers', function () { | ||
arraySync([1, 2, 3, 4], [1, 3, 4, 5], function (err, result) { | ||
return arraySync([1, 2, 3, 4], [1, 3, 4, 5]) | ||
.then(function (result) { | ||
expect(err).to.not.exist; | ||
expect(result).to.exist; | ||
expect(result).to.exist; | ||
expect(result).to.have.property('unchanged'); | ||
expect(result.unchanged).to.have.length(3); | ||
expect(result.unchanged[0]).to.eql(1); | ||
expect(result.unchanged[1]).to.eql(3); | ||
expect(result.unchanged[2]).to.eql(4); | ||
expect(result).to.have.property('unchanged'); | ||
expect(result.unchanged).to.have.length(3); | ||
expect(result.unchanged[0]).to.eql(1); | ||
expect(result.unchanged[1]).to.eql(3); | ||
expect(result.unchanged[2]).to.eql(4); | ||
expect(result).to.have.property('create'); | ||
expect(result.create).to.have.length(1); | ||
expect(result.create[0]).to.eql(5); | ||
expect(result).to.have.property('create'); | ||
expect(result.create).to.have.length(1); | ||
expect(result.create[0]).to.eql(5); | ||
expect(result).to.have.property('remove'); | ||
expect(result.remove).to.have.length(1); | ||
expect(result.remove[0]).to.eql(2); | ||
expect(result).to.have.property('remove'); | ||
expect(result.remove).to.have.length(1); | ||
expect(result.remove[0]).to.eql(2); | ||
}); | ||
return done(err); | ||
}); | ||
}); | ||
it('arrays', function (done) { | ||
it('arrays', function () { | ||
arraySync([ | ||
return arraySync([ | ||
['a', 'b', 'c'], | ||
@@ -596,31 +526,28 @@ ['one', 'two', 'three'], | ||
['orange', 'apple', 'pear'] | ||
], function (err, result) { | ||
]) | ||
.then(function (result) { | ||
expect(err).to.not.exist; | ||
expect(result).to.exist; | ||
expect(result).to.exist; | ||
expect(result).to.have.property('unchanged'); | ||
expect(result.unchanged).to.have.length(2); | ||
expect(result.unchanged[0]).to.eql(['one', 'two', 'three']); | ||
expect(result.unchanged[1]).to.eql(['orange', 'apple', 'pear']); | ||
expect(result).to.have.property('unchanged'); | ||
expect(result.unchanged).to.have.length(2); | ||
expect(result.unchanged[0]).to.eql(['one', 'two', 'three']); | ||
expect(result.unchanged[1]).to.eql(['orange', 'apple', 'pear']); | ||
expect(result).to.have.property('create'); | ||
expect(result.create).to.have.length(1); | ||
expect(result.create[0]).to.eql(['letter-a', 'letter-b', 'letter-c']); | ||
expect(result).to.have.property('create'); | ||
expect(result.create).to.have.length(1); | ||
expect(result.create[0]).to.eql(['letter-a', 'letter-b', 'letter-c']); | ||
expect(result).to.have.property('remove'); | ||
expect(result.remove).to.have.length(2); | ||
expect(result.remove[0]).to.eql(['a', 'b', 'c']); | ||
expect(result.remove[1]).to.eql(['cat', 'mouse', 'dog']); | ||
expect(result).to.have.property('remove'); | ||
expect(result.remove).to.have.length(2); | ||
expect(result.remove[0]).to.eql(['a', 'b', 'c']); | ||
expect(result.remove[1]).to.eql(['cat', 'mouse', 'dog']); | ||
}); | ||
return done(err); | ||
}); | ||
}); | ||
it('objects', function (done) { | ||
it('objects', function () { | ||
arraySync([ | ||
return arraySync([ | ||
{ type: 'fruit', _id: 1, label: 'Apple' }, | ||
@@ -631,31 +558,28 @@ { type: 'fruit', _id: 2, label: 'Cucumber' } | ||
{ type: 'vegetable', _id: 2, label: 'Cucumber' } | ||
], function (err, result) { | ||
]) | ||
.then(function (result) { | ||
expect(err).to.not.exist; | ||
expect(result).to.exist; | ||
expect(result).to.exist; | ||
expect(result).to.have.property('unchanged'); | ||
expect(result.unchanged).to.have.length(1); | ||
expect(result.unchanged[0]).to.eql({ type: 'fruit', _id: 1, label: 'Apple' }); | ||
expect(result).to.have.property('unchanged'); | ||
expect(result.unchanged).to.have.length(1); | ||
expect(result.unchanged[0]).to.eql({ type: 'fruit', _id: 1, label: 'Apple' }); | ||
expect(result).to.have.property('create'); | ||
expect(result.create).to.have.length(1); | ||
expect(result.create[0]).to.eql({ type: 'vegetable', _id: 2, label: 'Cucumber' }); | ||
expect(result).to.have.property('create'); | ||
expect(result.create).to.have.length(1); | ||
expect(result.create[0]).to.eql({ type: 'vegetable', _id: 2, label: 'Cucumber' }); | ||
expect(result).to.have.property('remove'); | ||
expect(result.remove).to.have.length(1); | ||
expect(result.remove[0]).to.eql({ type: 'fruit', _id: 2, label: 'Cucumber' }); | ||
expect(result).to.have.property('remove'); | ||
expect(result.remove).to.have.length(1); | ||
expect(result.remove[0]).to.eql({ type: 'fruit', _id: 2, label: 'Cucumber' }); | ||
expect(result).to.not.have.property('changed'); | ||
expect(result).to.not.have.property('changed'); | ||
}); | ||
return done(err); | ||
}); | ||
}); | ||
it('strings', function (done) { | ||
it('strings', function () { | ||
arraySync([ | ||
return arraySync([ | ||
'Apple', | ||
@@ -666,26 +590,23 @@ 'Cucumber' | ||
'Pear' | ||
], function (err, result) { | ||
]) | ||
.then(function (result) { | ||
expect(err).to.not.exist; | ||
expect(result).to.exist; | ||
expect(result).to.exist; | ||
expect(result).to.have.property('unchanged'); | ||
expect(result.unchanged).to.have.length(1); | ||
expect(result.unchanged[0]).to.eql('Apple'); | ||
expect(result).to.have.property('unchanged'); | ||
expect(result.unchanged).to.have.length(1); | ||
expect(result.unchanged[0]).to.eql('Apple'); | ||
expect(result).to.have.property('create'); | ||
expect(result.create).to.have.length(1); | ||
expect(result.create[0]).to.eql('Pear'); | ||
expect(result).to.have.property('create'); | ||
expect(result.create).to.have.length(1); | ||
expect(result.create[0]).to.eql('Pear'); | ||
expect(result).to.have.property('remove'); | ||
expect(result.remove).to.have.length(1); | ||
expect(result.remove[0]).to.eql('Cucumber'); | ||
expect(result).to.have.property('remove'); | ||
expect(result.remove).to.have.length(1); | ||
expect(result.remove[0]).to.eql('Cucumber'); | ||
expect(result).to.not.have.property('changed'); | ||
expect(result).to.not.have.property('changed'); | ||
}); | ||
return done(err); | ||
}); | ||
}); | ||
@@ -692,0 +613,0 @@ |
Sorry, the diff of this file is not supported yet
0
41520
13
559
151
- Removedbluebird@3.5.1
- Removedbluebird@3.5.1(transitive)