diff --git a/src/apps.js b/src/apps.js index 362eee45b..820ea0087 100644 --- a/src/apps.js +++ b/src/apps.js @@ -2468,7 +2468,7 @@ async function clone(app, data, user, auditSource) { }; const taskId = await addTask(newAppId, exports.ISTATE_PENDING_CLONE, task, auditSource); - const newApp = Object.assign({}, _.omit(obj, 'icon'), { appStoreId, manifest, subdomain, domain, portBindings }); + const newApp = Object.assign({}, _.omit(obj, ['icon']), { appStoreId, manifest, subdomain, domain, portBindings }); newApp.fqdn = dns.fqdn(newApp.subdomain, newApp.domain); newApp.secondaryDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, ad.domain); }); newApp.redirectDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, ad.domain); }); @@ -2545,7 +2545,7 @@ async function unarchive(archive, data, auditSource) { const taskId = await addTask(appId, obj.installationState, task, auditSource); - const newApp = Object.assign({}, _.omit(obj, 'icon'), { appStoreId, manifest, subdomain, domain, portBindings }); + const newApp = Object.assign({}, _.omit(obj, ['icon']), { appStoreId, manifest, subdomain, domain, portBindings }); newApp.fqdn = dns.fqdn(newApp.subdomain, newApp.domain); newApp.secondaryDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, ad.domain); }); newApp.redirectDomains.forEach(function (ad) { ad.fqdn = dns.fqdn(ad.subdomain, ad.domain); }); diff --git a/src/test/underscore-test.js b/src/test/underscore-test.js new file mode 100644 index 000000000..373cabb87 --- /dev/null +++ b/src/test/underscore-test.js @@ -0,0 +1,51 @@ +'use strict'; + +/* global it, describe, before, after */ + +const expect = require('expect.js'), + _ = require('../underscore.js'); + +describe('Underscore', function () { + it('pick', function () { + expect(_.pick({ x: 1, y: 2 }, ['x'])).to.eql({x: 1}); + expect(_.pick({ x: 1, y: 2 }, ['x', 'y', 'z'])).to.eql({x: 1, y:2}); + expect(_.pick({ x: 1, y: 2 }, ['z'])).to.eql({}); + expect(_.pick({ x: 1, y: 2 }, [])).to.eql({}); + }); + + it('omit', function () { + expect(_.omit({ x: 1, y: 2 }, ['x'])).to.eql({ y: 2 }); + expect(_.omit({ x: 1, y: 2 }, ['x', 'y', 'z'])).to.eql({}); + expect(_.omit({ x: 1, y: 2 }, ['z'])).to.eql({ x: 1, y: 2 }); + expect(_.omit({ x: 1, y: 2 }, [])).to.eql({ x: 1, y: 2 }); + }); + + it('intersection', function () { + expect(_.intersection([], [2,3])).to.eql([]); + expect(_.intersection([1,2], [2,3])).to.eql([2]); + expect(_.intersection([1,2], [3])).to.eql([]); + expect(_.intersection([1,2], [1,2])).to.eql([1,2]); + }); + + it('isEqual', function () { + expect(_.isEqual(null, null)).to.be(true); + + expect(_.isEqual(1, 1)).to.be(true); + expect(_.isEqual(1, 2)).to.be(false); + + expect(_.isEqual([], [])).to.be(true); + expect(_.isEqual([2,3,4], [3,4,2])).to.be(false); + + expect(_.isEqual({x:1}, {y:2})).to.be(false); + expect(_.isEqual({x:1}, {x:1})).to.be(true); + expect(_.isEqual({x:1,z:2}, {z:1,x:1})).to.be(false); + expect(_.isEqual({x:1,y:3,z:2}, {y:3,z:2,x:1})).to.be(true); + }); + + it('difference', function () { + expect(_.difference([1,2], [2,3])).to.eql([1]); + expect(_.difference([1,2], [3])).to.eql([1,2]); + expect(_.difference([1,2], [1,2])).to.eql([]); + expect(_.difference([], [1,2])).to.eql([]); + }); +}); diff --git a/src/underscore.js b/src/underscore.js index e857ae378..465071fd2 100644 --- a/src/underscore.js +++ b/src/underscore.js @@ -8,6 +8,7 @@ exports = module.exports = { difference }; +// IMPORTANT: this file is required from the migration logic. avoid requires const assert = require('assert'); function pick(obj, keys) {