feat: refs #6276 test operator_add
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-01-19 14:44:07 +01:00
parent 817a6b1289
commit 6e59a87f9c
1 changed files with 26 additions and 1 deletions

View File

@ -1,10 +1,13 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
describe('operator add()', () => { describe('operator add()', () => {
const itBoss = 104;
const noWorker = 100000;
beforeAll(async() => { beforeAll(async() => {
ctx = { ctx = {
req: { req: {
accessToken: {userId: 100000}, accessToken: {},
headers: {origin: 'http://localhost'}, headers: {origin: 'http://localhost'},
__: value => value __: value => value
} }
@ -14,6 +17,7 @@ describe('operator add()', () => {
it('should throw an error if the worker does not exist', async() => { it('should throw an error if the worker does not exist', async() => {
const tx = await models.Operator.beginTransaction({}); const tx = await models.Operator.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
ctx.req.accessToken.userId = noWorker;
try { try {
await models.Operator.add(ctx, options); await models.Operator.add(ctx, options);
@ -25,4 +29,25 @@ describe('operator add()', () => {
await tx.rollback(); 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 = 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;
}
});
}); });