8355-testToMaster #3336
|
@ -0,0 +1,66 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
fdescribe('invoiceIn', () => {
|
||||
let options;
|
||||
let tx;
|
||||
const invoiceId = 1;
|
||||
const supplierId = 791;
|
||||
const currencyId = 1;
|
||||
const companyId = 442;
|
||||
|
||||
beforeEach(async() => {
|
||||
options = {transaction: tx};
|
||||
tx = await models.InvoiceIn.beginTransaction({});
|
||||
options.transaction = tx;
|
||||
});
|
||||
|
||||
afterEach(async() => {
|
||||
await tx.rollback();
|
||||
});
|
||||
|
||||
it('should allow insert for new instance', async() => {
|
||||
const newInvoice = {
|
||||
supplierFk: supplierId,
|
||||
issued: Date.vnNew(),
|
||||
operated: Date.vnNew(),
|
||||
currencyFk: currencyId,
|
||||
companyFk: companyId,
|
||||
isBooked: false
|
||||
};
|
||||
|
||||
const createdInvoice = await models.InvoiceIn.create(newInvoice, options);
|
||||
|
||||
expect(createdInvoice).toBeDefined();
|
||||
expect(createdInvoice.id).toBeDefined();
|
||||
});
|
||||
|
||||
it('should throw an error if trying to update a booked invoice', async() => {
|
||||
const invoice = await models.InvoiceIn.findById(invoiceId, null, options);
|
||||
await invoice.updateAttribute('isBooked', true, options);
|
||||
|
||||
let error;
|
||||
try {
|
||||
await invoice.updateAttribute('supplierFk', supplierId, options);
|
||||
} catch (err) {
|
||||
error = err;
|
||||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
expect(error.message).toBe('InvoiceIn is already booked');
|
||||
});
|
||||
|
||||
it('should throw an error if trying to delete a booked invoice', async() => {
|
||||
const invoice = await models.InvoiceIn.findById(invoiceId, null, options);
|
||||
await invoice.updateAttribute('isBooked', true, options);
|
||||
|
||||
let error;
|
||||
try {
|
||||
await models.InvoiceIn.deleteById(invoiceId, options);
|
||||
} catch (err) {
|
||||
error = err;
|
||||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
expect(error.sqlMessage).toBe('InvoiceIn is already booked');
|
||||
});
|
||||
});
|
|
@ -2,7 +2,7 @@ const models = require('vn-loopback/server/server').models;
|
|||
|
||||
const invoiceInId = 1;
|
||||
const supplierId = 791;
|
||||
fdescribe('invoiceIn updateInvoiceIn()', () => {
|
||||
describe('invoiceIn updateInvoiceIn()', () => {
|
||||
const ctx = beforeAll.getCtx();
|
||||
let options;
|
||||
let tx;
|
||||
|
|
Loading…
Reference in New Issue