falta test checkToBook
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Javi Gallego 2021-10-05 11:19:48 +02:00
parent 4f1fd5412d
commit 2dee9fec20
4 changed files with 21 additions and 26 deletions

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethodCtx('getTotals', {
Self.remoteMethod('getTotals', {
description: 'Return totals for an invoiceIn',
accessType: 'READ',
accepts: {
@ -19,7 +19,7 @@ module.exports = Self => {
}
});
Self.getTotals = async(ctx, id, options) => {
Self.getTotals = async(id, options) => {
let tx;
const myOptions = {};

View File

@ -22,7 +22,6 @@ module.exports = Self => {
});
Self.toBook = async(ctx, id, options) => {
const models = Self.app.models;
let tx;
const myOptions = {};
@ -35,10 +34,6 @@ module.exports = Self => {
}
try {
const totals = await models.InvoiceIn.getTotals(id);
if (totals.totalDueDay != totals.totalTaxableBase && totals.totalDueDay != totals.totalVal)
throw new UserError(`Amounts do not match`);
await Self.rawSql(`CALL vn.invoiceInBookingMain(?)`, [id], myOptions);
if (tx) await tx.commit();
} catch (e) {

View File

@ -51,14 +51,17 @@ class Controller extends Descriptor {
return this.getData(`InvoiceIns/${this.id}`, {filter})
.then(res => this.entity = res.data);
}
checktoBook() {
let message = '';
const id = this.invoiceIn.id;
this.$q.all([
this.$http.get(`InvoiceIns/${this.id}/getTotals`)
.then(res => {
if (res.data.totalDueDay != res.data.totalTaxableBase && res.data.totalDueDay != res.data.totalVat)
message += 'amountsNotMatch';
const taxableBaseNotEqualDueDay = res.data.totalDueDay != res.data.totalTaxableBase;
const vatNotEqualDueDay = res.data.totalDueDay != res.data.totalVat;
if (taxableBaseNotEqualDueDay && vatNotEqualDueDay)
message += 'amountsDoNotMatch';
}),
this.$http.get('InvoiceInDueDays/count', {
filter: {
@ -73,7 +76,7 @@ class Controller extends Descriptor {
})
]).finally(() => {
if (message > '')
if (message.length)
this.$.confirmToBookAnyway.show();
else
onAcceptToBook();
@ -81,8 +84,10 @@ class Controller extends Descriptor {
}
onAcceptToBook() {
this.$http.post(`InvoiceIns/${this.id}/toBook`);
this.vnApp.showSuccess(this.$t('InvoiceIn booked'));
this.$http.post(`InvoiceIns/${this.id}/toBook`)
.then(() => {
this.vnApp.showSuccess(this.$t('InvoiceIn booked'));
});
}
}

View File

@ -9,31 +9,26 @@ describe('vnInvoiceInDescriptor', () => {
beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
controller = $componentController('vnInvoiceInDescriptor', {$element: null});
controller.invoiceIn = {id: 1};
$httpBackend.when('GET', `InvoiceIns/${controller.invoiceIn.id}`).respond({id: 1});
}));
describe('loadData()', () => {
it(`should perform a get query to store the invoice in data into the controller`, () => {
const id = 1;
const response = {id: 1};
$httpBackend.expectGET(`InvoiceIns/${id}`).respond(response);
controller.id = id;
$httpBackend.flush();
expect(controller.invoiceIn).toEqual(response);
expect(controller.invoiceIn).toEqual({id: 1});
});
});
describe('toBook()', () => {
it(`should perform a post query to book the invoiSce`, () => {
describe('onAcceptToBook()', () => {
it(`should perform a post query to book the invoice`, () => {
controller.vnApp = {showSuccess: jest.fn()};
const id = 1;
const response = {id: 1};
$httpBackend.expectPOST(`InvoiceIns/${id}/toBook`).respond(response);
controller.id = id;
$httpBackend.expectPOST(`InvoiceIns/${id}/toBook`).respond();
controller.onAcceptToBook();
$httpBackend.flush();
expect(controller.invoiceIn).toEqual(response);
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('InvoiceIn booked');
});
});
});