Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 5858-zone_Collisions

This commit is contained in:
Javier Segarra 2024-02-21 13:48:53 +01:00
commit e00133458b
2 changed files with 42 additions and 5 deletions

View File

@ -8,6 +8,25 @@ BEGIN
* @param vSaleGroupFk Identificador de vn.saleGroup * @param vSaleGroupFk Identificador de vn.saleGroup
* @param vSectorCollectionFk Identificador de vn.sectorCollection * @param vSectorCollectionFk Identificador de vn.sectorCollection
*/ */
DECLARE vHasSaleGroup INT;
DECLARE vHasSectorCollection INT;
SELECT COUNT(id) INTO vHasSaleGroup
FROM saleGroup
WHERE id = vSaleGroupFk;
IF !vHasSaleGroup THEN
CALL util.throw ("invalid saleGroup");
END IF;
SELECT COUNT(id) INTO vHasSectorCollection
FROM sectorCollection
WHERE id = vSectorCollectionFk;
IF !vHasSectorCollection THEN
CALL util.throw ("invalid sectorCollection");
END IF;
REPLACE sectorCollectionSaleGroup REPLACE sectorCollectionSaleGroup
SET sectorCollectionFk = vSectorCollectionFk, SET sectorCollectionFk = vSectorCollectionFk,
saleGroupFk = vSaleGroupFk; saleGroupFk = vSaleGroupFk;

View File

@ -36,6 +36,7 @@ describe('Worker new', () => {
payMethodFk: 1, payMethodFk: 1,
roleFk: 1 roleFk: 1
}; };
const req = {accessToken: {userId: 9}}; const req = {accessToken: {userId: 9}};
it('should return error if personal mail already exists', async() => { it('should return error if personal mail already exists', async() => {
@ -140,15 +141,24 @@ describe('Worker new', () => {
it('should create a new worker', async() => { it('should create a new worker', async() => {
const newWorker = await models.Worker.new({args: defaultWorker, req}); const newWorker = await models.Worker.new({args: defaultWorker, req});
await models.Worker.destroyById(newWorker.id); await removeWorker(newWorker.id);
await models.Address.destroyAll({clientFk: newWorker.id});
await models.Mandate.destroyAll({clientFk: newWorker.id});
await models.Client.destroyById(newWorker.id);
await models.VnUser.destroyById(newWorker.id);
expect(newWorker.id).toBeDefined(); expect(newWorker.id).toBeDefined();
}); });
it('should create a new client', async() => {
let newWorker;
let client;
try {
newWorker = await models.Worker.new({args: defaultWorker, req});
client = await models.Client.findById(newWorker.id);
} finally {
await removeWorker(newWorker.id);
}
expect(client).toBeDefined();
});
it('should create a new worker in client', async() => { it('should create a new worker in client', async() => {
const bruceWayneId = 1101; const bruceWayneId = 1101;
const client = await models.Client.findById(bruceWayneId, {fields: ['fi', 'email']}); const client = await models.Client.findById(bruceWayneId, {fields: ['fi', 'email']});
@ -170,3 +180,11 @@ describe('Worker new', () => {
expect(newWorker.id).toEqual(bruceWayneId); expect(newWorker.id).toEqual(bruceWayneId);
}); });
}); });
async function removeWorker(id) {
await models.Worker.destroyById(id);
await models.Address.destroyAll({clientFk: id});
await models.Mandate.destroyAll({clientFk: id});
await models.Client.destroyById(id);
await models.VnUser.destroyById(id);
}