feat: refs #7821 with test
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Javi Gallego 2024-11-21 09:12:04 +01:00
parent a40a5a22ab
commit b3ce3a0cc2
3 changed files with 107 additions and 7 deletions

View File

@ -28,9 +28,10 @@ describe('ticket assign()', () => {
await tx.rollback(); await tx.rollback();
}); });
it('should throw an error when there is not picking tickets', async() => { it('should throw an error when there are no picking tickets', async() => {
try { try {
await models.Collection.assign(ctx, options); await models.Collection.assign(ctx, options);
fail('Expected an error to be thrown, but none was thrown.');
} catch (e) { } catch (e) {
expect(e.message).toEqual('There are not picking tickets'); expect(e.message).toEqual('There are not picking tickets');
} }

View File

@ -9,16 +9,18 @@ BEGIN
* *
* @param vSelf Id de entrada * @param vSelf Id de entrada
*/ */
DECLARE vIsNotEditable BOOL; DECLARE vIsNotEditable BOOL DEFAULT FALSE;
SELECT (e.typeFk IS NULL OR NOT et.isInformal) INTO vIsNotEditable SELECT TRUE INTO vIsNotEditable
FROM `entry` e FROM `entry` e
LEFT JOIN entryType et ON et.code = e.typeFk LEFT JOIN entryType et ON et.code = e.typeFk
WHERE e.id = vSelf WHERE e.id = vSelf
AND e.isBooked; AND e.isBooked
AND (e.typeFk IS NULL OR NOT et.isInformal);
IF vIsNotEditable AND NOT IFNULL(@isModeInventory, FALSE) THEN IF vIsNotEditable AND NOT IFNULL(@isModeInventory, FALSE) THEN
CALL util.throw(CONCAT('Entry ', vSelf, ' is not editable')); CALL util.throw(CONCAT('Entry ', vSelf, ' is not editable'));
END IF; END IF;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -0,0 +1,97 @@
const {models} = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('entry_isEditable trigger', () => {
const activeCtx = {
accessToken: {userId: 5},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
const ctx = {req: activeCtx};
const entryId = 1;
let tx;
let options;
let entry;
beforeEach(async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: ctx.req});
tx = await models.Entry.beginTransaction({});
options = {transaction: tx};
entry = await models.Entry.findById(entryId, null, options);
});
afterEach(async() => {
await tx.rollback();
});
async function prepareEntry(isBooked, typeFk) {
let newCreated = Date.vnNew();
await entry.updateAttributes({isBooked, typeFk}, options);
await entry.updateAttributes({dated: newCreated}, options);
}
it('should throw an error when entry is booked and typeFk is null', async() => {
let error;
try {
await prepareEntry(true, null);
} catch (e) {
error = e;
}
expect(error.message).toContain(`Entry ${entryId} is not editable`);
});
it('should throw an error when entry is booked and typeFk is not informal', async() => {
let error;
try {
const type = await models.EntryType.findOne({where: {isInformal: false}}, options);
await prepareEntry(true, type.code);
} catch (e) {
error = e;
}
expect(error.message).toContain(`Entry ${entryId} is not editable`);
});
it('should not throw an error when entry is booked and typeFk is informal', async() => {
let error;
try {
const type = await models.EntryType.findOne({where: {isInformal: true}}, options);
await prepareEntry(true, type.code);
} catch (e) {
error = e;
}
expect(error).toBeUndefined();
});
it('should not throw an error when entry is not booked', async() => {
let error;
try {
const type = await models.EntryType.findOne({}, options);
await prepareEntry(false, type.code);
} catch (e) {
error = e;
}
expect(error).toBeUndefined();
});
it('should not throw an error when @isModeInventory is true', async() => {
let error;
try {
await models.Application.rawSql('SET @isModeInventory = TRUE;', null, options);
await prepareEntry(true, null);
} catch (e) {
error = e;
} finally {
await models.Application.rawSql('SET @isModeInventory = FALSE;', null, options);
}
expect(error).toBeUndefined();
});
});