#521 updateBasicData.js Backend unit tests
This commit is contained in:
parent
9268fdb2da
commit
24ad4a83a1
|
@ -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');
|
||||||
|
});
|
||||||
|
});
|
|
@ -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');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue