2024-01-19 13:35:10 +00:00
|
|
|
const {models} = require('vn-loopback/server/server');
|
|
|
|
|
|
|
|
describe('operator add()', () => {
|
2024-01-19 13:44:07 +00:00
|
|
|
const itBoss = 104;
|
|
|
|
const noWorker = 100000;
|
|
|
|
|
2024-01-19 13:35:10 +00:00
|
|
|
beforeAll(async() => {
|
|
|
|
ctx = {
|
|
|
|
req: {
|
2024-01-19 13:44:07 +00:00
|
|
|
accessToken: {},
|
2024-01-19 13:35:10 +00:00
|
|
|
headers: {origin: 'http://localhost'},
|
|
|
|
__: value => value
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error if the worker does not exist', async() => {
|
|
|
|
const tx = await models.Operator.beginTransaction({});
|
|
|
|
const options = {transaction: tx};
|
2024-01-19 13:44:07 +00:00
|
|
|
ctx.req.accessToken.userId = noWorker;
|
2024-01-19 13:35:10 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
await models.Operator.add(ctx, options);
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
const error = e;
|
|
|
|
|
|
|
|
expect(error.message).toEqual('This worker does not exist');
|
|
|
|
await tx.rollback();
|
|
|
|
}
|
|
|
|
});
|
2024-01-19 13:44:07 +00:00
|
|
|
|
|
|
|
it('should add a new operator successfully', async() => {
|
|
|
|
const tx = await models.Operator.beginTransaction({});
|
|
|
|
const options = {transaction: tx};
|
|
|
|
ctx.req.accessToken.userId = itBoss;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
2024-01-19 13:35:10 +00:00
|
|
|
});
|