cau 10041 update fixtures for workers and fix test
gitea/salix/dev This commit looks good Details

This commit is contained in:
Bernat 2019-03-07 07:51:29 +01:00
parent b04dc02c61
commit b709930db5
3 changed files with 61 additions and 57 deletions

View File

@ -204,6 +204,11 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city
(200, 'Missing', NULL, 'Missing man', 'Anton', 'The space', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1), (200, 'Missing', NULL, 'Missing man', 'Anton', 'The space', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1),
(400, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1); (400, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1);
INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `phone`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`)
SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'SILLA', 46460, 623111111, 1, CONCAT(name,'@verdnatura.es'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, CURDATE(), 1
FROM `account`.`role` `r`
WHERE `r`.`hasLogin` = 1;
INSERT INTO `vn`.`clientManaCache`(`clientFk`, `mana`, `dated`) INSERT INTO `vn`.`clientManaCache`(`clientFk`, `mana`, `dated`)
VALUES VALUES
( 101, 50, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), ( 101, 50, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)),
@ -258,6 +263,11 @@ INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `pr
(131, 'Missing', 'The space', 'Silla', 46460, 1, 1111111111, 222222222, 1, 200, 2, NULL, NULL, 0, 0), (131, 'Missing', 'The space', 'Silla', 46460, 1, 1111111111, 222222222, 1, 200, 2, NULL, NULL, 0, 0),
(132, 'Trash', 'New York city', 'Silla', 46460, 1, 1111111111, 222222222, 1, 400, 2, NULL, NULL, 0, 0); (132, 'Trash', 'New York city', 'Silla', 46460, 1, 1111111111, 222222222, 1, 400, 2, NULL, NULL, 0, 0);
INSERT INTO `vn`.`address`( `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `isActive`, `clientFk`, `agencyModeFk`, `isDefaultAddress`)
SELECT name, CONCAT(name, 'Street'), 'SILLA', 46460, 1, 1, id, 2, 1
FROM `account`.`role` `r`
WHERE `r`.`hasLogin` = 1;
UPDATE `vn`.`client` SET defaultAddressFk = 1 WHERE id = 101; UPDATE `vn`.`client` SET defaultAddressFk = 1 WHERE id = 101;
UPDATE `vn`.`client` SET defaultAddressFk = 2 WHERE id = 102; UPDATE `vn`.`client` SET defaultAddressFk = 2 WHERE id = 102;
UPDATE `vn`.`client` SET defaultAddressFk = 3 WHERE id = 103; UPDATE `vn`.`client` SET defaultAddressFk = 3 WHERE id = 103;
@ -271,6 +281,11 @@ UPDATE `vn`.`client` SET defaultAddressFk = 10 WHERE id = 110;
UPDATE `vn`.`client` SET defaultAddressFk = 11 WHERE id = 200; UPDATE `vn`.`client` SET defaultAddressFk = 11 WHERE id = 200;
UPDATE `vn`.`client` SET defaultAddressFk = 12 WHERE id = 400; UPDATE `vn`.`client` SET defaultAddressFk = 12 WHERE id = 400;
UPDATE `vn`.`client` `c`
JOIN `vn`.`address` `a` ON `a`.`clientFk` = `c`.`id`
SET `c`.`defaultAddressFk` = `a`.`id`
WHERE `defaultAddressFk` IS NULL;
INSERT INTO `vn`.`clientCredit`(`id`, `clientFk`, `workerFk`, `amount`, `created`) INSERT INTO `vn`.`clientCredit`(`id`, `clientFk`, `workerFk`, `amount`, `created`)
VALUES VALUES
(1 , 101, 5, 300, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), (1 , 101, 5, 300, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)),

View File

@ -29,22 +29,23 @@ module.exports = Self => {
} }
}); });
Self.isValidClient = async function(id) { Self.isValidClient = async id => {
let query = let query =
`SELECT r.name `SELECT r.name
FROM salix.Account A FROM salix.Account a
JOIN vn.client C ON A.id = C.id JOIN vn.client c ON a.id = c.id
JOIN salix.RoleMapping rm ON rm.principalId = A.id JOIN salix.RoleMapping rm ON rm.principalId = a.id
JOIN salix.Role r ON r.id = rm.roleId JOIN salix.Role r ON r.id = rm.roleId
WHERE A.id = ? AND C.isActive AND C.isTaxDataChecked`; WHERE a.id = ? AND c.isActive AND c.isTaxDataChecked`;
let roleNames = await Self.rawSql(query, [id]); let roleNames = await Self.rawSql(query, [id]);
if (!roleNames.length) return false;
roleNames.forEach(role => { let isEmployee = roleNames.findIndex(role => {
if (role.name === 'employee') return role.name === 'employee';
return false;
}); });
if (!roleNames.length || isEmployee > -1 ) return false;
return true; return true;
}; };
}; };

View File

@ -1,57 +1,45 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
describe('Client isValidClient', () => { describe('Client isValidClient', () => {
it('should call the isValidClient() method with a client id and receive true', done => { it('should call the isValidClient() method with a client id and receive true', async() => {
let id = 101; let id = 101;
app.models.Client.isValidClient(id) let result = await app.models.Client.isValidClient(id);
.then(result => {
expect(result).toBeTruthy(); expect(result).toBeTruthy();
done();
});
}); });
it('should call the isValidClient() method with a employee id and receive false', done => { it('should call the isValidClient() method with an employee id to receive false', async() => {
let id = 1; let id = 1;
app.models.Client.isValidClient(id) let result = await app.models.Client.isValidClient(id);
.then(result => {
expect(result).toBeFalsy(); expect(result).toBeFalsy();
done();
});
}); });
it('should call the isValidClient() method with a unexistant id and receive false', done => { it('should call the isValidClient() method with an unexistant id and receive false', async() => {
let id = 999999; let id = 999999;
app.models.Client.isValidClient(id) let result = await app.models.Client.isValidClient(id);
.then(result => {
expect(result).toBeFalsy(); expect(result).toBeFalsy();
done();
});
}); });
it('should call the isValidClient() method with a invalid id and receive false', done => { it('should call the isValidClient() method with an invalid id and receive false', async() => {
let id = 'Pepinillos'; let id = 'Pepinillos';
app.models.Client.isValidClient(id) let result = await app.models.Client.isValidClient(id);
.then(result => {
expect(result).toBeFalsy(); expect(result).toBeFalsy();
done();
});
}); });
it('should call the isValidClient() method with a customer id which isnt active and return false', done => { it('should call the isValidClient() method with a customer id which isnt active and return false', async() => {
let id = '106'; let id = '106';
app.models.Client.isValidClient(id) let result = await app.models.Client.isValidClient(id);
.then(result => {
expect(result).toBeFalsy(); expect(result).toBeFalsy();
done();
});
}); });
it('should call the isValidClient() method with a customer id which his data isnt verified and return false', done => { it('should call the isValidClient() method with a customer id which his data isnt verified and return false', async() => {
let id = '110'; let id = '110';
app.models.Client.isValidClient(id) let result = await app.models.Client.isValidClient(id);
.then(result => {
expect(result).toBeFalsy(); expect(result).toBeFalsy();
done();
});
}); });
}); });