Skip to content

Commit

Permalink
added client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schaechinger committed Mar 26, 2018
1 parent 320a22f commit 8cac3d4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/ProductList/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

'use strict';

const errors = require('../errors');

class Client {
/**
* Create a new product service client object holding the credentials to
Expand All @@ -24,6 +26,9 @@ class Client {
* from the username but in caps <MANDANTID>
*/
constructor({ username, password, id = null }) {
if (!username || !password) {
throw new Error(errors.usage.missingClientCredentials);
}
/** @type {string} */
this._username = username;
/** @type {string} */
Expand Down
7 changes: 7 additions & 0 deletions lib/ProductList/Product.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class Product {
return this._price;
}

/**
* @returns {string}
*/
getName() {
return this._name;
}

/**
* Checks the validity of the product by validating the id.
*
Expand Down
3 changes: 2 additions & 1 deletion lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {
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!',
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!'
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!'
}
};
37 changes: 37 additions & 0 deletions test/ProductList/Client.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const Client = require('../../lib/ProductList/Client'),
errors = require('../../lib/errors');

describe('Client', () => {
const args = {
username: 'myusername',
password: '#MY_PASS',
id: 'myid'
};

it('should require client credentials', () => {
(() => {
const client = new Client();
}).should.throw(errors.usage.missingClientCredentials);
});

it('should create instance with demo data', () => {
const client = new Client(args);

client.should.be.ok();

client.getUsername().should.equal(args.username);
client.getPassword().should.equal(args.password);
client.getId().should.equal(args.id);
});

it('should generate the client id if not given', () {
const credentials = {
username: 'myusername',
password: '*****'
};

const client = new Client(credentials);

client.getId().shoul.equal(credentials.username.toUpperCase());
});
});

0 comments on commit 8cac3d4

Please sign in to comment.