salesperson back end unit tests plus small refactor on addresses, employee and filter specs

This commit is contained in:
Carlos Jimenez 2018-01-26 11:23:53 +01:00
parent 8dafd8c3b0
commit 6dba8c7a40
4 changed files with 41 additions and 34 deletions

View File

@ -2,19 +2,17 @@ import app from '../../../../server/server';
import {catchErrors} from '../../../../../../services/utils/jasmineHelpers';
describe('Client addresses', () => {
it('should call the addressesList method and receive total results and results of 2 as it has only 2 addresses', done => {
it('should call the addressesList method and receive total results and items', done => {
let id = 1;
let params = {
page: 10,
size: 30
page: 1,
size: 1
};
let callback = (error, result) => {
if (error) return catchErrors(done)(error);
expect(result).toEqual(jasmine.objectContaining({
total: 2
}));
expect(Object.keys(result)).toEqual(['total', 'items']);
done();
};
app.models.Client.addressesList(id, params, callback);

View File

@ -5,33 +5,9 @@ describe('Client employeeList', () => {
it('should call the employeeList()', done => {
let callback = (error, result) => {
if (error) return catchErrors(done)(error);
let amountOfEmployees = Object.keys(result).length;
expect(result).toEqual(jasmine.objectContaining([
{
id: 4,
name: 'Bruce Banner'
},
{
id: 3,
name: 'Charles Xavier'
},
{
id: 1,
name: 'David Charles Haller'
},
{
id: 2,
name: 'Hank Pym'
},
{
id: 5,
name: 'Jessica Jones'
},
{
id: 20,
name: 'Victor Stone'
}
]));
expect(amountOfEmployees).toEqual(6);
done();
};
app.models.Client.employeeList(callback);

View File

@ -8,11 +8,11 @@ describe('Client filterClients()', () => {
search: 'Bruce Wayne',
phone: 555555555
};
let expectedResponse = {where: {and: [{or: [{id: 'Bruce Wayne'}, {name: {regexp: 'Bruce Wayne'}}]}, {or: [{phone: 555555555}, {mobile: 555555555}]}]}, skip: 0, limit: 1};
let client = jasmine.createSpyObj('client', ['installMethod']);
filter(client);
let filterClients = client.installMethod.calls.allArgs()[0][1];
let nameOfResultingClient = filterClients(params).where.and[0].or[1].name.regexp;
expect(Object.keys(filterClients(params))).toEqual(Object.keys(expectedResponse));
expect(nameOfResultingClient).toEqual('Bruce Wayne');
});
});

View File

@ -0,0 +1,33 @@
import app from '../../../../server/server';
import {catchErrors} from '../../../../../../services/utils/jasmineHelpers';
describe('Client activeSalesPerson', () => {
it('should call the activeSalesPerson() method with limit of 1', done => {
let filter = {
limit: 1
};
let callback = (error, result) => {
if (error) return catchErrors(done)(error);
expect(result.length).toEqual(1);
done();
};
app.models.Client.activeSalesPerson(filter, callback);
});
it('should call the activeSalesPerson() method with no limit and receive all 3 salesPersons', done => {
let filter = {
};
let callback = (error, result) => {
if (error) return catchErrors(done)(error);
expect(result.length).toEqual(3);
done();
};
app.models.Client.activeSalesPerson(filter, callback);
});
});