59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
const {models} = require('vn-loopback/server/server');
|
|
|
|
describe('operator add()', () => {
|
|
const noOperator = 104;
|
|
const operator = 9;
|
|
|
|
beforeAll(async() => {
|
|
ctx = {
|
|
req: {
|
|
accessToken: {},
|
|
headers: {origin: 'http://localhost'},
|
|
__: value => value
|
|
}
|
|
};
|
|
});
|
|
|
|
it('should not add an existent operator', async() => {
|
|
const tx = await models.Operator.beginTransaction({});
|
|
const options = {transaction: tx};
|
|
ctx.req.accessToken.userId = operator;
|
|
|
|
try {
|
|
const operatorBefore = await models.Operator.find(null, options);
|
|
const isOperator = await models.Operator.findOne(null, options);
|
|
|
|
expect(isOperator).toBeDefined();
|
|
|
|
await models.Operator.add(ctx, options);
|
|
const operatorAfter = await models.Operator.find(null, options);
|
|
|
|
expect(operatorBefore.length).toEqual(operatorAfter.length);
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
}
|
|
});
|
|
|
|
it('should add a new operator successfully', async() => {
|
|
const tx = await models.Operator.beginTransaction({});
|
|
const options = {transaction: tx};
|
|
ctx.req.accessToken.userId = noOperator;
|
|
|
|
try {
|
|
const operatorBefore = await models.Operator.find(null, options);
|
|
await models.Operator.add(ctx, options);
|
|
const operatorAfter = await models.Operator.find(null, options);
|
|
|
|
const isOperator = await models.Operator.findOne(null, options);
|
|
|
|
expect(operatorBefore.length).toEqual(operatorAfter.length - 1);
|
|
expect(isOperator).toBeDefined();
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
});
|