diff --git a/lib/ProductList/Client.js b/lib/ProductList/Client.js index 275ffa3..af241b2 100644 --- a/lib/ProductList/Client.js +++ b/lib/ProductList/Client.js @@ -25,7 +25,7 @@ class Client { * @param {string} [client.id] - The dedicated id of the account if different * from the username but in caps */ - constructor({ username, password, id = null }) { + constructor({ username, password, id = null } = {}) { if (!username || !password) { throw new Error(errors.usage.missingClientCredentials); } diff --git a/lib/ProductList/Product.js b/lib/ProductList/Product.js index c816642..624650d 100644 --- a/lib/ProductList/Product.js +++ b/lib/ProductList/Product.js @@ -22,7 +22,9 @@ class Product { /** @type {number[]} - The weight range in grams. */ this._weight = []; - this._readData(data); + if (data) { + this._readData(data); + } } /** @@ -55,7 +57,7 @@ class Product { return !!this._id; } - _readData(data) { + _readData(data = {}) { if (data.hasOwnProperty('extendedIdentifier')) { this._id = +data.extendedIdentifier.externIdentifier.attributes.id; this._name = data.extendedIdentifier.externIdentifier.attributes.name; diff --git a/lib/errors.js b/lib/errors.js index 7e4c2b5..bf73ecf 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -22,7 +22,7 @@ module.exports = { invalidCountryCode: '3002: Invalid country code for address given: ', missingAddressBindings: '3003: Please add receiver and sender to address binding!', missingPartnerCredentials: '3004: The api requires valid partner credentials including the id and the secret!', - missingPositionParameters: '3005: A position requires at least the productCode and a voucherLayout!', + missingPositionParameters: '3005: A position requires at least the product or productCode and a voucherLayout!', invalidLayoutZone: '3006: Invalid voucher layout given: ', missingProductClients: '3007: The product client credentials are required to make use of the product list. Please add credentials with internetmarke.enableProductList!', missingClientCredentials: '3008: The api requires valid client credentials including the username and password!' diff --git a/test/Order/Order.test.js b/test/Order/Order.test.js index 750351c..a37edc6 100644 --- a/test/Order/Order.test.js +++ b/test/Order/Order.test.js @@ -29,15 +29,15 @@ describe('Order', () => { const product = { getId: sinon.stub().returns(1), - getPrice: sinon.stub().returned(70) + getPrice: sinon.stub().returns(70) }; - order.addPosition({ product }); + order.addPosition({ product, voucherLayout: 'FrankingZone' }); product.getId.calledOnce.should.be.true(); product.getPrice.calledOnce.should.be.true(); - order._positions.length.should.have.length(1); + order._positions.should.have.length(1); }); }); diff --git a/test/ProductList/Client.test.js b/test/ProductList/Client.test.js index ef2e7cc..dbd95a6 100644 --- a/test/ProductList/Client.test.js +++ b/test/ProductList/Client.test.js @@ -24,7 +24,7 @@ describe('Client', () => { client.getId().should.equal(args.id); }); - it('should generate the client id if not given', () { + it('should generate the client id if not given', () => { const credentials = { username: 'myusername', password: '*****' @@ -32,6 +32,6 @@ describe('Client', () => { const client = new Client(credentials); - client.getId().shoul.equal(credentials.username.toUpperCase()); + client.getId().should.equal(credentials.username.toUpperCase()); }); }); diff --git a/test/ProductList/Product.test.js b/test/ProductList/Product.test.js index 2d755a9..119cbcc 100644 --- a/test/ProductList/Product.test.js +++ b/test/ProductList/Product.test.js @@ -26,7 +26,7 @@ describe('Product', () => { product.getId().should.equal(data.gen.id); product.getPrice().should.equal(data.gen.price); product.getName().should.equal(data.gen.name); - product._dimensions.should.have.properties('length', 'weight', 'height'); + product._dimensions.should.have.properties('length', 'width', 'height'); product._dimensions.length.should.have.length(2); product._weight.should.have.length(2); product._ppl.should.equal(data.gen.ppl);