refs #4928 fixture notification, fix test supplier
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
f4ed7781b5
commit
33196acac6
|
@ -44,3 +44,6 @@ BEGIN
|
|||
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
INSERT INTO `util`.`notification` (`id`, `name`,`description`)
|
||||
VALUES (3, 'supplier-pay-method-update', 'A supplier pay method has been updated');
|
||||
|
|
|
@ -2,13 +2,7 @@ const models = require('vn-loopback/server/server').models;
|
|||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('loopback model Supplier', () => {
|
||||
let supplierOne;
|
||||
let supplierTwo;
|
||||
|
||||
beforeAll(async() => {
|
||||
supplierOne = await models.Supplier.findById(1);
|
||||
supplierTwo = await models.Supplier.findById(442);
|
||||
|
||||
const activeCtx = {
|
||||
accessToken: {userId: 9},
|
||||
http: {
|
||||
|
@ -23,18 +17,17 @@ describe('loopback model Supplier', () => {
|
|||
});
|
||||
});
|
||||
|
||||
afterAll(async() => {
|
||||
await supplierOne.updateAttribute('payMethodFk', supplierOne.payMethodFk);
|
||||
await supplierTwo.updateAttribute('payMethodFk', supplierTwo.payMethodFk);
|
||||
});
|
||||
|
||||
describe('payMethodFk', () => {
|
||||
it('should throw an error when attempting to set an invalid payMethod id in the supplier', async() => {
|
||||
const tx = await models.Supplier.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
let error;
|
||||
const expectedError = 'You can not select this payment method without a registered bankery account';
|
||||
const supplier = await models.Supplier.findById(1);
|
||||
const supplier = await models.Supplier.findOne({where: {id: 1}}, options);
|
||||
|
||||
await supplier.updateAttribute('payMethodFk', 8)
|
||||
await supplier.updateAttribute('payMethodFk', 8, options)
|
||||
.catch(e => {
|
||||
error = e;
|
||||
|
||||
|
@ -42,52 +35,94 @@ describe('loopback model Supplier', () => {
|
|||
});
|
||||
|
||||
expect(error).toBeDefined();
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should not throw if the payMethod id is valid', async() => {
|
||||
const tx = await models.Supplier.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
let error;
|
||||
const supplier = await models.Supplier.findById(442);
|
||||
await supplier.updateAttribute('payMethodFk', 4)
|
||||
const supplier = await models.Supplier.findOne({where: {id: 442}}, options);
|
||||
await supplier.updateAttribute('payMethodFk', 4, options)
|
||||
.catch(e => {
|
||||
error = e;
|
||||
});
|
||||
|
||||
expect(error).not.toBeDefined();
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should have checked isPayMethodChecked for payMethod hasVerfified is false', async() => {
|
||||
const supplier = await models.Supplier.findById(442);
|
||||
await supplier.updateAttribute('isPayMethodChecked', true);
|
||||
await supplier.updateAttribute('payMethodFk', 5);
|
||||
const tx = await models.Supplier.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
const result = await models.Supplier.findById(442);
|
||||
try {
|
||||
const supplier = await models.Supplier.findOne({where: {id: 442}}, options);
|
||||
await supplier.updateAttribute('isPayMethodChecked', true, options);
|
||||
await supplier.updateAttribute('payMethodFk', 5, options);
|
||||
|
||||
const result = await models.Supplier.findOne({where: {id: 442}}, options);
|
||||
|
||||
expect(result.isPayMethodChecked).toEqual(true);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should have unchecked isPayMethodChecked for payMethod hasVerfified is true', async() => {
|
||||
const supplier = await models.Supplier.findById(442);
|
||||
await supplier.updateAttribute('isPayMethodChecked', true);
|
||||
await supplier.updateAttribute('payMethodFk', 2);
|
||||
const tx = await models.Supplier.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
const result = await models.Supplier.findById(442);
|
||||
try {
|
||||
const supplier = await models.Supplier.findOne({where: {id: 442}}, options);
|
||||
await supplier.updateAttribute('isPayMethodChecked', true, options);
|
||||
await supplier.updateAttribute('payMethodFk', 2, options);
|
||||
|
||||
const result = await models.Supplier.findOne({where: {id: 442}}, options);
|
||||
|
||||
expect(result.isPayMethodChecked).toEqual(false);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should have unchecked isPayMethodChecked for payDay and peyDemFk', async() => {
|
||||
const supplier = await models.Supplier.findById(442);
|
||||
const tx = await models.Supplier.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
await supplier.updateAttribute('isPayMethodChecked', true);
|
||||
await supplier.updateAttribute('payDay', 5);
|
||||
const firstResult = await models.Supplier.findById(442);
|
||||
try {
|
||||
const supplier = await models.Supplier.findOne({where: {id: 442}}, options);
|
||||
await supplier.updateAttribute('payMethodFk', 2, options);
|
||||
|
||||
await supplier.updateAttribute('isPayMethodChecked', true);
|
||||
await supplier.updateAttribute('payDemFk', 1);
|
||||
const secondResult = await models.Supplier.findById(442);
|
||||
await supplier.updateAttribute('isPayMethodChecked', true, options);
|
||||
await supplier.updateAttribute('payDay', 5, options);
|
||||
const firstResult = await models.Supplier.findOne({where: {id: 442}}, options);
|
||||
|
||||
await supplier.updateAttribute('isPayMethodChecked', true, options);
|
||||
await supplier.updateAttribute('payDemFk', 1, options);
|
||||
const secondResult = await models.Supplier.findOne({where: {id: 442}}, options);
|
||||
|
||||
expect(firstResult.isPayMethodChecked).toEqual(false);
|
||||
expect(secondResult.isPayMethodChecked).toEqual(false);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue