Skip to content

Commit

Permalink
Remove polyfill for Object.assign
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregoire Weber committed Mar 23, 2017
1 parent ac555a5 commit 7f71719
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 80 deletions.
8 changes: 4 additions & 4 deletions src/clientHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module.exports = {
var result = {};
Object.keys(serverResponse).forEach(function (key) {
result[key] = serverResponse[key].map(function (item) {
return Object.assign({}, item, {
package: item.component,
component: undefined
});
var result = item;
result.package = item.component;
delete result.component;
return result;
});
});
return result;
Expand Down
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict';

var ERROR_REQUEST_FAILED = 'REQUEST_FAILED';
var ERROR_DOWNLOAD_FAILED = 'ERROR_DOWNLOAD_FAILED';
var ERROR_DOWNLOAD_FAILED = 'DOWNLOAD_FAILED';
var ERROR_UNEXPECTED_SERVER_RESPONSE = 'UNEXPECTED_SERVER_RESPONSE';

var DEFAULT_BARRACKS_BASE_URL = 'https://app.barracks.io';
var CHECK_UPDATE_ENDPOINT = '/api/device/v2/update/check';

require('./polyfill');
var fs = require('fs');
var request = require('request');
var clientHelper = require('./clientHelper');
Expand Down
26 changes: 0 additions & 26 deletions src/polyfill.js

This file was deleted.

86 changes: 38 additions & 48 deletions tests/clientHelper_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ describe('buildCheckUpdateResult : ', function () {
expect(result.changed).to.be.an('array').and.to.have.lengthOf(0);
expect(result.unchanged).to.be.an('array').and.to.have.lengthOf(0);
expect(result.unavailable).to.be.an('array').and.to.have.lengthOf(0);
expect(result.available[0]).to.deep.equals(
Object.assign({}, component, {
package: component.component,
component: undefined
})
);
expect(result.available[0]).to.deep.equals({
package: 'abc.edf',
version: '0.0.1',
url: 'https://dtc.io/',
size: 42,
md5: 'deadbeefbadc0ffee'
});
});

it('Should correctly map packages in the changed section', function () {
Expand Down Expand Up @@ -65,12 +66,13 @@ describe('buildCheckUpdateResult : ', function () {
expect(result.changed).to.be.an('array').and.to.have.lengthOf(1);
expect(result.unchanged).to.be.an('array').and.to.have.lengthOf(0);
expect(result.unavailable).to.be.an('array').and.to.have.lengthOf(0);
expect(result.changed[0]).to.deep.equals(
Object.assign({}, component, {
package: component.component,
component: undefined
})
);
expect(result.changed[0]).to.deep.equals({
package: 'abc.edf',
version: '0.0.1',
url: 'https://dtc.io/',
size: 42,
md5: 'deadbeefbadc0ffee'
});
});

it('Should correctly map packages in the unchanged section', function () {
Expand All @@ -95,12 +97,10 @@ describe('buildCheckUpdateResult : ', function () {
expect(result.changed).to.be.an('array').and.to.have.lengthOf(0);
expect(result.unchanged).to.be.an('array').and.to.have.lengthOf(1);
expect(result.unavailable).to.be.an('array').and.to.have.lengthOf(0);
expect(result.unchanged[0]).to.deep.equals(
Object.assign({}, component, {
package: component.component,
component: undefined
})
);
expect(result.unchanged[0]).to.deep.equals({
package: 'abc.edf',
version: '0.0.1'
});
});

it('Should correctly map packages in the unavailable section', function () {
Expand All @@ -122,12 +122,7 @@ describe('buildCheckUpdateResult : ', function () {
expect(result.changed).to.be.an('array').and.to.have.lengthOf(0);
expect(result.unchanged).to.be.an('array').and.to.have.lengthOf(0);
expect(result.unavailable).to.be.an('array').and.to.have.lengthOf(1);
expect(result.unavailable[0]).to.deep.equals(
Object.assign({}, component, {
package: component.component,
component: undefined
})
);
expect(result.unavailable[0]).to.deep.equals({ package: 'abc.edf' });
});

it('Should correctly map packages in all sections', function () {
Expand Down Expand Up @@ -167,29 +162,24 @@ describe('buildCheckUpdateResult : ', function () {
expect(result.changed).to.be.an('array').and.to.have.lengthOf(1);
expect(result.unchanged).to.be.an('array').and.to.have.lengthOf(1);
expect(result.unavailable).to.be.an('array').and.to.have.lengthOf(1);
expect(result.available[0]).to.deep.equals(
Object.assign({}, availableComponent, {
package: availableComponent.component,
component: undefined
})
);
expect(result.changed[0]).to.deep.equals(
Object.assign({}, changedComponent, {
package: changedComponent.component,
component: undefined
})
);
expect(result.unchanged[0]).to.deep.equals(
Object.assign({}, unchangedComponent, {
package: unchangedComponent.component,
component: undefined
})
);
expect(result.unavailable[0]).to.deep.equals(
Object.assign({}, unavailableComponent, {
package: unavailableComponent.component,
component: undefined
})
);
expect(result.available[0]).to.deep.equals({
package: 'abc.edf',
version: '0.0.1',
url: 'https://dtc.io/',
size: 42,
md5: 'deadbeefbadc0ffee'
});
expect(result.changed[0]).to.deep.equals({
package: 'abc.edf',
version: '0.0.1',
url: 'https://dtc.io/',
size: 42,
md5: 'deadbeefbadc0ffee'
});
expect(result.unchanged[0]).to.deep.equals({
package: 'abc.edf',
version: '0.0.1'
});
expect(result.unavailable[0]).to.deep.equals({ package: 'abc.edf' });
});
});

0 comments on commit 7f71719

Please sign in to comment.