1447-updateClaim_refactor #405

Merged
joan merged 5 commits from 1447-updateClaim_refactor into dev 2020-10-13 08:10:06 +00:00
6 changed files with 44 additions and 36 deletions
Showing only changes of commit 7538b1c941 - Show all commits

View File

@ -127,7 +127,7 @@ export default class Controller extends Section {
promises.push(this.getGreugeConfig());
return Promise.all(promises).then(() => {
const data = {
return this.updateGreuge({
clientFk: this.claim.clientFk,
description: this.$t('ClaimGreugeDescription', {
claimId: this.claim.id
@ -135,11 +135,14 @@ export default class Controller extends Section {
amount: this.freightPickUpPrice,
greugeTypeFk: this.greugeTypeFreightId,
ticketFk: this.claim.ticketFk
};
});
});
}
updateGreuge(data) {
return this.$http.post(`Greuges`, data).then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
this.vnApp.showMessage(this.$t('Greuge inserted'));
});
this.vnApp.showMessage(this.$t('Greuge added'));
});
}

View File

@ -128,9 +128,6 @@ describe('claim', () => {
const freightPickUpPrice = 11;
it('should make a query and get the greugeTypeId and greuge config', () => {
jest.spyOn(controller.card, 'reload');
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectRoute('GET', `GreugeTypes/findOne`).respond({id: greugeTypeId});
$httpBackend.expectGET(`GreugeConfigs/findOne`).respond({freightPickUpPrice});
controller.onUpdateGreugeAccept();
@ -140,37 +137,47 @@ describe('claim', () => {
expect(controller.freightPickUpPrice).toEqual(freightPickUpPrice);
});
// #1957 - Investigate how to test nested httpBackend requests
xit('should perform a insert into greuges', () => {
jest.spyOn(controller.card, 'reload');
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller, 'getGreugeTypeId').and.returnValue(new Promise(resolve => {
it('should perform a insert into greuges', done => {
jest.spyOn(controller, 'getGreugeTypeId').mockReturnValue(new Promise(resolve => {
return resolve({id: greugeTypeId});
}));
jest.spyOn(controller, 'getGreugeConfig').and.returnValue(new Promise(resolve => {
jest.spyOn(controller, 'getGreugeConfig').mockReturnValue(new Promise(resolve => {
return resolve({freightPickUpPrice});
}));
jest.spyOn(controller, 'updateGreuge').mockReturnValue(new Promise(resolve => {
return resolve(true);
}));
controller.claim.clientFk = 101;
controller.claim.id = 11;
let data = {
controller.onUpdateGreugeAccept().then(() => {
expect(controller.updateGreuge).toHaveBeenCalledWith(jasmine.any(Object));
done();
}).catch(done.fail);
});
});
describe('updateGreuge()', () => {
it('should make a query and then call to showSuccess() and showMessage() methods', () => {
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.vnApp, 'showMessage');
const freightPickUpPrice = 11;
const greugeTypeId = 7;
const expectedData = {
clientFk: 101,
description: `claim: ${controller.claim.id}`,
amount: freightPickUpPrice,
greugeTypeFk: greugeTypeId,
ticketFk: controller.claim.ticketFk
};
$httpBackend.expect('POST', `Greuges/`, data).respond(new Promise(resolve => {
return resolve({id: freightPickUpPrice});
}));
controller.onUpdateGreugeAccept().then(res => {
}).catch(error => {
});
$httpBackend.expect('POST', `Greuges`, expectedData).respond(200);
controller.updateGreuge(expectedData);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Greuge added');
});
});
});

View File

@ -8,5 +8,5 @@ Imports ticket lines: Importa las lineas de un ticket
Regularize: Regularizar
Do you want to insert greuges?: Desea insertar greuges?
Insert greuges on client card: Insertar greuges en la ficha del cliente
Greuge inserted: Greuge insertado
Greuge added: Greuge añadido
ClaimGreugeDescription: Reclamación id {{claimId}}

View File

@ -1,6 +1,6 @@
const app = require('vn-loopback/server/server');
xdescribe('item getWasteDetail()', () => {
describe('item getWasteDetail()', () => {
it('should check for the waste breakdown for every worker', async() => {
let result = await app.models.Item.getWasteDetail();
@ -14,10 +14,10 @@ xdescribe('item getWasteDetail()', () => {
expect(result.length).toEqual(3);
expect(firstBuyer).toEqual('CharlesXavier');
expect(firstBuyerLines.length).toEqual(4);
expect(secondBuyer).toEqual('DavidCharlesHaller');
expect(secondBuyer).toEqual('HankPym');
expect(secondBuyerLines.length).toEqual(3);
expect(thirdBuyer).toEqual('HankPym');
expect(thirdBuyer).toEqual('DavidCharlesHaller');
expect(thirdBuyerLines.length).toEqual(3);
});
});

View File

@ -1,10 +1,9 @@
import number from '../number.js';
// Issue #2437
xdescribe('number filter', () => {
describe('number filter', () => {
const superDuperNumber = 18021984;
it('should filter the number with commas by default', () => {
expect(number(superDuperNumber)).toEqual('18,021,984');
expect(number(superDuperNumber, 'en')).toEqual('18,021,984');
});
});

View File

@ -1,12 +1,11 @@
import percentage from '../percentage.js';
// Issue #2437
xdescribe('percentage filter', () => {
describe('percentage filter', () => {
it('should filter the percentage also round it correctly', () => {
expect(percentage(99.9999999999999999 / 100)).toEqual('100.00%');
expect(percentage(99.9999999999999999 / 100, 2, 2, 'en')).toEqual('100.00%');
});
it('should filter the percentage and round it correctly', () => {
expect(percentage(1.25444444444444444 / 100)).toEqual('1.25%');
expect(percentage(1.25444444444444444 / 100, 2, 2, 'en')).toEqual('1.25%');
});
});