Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2488-jasmine_true_random

This commit is contained in:
Carlos Jimenez Ruiz 2020-10-06 14:50:23 +02:00
commit 641eb93282
3 changed files with 36 additions and 26 deletions

View File

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

View File

@ -128,9 +128,6 @@ describe('claim', () => {
const freightPickUpPrice = 11; const freightPickUpPrice = 11;
it('should make a query and get the greugeTypeId and greuge config', () => { 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.expectRoute('GET', `GreugeTypes/findOne`).respond({id: greugeTypeId});
$httpBackend.expectGET(`GreugeConfigs/findOne`).respond({freightPickUpPrice}); $httpBackend.expectGET(`GreugeConfigs/findOne`).respond({freightPickUpPrice});
controller.onUpdateGreugeAccept(); controller.onUpdateGreugeAccept();
@ -140,37 +137,47 @@ describe('claim', () => {
expect(controller.freightPickUpPrice).toEqual(freightPickUpPrice); expect(controller.freightPickUpPrice).toEqual(freightPickUpPrice);
}); });
// #1957 - Investigate how to test nested httpBackend requests it('should perform a insert into greuges', done => {
xit('should perform a insert into greuges', () => { jest.spyOn(controller, 'getGreugeTypeId').mockReturnValue(new Promise(resolve => {
jest.spyOn(controller.card, 'reload');
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller, 'getGreugeTypeId').and.returnValue(new Promise(resolve => {
return resolve({id: greugeTypeId}); return resolve({id: greugeTypeId});
})); }));
jest.spyOn(controller, 'getGreugeConfig').and.returnValue(new Promise(resolve => { jest.spyOn(controller, 'getGreugeConfig').mockReturnValue(new Promise(resolve => {
return resolve({freightPickUpPrice}); return resolve({freightPickUpPrice});
})); }));
jest.spyOn(controller, 'updateGreuge').mockReturnValue(new Promise(resolve => {
return resolve(true);
}));
controller.claim.clientFk = 101; controller.claim.clientFk = 101;
controller.claim.id = 11; 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, clientFk: 101,
description: `claim: ${controller.claim.id}`, description: `claim: ${controller.claim.id}`,
amount: freightPickUpPrice, amount: freightPickUpPrice,
greugeTypeFk: greugeTypeId, greugeTypeFk: greugeTypeId,
ticketFk: controller.claim.ticketFk ticketFk: controller.claim.ticketFk
}; };
$httpBackend.expect('POST', `Greuges/`, data).respond(new Promise(resolve => { $httpBackend.expect('POST', `Greuges`, expectedData).respond(200);
return resolve({id: freightPickUpPrice}); controller.updateGreuge(expectedData);
}));
controller.onUpdateGreugeAccept().then(res => {
}).catch(error => {
});
$httpBackend.flush(); $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 Regularize: Regularizar
Do you want to insert greuges?: Desea insertar greuges? Do you want to insert greuges?: Desea insertar greuges?
Insert greuges on client card: Insertar greuges en la ficha del cliente 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}} ClaimGreugeDescription: Reclamación id {{claimId}}