refactor: add frontTest
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
5e35783a38
commit
7abceb8564
|
@ -117,27 +117,26 @@ class Controller extends Section {
|
|||
});
|
||||
}
|
||||
|
||||
async refundInvoiceOut() {
|
||||
refundInvoiceOut() {
|
||||
let filter = {
|
||||
where: {refFk: this.invoiceOut.ref}
|
||||
};
|
||||
await this.$http.get('Tickets', {filter})
|
||||
this.$http.get('Tickets', {filter})
|
||||
.then(res => {
|
||||
this.tickets = res.data;
|
||||
this.ticketsIds = [];
|
||||
for (let ticket of this.tickets)
|
||||
this.ticketsIds.push(ticket.id);
|
||||
});
|
||||
|
||||
filter = {
|
||||
where: {ticketFk: {inq: this.ticketsIds}}
|
||||
};
|
||||
await this.$http.get('Sales', {filter})
|
||||
.then(res => this.sales = res.data);
|
||||
|
||||
await this.$http.get('TicketServices', {filter})
|
||||
.then(res => this.services = res.data);
|
||||
|
||||
this.$http.get('Sales', {filter})
|
||||
.then(res => {
|
||||
this.sales = res.data;
|
||||
this.$http.get('TicketServices', {filter})
|
||||
.then(res => {
|
||||
this.services = res.data;
|
||||
const params = {
|
||||
sales: this.sales,
|
||||
services: this.services
|
||||
|
@ -146,6 +145,9 @@ class Controller extends Section {
|
|||
return this.$http.post(query, params).then(res => {
|
||||
this.$state.go('ticket.card.sale', {id: res.data});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -122,4 +122,33 @@ describe('vnInvoiceOutDescriptorMenu', () => {
|
|||
expect(controller.vnApp.showMessage).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('refundInvoiceOut()', () => {
|
||||
it('should make a query and go to ticket.card.sale', () => {
|
||||
controller.$state.go = jest.fn();
|
||||
|
||||
const invoiceOut = {
|
||||
id: 1,
|
||||
ref: 'T1111111'
|
||||
};
|
||||
controller.invoiceOut = invoiceOut;
|
||||
const tickets = [{id: 1}];
|
||||
const sales = [{id: 1}];
|
||||
const services = [{id: 2}];
|
||||
|
||||
$httpBackend.expectGET(`Tickets`).respond(tickets);
|
||||
$httpBackend.expectGET(`Sales`).respond(sales);
|
||||
$httpBackend.expectGET(`TicketServices`).respond(services);
|
||||
|
||||
const expectedParams = {
|
||||
sales: sales,
|
||||
services: services
|
||||
};
|
||||
$httpBackend.expectPOST(`Sales/refund`, expectedParams).respond();
|
||||
controller.refundInvoiceOut();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: undefined});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -273,16 +273,16 @@ class Controller extends Section {
|
|||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
||||
}
|
||||
|
||||
async refund() {
|
||||
refund() {
|
||||
const filter = {
|
||||
where: {ticketFk: this.id}
|
||||
};
|
||||
await this.$http.get('Sales', {filter})
|
||||
.then(res => this.sales = res.data);
|
||||
|
||||
await this.$http.get('TicketServices', {filter})
|
||||
.then(res => this.services = res.data);
|
||||
|
||||
this.$http.get('Sales', {filter})
|
||||
.then(res => {
|
||||
this.sales = res.data;
|
||||
this.$http.get('TicketServices', {filter})
|
||||
.then(res => {
|
||||
this.services = res.data;
|
||||
const params = {
|
||||
sales: this.sales,
|
||||
services: this.services
|
||||
|
@ -291,6 +291,8 @@ class Controller extends Section {
|
|||
return this.$http.post(query, params).then(res => {
|
||||
this.$state.go('ticket.card.sale', {id: res.data});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -264,51 +264,14 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
|
|||
|
||||
describe('refund()', () => {
|
||||
it('should make a query and go to ticket.card.sale', () => {
|
||||
jest.spyOn(controller.$state, 'go').mockReturnValue();
|
||||
controller.$state.go = jest.fn();
|
||||
|
||||
const sales = [{
|
||||
id: 13,
|
||||
concept: 'Melee weapon combat fist 15cm',
|
||||
quantity: 10,
|
||||
price: 7.08,
|
||||
discount: 0,
|
||||
reserved: false,
|
||||
isPicked: 0,
|
||||
created: '2022-04-21T22:00:00.000Z',
|
||||
itemFk: 2,
|
||||
ticketFk: 8
|
||||
},
|
||||
{
|
||||
id: 14,
|
||||
concept: 'Ranged weapon longbow 2m',
|
||||
quantity: 2,
|
||||
price: 103.49,
|
||||
discount: 0,
|
||||
reserved: false,
|
||||
isPicked: 0,
|
||||
created: '2022-04-21T22:00:00.000Z',
|
||||
itemFk: 1,
|
||||
ticketFk: 8
|
||||
}];
|
||||
controller._id = ticket.id;
|
||||
const sales = [{id: 1}];
|
||||
const services = [{id: 2}];
|
||||
|
||||
const services = [{
|
||||
id: 5,
|
||||
ticketFk: 8,
|
||||
description: 'Documentos',
|
||||
quantity: 1,
|
||||
price: 2,
|
||||
taxClassFk: 1,
|
||||
ticketServiceTypeFk: 1
|
||||
}];
|
||||
|
||||
const filter = {
|
||||
where: {ticketFk: ticket.id}
|
||||
};
|
||||
const serializedParams = $httpParamSerializer({filter});
|
||||
console.log(serializedParams);
|
||||
|
||||
$httpBackend.expect('GET', `Sales?${serializedParams}`).respond();
|
||||
$httpBackend.expectGET(`TicketServices?filter=${serializedParams}`).respond();
|
||||
$httpBackend.expectGET(`Sales`).respond(sales);
|
||||
$httpBackend.expectGET(`TicketServices`).respond(services);
|
||||
|
||||
const expectedParams = {
|
||||
sales: sales,
|
||||
|
@ -318,7 +281,7 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
|
|||
controller.refund();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: {ticketId: ticket.id}});
|
||||
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: undefined});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue