const app = require(`${servicesDir}/client/server/server`); describe('Client updateBillingData', () => { afterAll(async() => { let ctxOfAdmin = {req: {accessToken: {userId: 5}}}; let validparams = {iban: null}; let idWithDataChecked = 101; await app.models.Client.updateBillingData(ctxOfAdmin, validparams, idWithDataChecked); }); it('should return an error if the user is not administrative and the isTaxDataChecked value is true', async() => { let error; let ctxOfNoAdmin = {req: {accessToken: {userId: 1}}}; let params = []; let idWithDataChecked = 101; await app.models.Client.updateBillingData(ctxOfNoAdmin, params, idWithDataChecked) .catch(e => { error = e; }); expect(error.toString()).toContain(`You don't have enough privileges to do that`); }); it('should return an error if the user is administrative and the isTaxDataChecked value is true BUT the params aint valid', async() => { let error; let ctxOfAdmin = {req: {accessToken: {userId: 5}}}; let invalidparams = {invalid: 'param for update'}; let idWithDataChecked = 101; await app.models.Client.updateBillingData(ctxOfAdmin, invalidparams, idWithDataChecked) .catch(e => { error = e; }); expect(error.toString()).toContain(`You don't have enough privileges to do that`); }); it('should return an error if the given IBAN is an invalid one', async() => { let ctxOfAdmin = {req: {accessToken: {userId: 5}}}; let validparams = {iban: 12345}; let idWithDataChecked = 101; try { await app.models.Client.updateBillingData(ctxOfAdmin, validparams, idWithDataChecked); } catch (error) { expect(error.toString()).toContain('The IBAN does not have the correct format'); } let client = await app.models.Client.findById(idWithDataChecked); expect(client.iban).toBeFalsy(); }); });