ticket.basicData address
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Bernat Exposito Domenech 2020-03-06 08:38:03 +01:00
parent f168734b8c
commit 666ccbf370
2 changed files with 34 additions and 16 deletions

View File

@ -22,7 +22,7 @@ class Controller {
if (!value || !value.id) return; if (!value || !value.id) return;
this.onChangeClient(value.clientFk); this.clientAddressesList(value.clientFk);
} }
get clientId() { get clientId() {
@ -33,7 +33,8 @@ class Controller {
this.ticket.clientFk = value; this.ticket.clientFk = value;
this.ticket.addressFk = null; this.ticket.addressFk = null;
this.onChangeClient(value); this.getClientDefaultAddress(value);
this.clientAddressesList(value);
} }
get addressId() { get addressId() {
@ -68,7 +69,6 @@ class Controller {
} }
} }
get shipped() { get shipped() {
return this.ticket && this.ticket.shipped; return this.ticket && this.ticket.shipped;
} }
@ -127,7 +127,7 @@ class Controller {
/* /*
* Autocompletes address on client change * Autocompletes address on client change
*/ */
onChangeClient(value) { clientAddressesList(value) {
let filter = { let filter = {
include: [ include: [
{ {
@ -153,6 +153,14 @@ class Controller {
}); });
} }
getClientDefaultAddress(value) {
let query = `Clients/${value}`;
this.$http.get(query).then(res => {
if (res.data)
this.ticket.addressFk = res.data.defaultAddressFk;
});
}
/* /*
* Gets an agency from an specified zone * Gets an agency from an specified zone
*/ */

View File

@ -22,18 +22,18 @@ describe('Ticket', () => {
})); }));
describe('ticket() setter', () => { describe('ticket() setter', () => {
it('should set ticket property and call onChangeClient() method', () => { it('should set ticket property and call clientAddressesList() method', () => {
jest.spyOn(controller, 'onChangeClient'); jest.spyOn(controller, 'clientAddressesList');
controller.ticket = {id: 1, clientFk: 101}; controller.ticket = {id: 1, clientFk: 101};
expect(controller.onChangeClient).toHaveBeenCalledWith(101); expect(controller.clientAddressesList).toHaveBeenCalledWith(101);
}); });
it(`should not call onChangeClient() method as the ticket doesn't have an ID`, () => { it(`should not call clientAddressesList() method as the ticket doesn't have an ID`, () => {
jest.spyOn(controller, 'onChangeClient'); jest.spyOn(controller, 'clientAddressesList');
controller.ticket = {}; controller.ticket = {};
expect(controller.onChangeClient).not.toHaveBeenCalledWith(); expect(controller.clientAddressesList).not.toHaveBeenCalledWith();
}); });
}); });
@ -46,12 +46,12 @@ describe('Ticket', () => {
}); });
describe('clientId() setter', () => { describe('clientId() setter', () => {
it('should set clientId property and call onChangeClient() method ', () => { it('should set clientId property and call clientAddressesList() method ', () => {
jest.spyOn(controller, 'onChangeClient'); jest.spyOn(controller, 'clientAddressesList');
controller.ticket = {id: 1, clientId: 101}; controller.ticket = {id: 1, clientId: 101};
controller.clientId = 102; controller.clientId = 102;
expect(controller.onChangeClient).toHaveBeenCalledWith(102); expect(controller.clientAddressesList).toHaveBeenCalledWith(102);
}); });
}); });
@ -155,7 +155,6 @@ describe('Ticket', () => {
}; };
controller.landed = landed; controller.landed = landed;
expect(controller.getShipped).toHaveBeenCalledWith(expectedResult); expect(controller.getShipped).toHaveBeenCalledWith(expectedResult);
}); });
}); });
@ -230,7 +229,7 @@ describe('Ticket', () => {
}); });
}); });
describe('onChangeClient()', () => { describe('clientAddressesList()', () => {
it('should return a list of addresses from choosed client', async() => { it('should return a list of addresses from choosed client', async() => {
const clientId = 102; const clientId = 102;
let filter = { let filter = {
@ -253,7 +252,18 @@ describe('Ticket', () => {
$httpBackend.when('GET', `Clients/${clientId}/addresses?filter=${filter}`).respond(200); $httpBackend.when('GET', `Clients/${clientId}/addresses?filter=${filter}`).respond(200);
$httpBackend.expect('GET', `Clients/${clientId}/addresses?filter=${filter}`); $httpBackend.expect('GET', `Clients/${clientId}/addresses?filter=${filter}`);
controller.onChangeClient(clientId); controller.clientAddressesList(clientId);
$httpBackend.flush();
});
});
describe('getClientDefaultAddress()', () => {
it('should return the default address from choosed client', async() => {
const clientId = 102;
$httpBackend.when('GET', `Clients/${clientId}`).respond(200);
$httpBackend.expect('GET', `Clients/${clientId}`);
controller.getClientDefaultAddress(clientId);
$httpBackend.flush(); $httpBackend.flush();
}); });
}); });