#521 updateBasicData.js Backend unit tests

This commit is contained in:
Carlos Jimenez 2018-08-13 14:52:05 +02:00
parent 9268fdb2da
commit 24ad4a83a1
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,41 @@
const app = require(`${servicesDir}/client/server/server`);
describe('Client updateBasicData', () => {
afterAll(async() => {
let id = 101;
let validparams = {email: 'BruceWayne@verdnatura.es'};
await app.models.Client.updateBasicData(validparams, id);
});
it('should return an error if the params aint valid', async() => {
let error;
let id = 101;
let invalidparams = {invalid: 'param for update'};
await app.models.Client.updateBasicData(invalidparams, id)
.catch(e => {
error = e;
});
expect(error.toString()).toContain(`You don't have enough privileges to do that`);
});
it('should update the client discal data and return the count if changes made', async() => {
let id = 101;
let client = await app.models.Client.findById(id);
expect(client.email).toEqual('BruceWayne@verdnatura.es');
let validparams = {email: 'myNewEmail@myDomain.es'};
let result = await app.models.Client.updateBasicData(validparams, id);
expect(result).toEqual({count: 1});
let updatedClient = await app.models.Client.findById(101);
expect(updatedClient.email).toEqual('myNewEmail@myDomain.es');
});
});

View File

@ -44,8 +44,16 @@ describe('Client updateFiscalData', () => {
let validparams = {postcode: 12345}; let validparams = {postcode: 12345};
let idWithDataChecked = 101; let idWithDataChecked = 101;
let client = await app.models.Client.findById(idWithDataChecked);
expect(client.postcode).toEqual('46460');
let result = await app.models.Client.updateFiscalData(ctxOfAdmin, validparams, idWithDataChecked); let result = await app.models.Client.updateFiscalData(ctxOfAdmin, validparams, idWithDataChecked);
expect(result).toEqual({count: 1}); expect(result).toEqual({count: 1});
let updatedClient = await app.models.Client.findById(idWithDataChecked);
expect(updatedClient.postcode).toEqual('12345');
}); });
}); });