Updated models

This commit is contained in:
Joan Sanchez 2023-01-24 09:04:43 +01:00
parent ee1ce21bb9
commit 89eb065f6d
48 changed files with 6006 additions and 28437 deletions

View File

@ -1,9 +1,9 @@
const app = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models;
describe('campaign latest()', () => {
it('should return the campaigns from the last year', async() => {
const now = new Date();
const result = await app.models.Campaign.latest();
const result = await models.Campaign.latest();
const randomIndex = Math.floor(Math.random() * result.length);
const campaignDated = result[randomIndex].dated;
@ -14,7 +14,7 @@ describe('campaign latest()', () => {
it('should return the campaigns from the current year', async() => {
const now = new Date();
const currentYear = now.getFullYear();
const result = await app.models.Campaign.latest({
const result = await models.Campaign.latest({
where: {dated: {like: `%${currentYear}%`}}
});

View File

@ -1,8 +1,8 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('campaign upcoming()', () => {
it('should return the upcoming campaign but from the last year', async() => {
const response = await app.models.Campaign.upcoming();
const response = await models.Campaign.upcoming();
const campaignDated = response.dated;
const now = new Date();

View File

@ -1,12 +1,12 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('Chat notifyIssue()', () => {
const ctx = {req: {accessToken: {userId: 1}}};
ctx.req.__ = value => {
return value;
};
const chatModel = app.models.Chat;
const osTicketModel = app.models.OsTicket;
const chatModel = models.Chat;
const osTicketModel = models.OsTicket;
const departmentId = 31;
it(`should not call to the send() method and neither return a response`, async() => {
@ -29,7 +29,7 @@ describe('Chat notifyIssue()', () => {
// eslint-disable-next-line max-len
const expectedMessage = `@all ➔ There's a new urgent ticket:\r\n[ID: 00001 - Issue title @batman](https://cau.verdnatura.es/scp/tickets.php?id=1)`;
const department = await app.models.Department.findById(departmentId);
const department = await models.Department.findById(departmentId);
let orgChatName = department.chatName;
await department.updateAttribute('chatName', 'IT');

View File

@ -1,16 +1,16 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('Chat send()', () => {
it('should return true as response', async() => {
let ctx = {req: {accessToken: {userId: 1}}};
let response = await app.models.Chat.send(ctx, '@salesPerson', 'I changed something');
let response = await models.Chat.send(ctx, '@salesPerson', 'I changed something');
expect(response).toEqual(true);
});
it('should return false as response', async() => {
let ctx = {req: {accessToken: {userId: 18}}};
let response = await app.models.Chat.send(ctx, '@salesPerson', 'I changed something');
let response = await models.Chat.send(ctx, '@salesPerson', 'I changed something');
expect(response).toEqual(false);
});

View File

@ -1,8 +1,8 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('getSectors()', () => {
it('return list of sectors', async() => {
let response = await app.models.Collection.getSectors();
let response = await models.Collection.getSectors();
expect(response.length).toBeGreaterThan(0);
expect(response[0].id).toEqual(1);

View File

@ -1,10 +1,10 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('newCollection()', () => {
it('should return a new collection', async() => {
pending('#3400 analizar que hacer con rutas de back collection');
let ctx = {req: {accessToken: {userId: 1106}}};
let response = await app.models.Collection.newCollection(ctx, 1, 1, 1);
let response = await models.Collection.newCollection(ctx, 1, 1, 1);
expect(response.length).toBeGreaterThan(0);
expect(response[0].ticketFk).toEqual(2);

View File

@ -1,4 +1,4 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('dms downloadFile()', () => {
let dmsId = 1;
@ -6,7 +6,7 @@ describe('dms downloadFile()', () => {
it('should return a response for an employee with text content-type', async() => {
let workerId = 1107;
let ctx = {req: {accessToken: {userId: workerId}}};
const result = await app.models.Dms.downloadFile(ctx, dmsId);
const result = await models.Dms.downloadFile(ctx, dmsId);
expect(result[1]).toEqual('text/plain');
});
@ -16,7 +16,7 @@ describe('dms downloadFile()', () => {
let ctx = {req: {accessToken: {userId: clientId}}};
let error;
await app.models.Dms.downloadFile(ctx, dmsId).catch(e => {
await models.Dms.downloadFile(ctx, dmsId).catch(e => {
error = e;
}).finally(() => {
expect(error.message).toEqual(`You don't have enough privileges`);

View File

@ -1,4 +1,4 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('dms removeFile()', () => {
let dmsId = 1;
@ -8,7 +8,7 @@ describe('dms removeFile()', () => {
let ctx = {req: {accessToken: {userId: clientId}}};
let error;
await app.models.Dms.removeFile(ctx, dmsId).catch(e => {
await models.Dms.removeFile(ctx, dmsId).catch(e => {
error = e;
}).finally(() => {
expect(error.message).toEqual(`You don't have enough privileges`);

View File

@ -1,4 +1,4 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('dms updateFile()', () => {
it(`should return an error for a user without enough privileges`, async() => {
@ -11,7 +11,7 @@ describe('dms updateFile()', () => {
let ctx = {req: {accessToken: {userId: clientId}}, args: {dmsTypeId: dmsTypeId}};
let error;
await app.models.Dms.updateFile(ctx, dmsId, warehouseId, companyId, dmsTypeId).catch(e => {
await models.Dms.updateFile(ctx, dmsId, warehouseId, companyId, dmsTypeId).catch(e => {
error = e;
}).finally(() => {
expect(error.message).toEqual(`You don't have enough privileges`);

View File

@ -1,4 +1,4 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('dms uploadFile()', () => {
it(`should return an error for a user without enough privileges`, async() => {
@ -7,7 +7,7 @@ describe('dms uploadFile()', () => {
let ctx = {req: {accessToken: {userId: clientId}}, args: {dmsTypeId: ticketDmsTypeId}};
let error;
await app.models.Dms.uploadFile(ctx).catch(e => {
await models.Dms.uploadFile(ctx).catch(e => {
error = e;
}).finally(() => {
expect(error.message).toEqual(`You don't have enough privileges`);

View File

@ -1,4 +1,4 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('image download()', () => {
const collection = 'user';
@ -8,7 +8,7 @@ describe('image download()', () => {
it('should return the image content-type of the user', async() => {
const userId = 9;
const image = await app.models.Image.download(ctx, collection, size, userId);
const image = await models.Image.download(ctx, collection, size, userId);
const contentType = image[1];
expect(contentType).toEqual('image/png');
@ -16,7 +16,7 @@ describe('image download()', () => {
it(`should return false if the user doesn't have image`, async() => {
const userId = 1110;
const image = await app.models.Image.download(ctx, collection, size, userId);
const image = await models.Image.download(ctx, collection, size, userId);
expect(image).toBeFalse();
});

View File

@ -1,4 +1,4 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('image upload()', () => {
describe('as buyer', () => {
@ -16,7 +16,7 @@ describe('image upload()', () => {
let error;
try {
await app.models.Image.upload(ctx);
await models.Image.upload(ctx);
} catch (err) {
error = err;
}
@ -25,7 +25,7 @@ describe('image upload()', () => {
});
it('should call to the TempContainer upload method for the collection "catalog"', async() => {
const containerModel = app.models.TempContainer;
const containerModel = models.TempContainer;
spyOn(containerModel, 'upload');
const ctx = {req: {accessToken: {userId: buyerId}},
@ -36,7 +36,7 @@ describe('image upload()', () => {
};
try {
await app.models.Image.upload(ctx);
await models.Image.upload(ctx);
} catch (err) { }
expect(containerModel.upload).toHaveBeenCalled();
@ -49,7 +49,7 @@ describe('image upload()', () => {
const itemId = 4;
it('should be able to call to the TempContainer upload method for the collection "user"', async() => {
const containerModel = app.models.TempContainer;
const containerModel = models.TempContainer;
spyOn(containerModel, 'upload');
const ctx = {req: {accessToken: {userId: marketingId}},
@ -60,14 +60,14 @@ describe('image upload()', () => {
};
try {
await app.models.Image.upload(ctx);
await models.Image.upload(ctx);
} catch (err) { }
expect(containerModel.upload).toHaveBeenCalled();
});
it('should be able to call to the TempContainer upload method for the collection "catalog"', async() => {
const containerModel = app.models.TempContainer;
const containerModel = models.TempContainer;
spyOn(containerModel, 'upload');
const ctx = {req: {accessToken: {userId: marketingId}},
@ -78,7 +78,7 @@ describe('image upload()', () => {
};
try {
await app.models.Image.upload(ctx);
await models.Image.upload(ctx);
} catch (err) { }
expect(containerModel.upload).toHaveBeenCalled();
@ -91,7 +91,7 @@ describe('image upload()', () => {
const itemId = 4;
it('should upload a file for the collection "user" and call to the TempContainer upload method', async() => {
const containerModel = app.models.TempContainer;
const containerModel = models.TempContainer;
spyOn(containerModel, 'upload');
const ctx = {req: {accessToken: {userId: hhrrId}},
@ -102,7 +102,7 @@ describe('image upload()', () => {
};
try {
await app.models.Image.upload(ctx);
await models.Image.upload(ctx);
} catch (err) { }
expect(containerModel.upload).toHaveBeenCalled();
@ -118,7 +118,7 @@ describe('image upload()', () => {
let error;
try {
await app.models.Image.upload(ctx);
await models.Image.upload(ctx);
} catch (err) {
error = err;
}

View File

@ -1,4 +1,4 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('getStarredModules()', () => {
@ -19,13 +19,13 @@ describe('getStarredModules()', () => {
});
it(`should return the starred modules for a given user`, async() => {
const newStarred = await app.models.StarredModule.create({workerFk: 9, moduleFk: 'customer', position: 1});
const starredModules = await app.models.StarredModule.getStarredModules(ctx);
const newStarred = await models.StarredModule.create({workerFk: 9, moduleFk: 'customer', position: 1});
const starredModules = await models.StarredModule.getStarredModules(ctx);
expect(starredModules.length).toEqual(1);
expect(starredModules[0].moduleFk).toEqual('customer');
// restores
await app.models.StarredModule.destroyById(newStarred.id);
await models.StarredModule.destroyById(newStarred.id);
});
});

View File

@ -1,4 +1,4 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('setPosition()', () => {
@ -21,7 +21,7 @@ describe('setPosition()', () => {
});
it('should increase the orders module position by replacing it with clients and vice versa', async() => {
const tx = await app.models.StarredModule.beginTransaction({});
const tx = await models.StarredModule.beginTransaction({});
const filter = {
where: {
@ -32,24 +32,24 @@ describe('setPosition()', () => {
try {
const options = {transaction: tx};
await app.models.StarredModule.toggleStarredModule(ctx, 'order', options);
await app.models.StarredModule.toggleStarredModule(ctx, 'customer', options);
await models.StarredModule.toggleStarredModule(ctx, 'order', options);
await models.StarredModule.toggleStarredModule(ctx, 'customer', options);
let orders = await app.models.StarredModule.findOne(filter, options);
let orders = await models.StarredModule.findOne(filter, options);
filter.where.moduleFk = 'customer';
let clients = await app.models.StarredModule.findOne(filter, options);
let clients = await models.StarredModule.findOne(filter, options);
expect(orders.position).toEqual(1);
expect(clients.position).toEqual(2);
await app.models.StarredModule.setPosition(ctx, 'customer', 'left', options);
await models.StarredModule.setPosition(ctx, 'customer', 'left', options);
filter.where.moduleFk = 'customer';
clients = await app.models.StarredModule.findOne(filter, options);
clients = await models.StarredModule.findOne(filter, options);
filter.where.moduleFk = 'order';
orders = await app.models.StarredModule.findOne(filter, options);
orders = await models.StarredModule.findOne(filter, options);
expect(clients.position).toEqual(1);
expect(orders.position).toEqual(2);
@ -62,7 +62,7 @@ describe('setPosition()', () => {
});
it('should decrease the orders module position by replacing it with clients and vice versa', async() => {
const tx = await app.models.StarredModule.beginTransaction({});
const tx = await models.StarredModule.beginTransaction({});
const filter = {
where: {
@ -73,24 +73,24 @@ describe('setPosition()', () => {
try {
const options = {transaction: tx};
await app.models.StarredModule.toggleStarredModule(ctx, 'order', options);
await app.models.StarredModule.toggleStarredModule(ctx, 'customer', options);
await models.StarredModule.toggleStarredModule(ctx, 'order', options);
await models.StarredModule.toggleStarredModule(ctx, 'customer', options);
let orders = await app.models.StarredModule.findOne(filter, options);
let orders = await models.StarredModule.findOne(filter, options);
filter.where.moduleFk = 'customer';
let clients = await app.models.StarredModule.findOne(filter, options);
let clients = await models.StarredModule.findOne(filter, options);
expect(orders.position).toEqual(1);
expect(clients.position).toEqual(2);
await app.models.StarredModule.setPosition(ctx, 'order', 'right', options);
await models.StarredModule.setPosition(ctx, 'order', 'right', options);
filter.where.moduleFk = 'order';
orders = await app.models.StarredModule.findOne(filter, options);
orders = await models.StarredModule.findOne(filter, options);
filter.where.moduleFk = 'customer';
clients = await app.models.StarredModule.findOne(filter, options);
clients = await models.StarredModule.findOne(filter, options);
expect(orders.position).toEqual(2);
expect(clients.position).toEqual(1);
@ -103,7 +103,7 @@ describe('setPosition()', () => {
});
it('should switch two modules after adding and deleting several modules', async() => {
const tx = await app.models.StarredModule.beginTransaction({});
const tx = await models.StarredModule.beginTransaction({});
const filter = {
where: {
@ -115,29 +115,29 @@ describe('setPosition()', () => {
try {
const options = {transaction: tx};
await app.models.StarredModule.toggleStarredModule(ctx, 'customer', options);
await app.models.StarredModule.toggleStarredModule(ctx, 'order', options);
await app.models.StarredModule.toggleStarredModule(ctx, 'customer', options);
await app.models.StarredModule.toggleStarredModule(ctx, 'order', options);
await app.models.StarredModule.toggleStarredModule(ctx, 'item', options);
await app.models.StarredModule.toggleStarredModule(ctx, 'claim', options);
await app.models.StarredModule.toggleStarredModule(ctx, 'customer', options);
await app.models.StarredModule.toggleStarredModule(ctx, 'order', options);
await app.models.StarredModule.toggleStarredModule(ctx, 'zone', options);
await models.StarredModule.toggleStarredModule(ctx, 'customer', options);
await models.StarredModule.toggleStarredModule(ctx, 'order', options);
await models.StarredModule.toggleStarredModule(ctx, 'customer', options);
await models.StarredModule.toggleStarredModule(ctx, 'order', options);
await models.StarredModule.toggleStarredModule(ctx, 'item', options);
await models.StarredModule.toggleStarredModule(ctx, 'claim', options);
await models.StarredModule.toggleStarredModule(ctx, 'customer', options);
await models.StarredModule.toggleStarredModule(ctx, 'order', options);
await models.StarredModule.toggleStarredModule(ctx, 'zone', options);
const items = await app.models.StarredModule.findOne(filter, options);
const items = await models.StarredModule.findOne(filter, options);
filter.where.moduleFk = 'claim';
const claims = await app.models.StarredModule.findOne(filter, options);
const claims = await models.StarredModule.findOne(filter, options);
filter.where.moduleFk = 'customer';
let clients = await app.models.StarredModule.findOne(filter, options);
let clients = await models.StarredModule.findOne(filter, options);
filter.where.moduleFk = 'order';
let orders = await app.models.StarredModule.findOne(filter, options);
let orders = await models.StarredModule.findOne(filter, options);
filter.where.moduleFk = 'zone';
const zones = await app.models.StarredModule.findOne(filter, options);
const zones = await models.StarredModule.findOne(filter, options);
expect(items.position).toEqual(1);
expect(claims.position).toEqual(2);
@ -145,13 +145,13 @@ describe('setPosition()', () => {
expect(orders.position).toEqual(4);
expect(zones.position).toEqual(5);
await app.models.StarredModule.setPosition(ctx, 'customer', 'right', options);
await models.StarredModule.setPosition(ctx, 'customer', 'right', options);
filter.where.moduleFk = 'order';
orders = await app.models.StarredModule.findOne(filter, options);
orders = await models.StarredModule.findOne(filter, options);
filter.where.moduleFk = 'customer';
clients = await app.models.StarredModule.findOne(filter, options);
clients = await models.StarredModule.findOne(filter, options);
expect(orders.position).toEqual(3);
expect(clients.position).toEqual(4);
@ -164,7 +164,7 @@ describe('setPosition()', () => {
});
it('should switch two modules after adding and deleting a module between them', async() => {
const tx = await app.models.StarredModule.beginTransaction({});
const tx = await models.StarredModule.beginTransaction({});
const filter = {
where: {
@ -176,25 +176,25 @@ describe('setPosition()', () => {
try {
const options = {transaction: tx};
await app.models.StarredModule.toggleStarredModule(ctx, 'item', options);
await app.models.StarredModule.toggleStarredModule(ctx, 'customer', options);
await app.models.StarredModule.toggleStarredModule(ctx, 'claim', options);
await app.models.StarredModule.toggleStarredModule(ctx, 'order', options);
await app.models.StarredModule.toggleStarredModule(ctx, 'zone', options);
await models.StarredModule.toggleStarredModule(ctx, 'item', options);
await models.StarredModule.toggleStarredModule(ctx, 'customer', options);
await models.StarredModule.toggleStarredModule(ctx, 'claim', options);
await models.StarredModule.toggleStarredModule(ctx, 'order', options);
await models.StarredModule.toggleStarredModule(ctx, 'zone', options);
const items = await app.models.StarredModule.findOne(filter, options);
const items = await models.StarredModule.findOne(filter, options);
filter.where.moduleFk = 'customer';
let clients = await app.models.StarredModule.findOne(filter, options);
let clients = await models.StarredModule.findOne(filter, options);
filter.where.moduleFk = 'claim';
const claims = await app.models.StarredModule.findOne(filter, options);
const claims = await models.StarredModule.findOne(filter, options);
filter.where.moduleFk = 'order';
let orders = await app.models.StarredModule.findOne(filter, options);
let orders = await models.StarredModule.findOne(filter, options);
filter.where.moduleFk = 'zone';
const zones = await app.models.StarredModule.findOne(filter, options);
const zones = await models.StarredModule.findOne(filter, options);
expect(items.position).toEqual(1);
expect(clients.position).toEqual(2);
@ -202,14 +202,14 @@ describe('setPosition()', () => {
expect(orders.position).toEqual(4);
expect(zones.position).toEqual(5);
await app.models.StarredModule.toggleStarredModule(ctx, 'claim', options);
await app.models.StarredModule.setPosition(ctx, 'customer', 'right', options);
await models.StarredModule.toggleStarredModule(ctx, 'claim', options);
await models.StarredModule.setPosition(ctx, 'customer', 'right', options);
filter.where.moduleFk = 'customer';
clients = await app.models.StarredModule.findOne(filter, options);
clients = await models.StarredModule.findOne(filter, options);
filter.where.moduleFk = 'order';
orders = await app.models.StarredModule.findOne(filter, options);
orders = await models.StarredModule.findOne(filter, options);
expect(orders.position).toEqual(2);
expect(clients.position).toEqual(4);

View File

@ -1,4 +1,4 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('toggleStarredModule()', () => {
@ -21,16 +21,16 @@ describe('toggleStarredModule()', () => {
});
it('should create a new starred module and then remove it by calling the method again with same args', async() => {
const starredModule = await app.models.StarredModule.toggleStarredModule(ctx, 'order');
let starredModules = await app.models.StarredModule.getStarredModules(ctx);
const starredModule = await models.StarredModule.toggleStarredModule(ctx, 'order');
let starredModules = await models.StarredModule.getStarredModules(ctx);
expect(starredModules.length).toEqual(1);
expect(starredModule.moduleFk).toEqual('order');
expect(starredModule.workerFk).toEqual(activeCtx.accessToken.userId);
expect(starredModule.position).toEqual(starredModules.length);
await app.models.StarredModule.toggleStarredModule(ctx, 'order');
starredModules = await app.models.StarredModule.getStarredModules(ctx);
await models.StarredModule.toggleStarredModule(ctx, 'order');
starredModules = await models.StarredModule.getStarredModules(ctx);
expect(starredModules.length).toEqual(0);
});

View File

@ -1,25 +1,25 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('account login()', () => {
describe('when credentials are correct', () => {
it('should return the token', async() => {
let login = await app.models.VnUser.login('salesAssistant', 'nightmare');
let accessToken = await app.models.AccessToken.findById(login.token);
let login = await models.VnUser.login('salesAssistant', 'nightmare');
let accessToken = await models.AccessToken.findById(login.token);
let ctx = {req: {accessToken: accessToken}};
expect(login.token).toBeDefined();
await app.models.VnUser.logout(ctx);
await models.VnUser.logout(ctx);
});
it('should return the token if the user doesnt exist but the client does', async() => {
let login = await app.models.VnUser.login('PetterParker', 'nightmare');
let accessToken = await app.models.AccessToken.findById(login.token);
let login = await models.VnUser.login('PetterParker', 'nightmare');
let accessToken = await models.AccessToken.findById(login.token);
let ctx = {req: {accessToken: accessToken}};
expect(login.token).toBeDefined();
await app.models.VnUser.logout(ctx);
await models.VnUser.logout(ctx);
});
});
@ -28,7 +28,7 @@ describe('account login()', () => {
let error;
try {
await app.models.VnUser.login('IDontExist', 'TotallyWrongPassword');
await models.VnUser.login('IDontExist', 'TotallyWrongPassword');
} catch (e) {
error = e;
}

View File

@ -1,13 +1,13 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('account logout()', () => {
it('should logout and remove token after valid login', async() => {
let loginResponse = await app.models.VnUser.login('buyer', 'nightmare');
let accessToken = await app.models.AccessToken.findById(loginResponse.token);
let loginResponse = await models.VnUser.login('buyer', 'nightmare');
let accessToken = await models.AccessToken.findById(loginResponse.token);
let ctx = {req: {accessToken: accessToken}};
let logoutResponse = await app.models.VnUser.logout(ctx);
let tokenAfterLogout = await app.models.AccessToken.findById(loginResponse.token);
let logoutResponse = await models.VnUser.logout(ctx);
let tokenAfterLogout = await models.AccessToken.findById(loginResponse.token);
expect(logoutResponse).toBeTrue();
expect(tokenAfterLogout).toBeNull();
@ -18,7 +18,7 @@ describe('account logout()', () => {
let ctx = {req: {accessToken: {id: 'invalidToken'}}};
try {
response = await app.models.VnUser.logout(ctx);
response = await models.VnUser.logout(ctx);
} catch (e) {
error = e;
}
@ -32,7 +32,7 @@ describe('account logout()', () => {
let ctx = {req: {accessToken: null}};
try {
response = await app.models.VnUser.logout(ctx);
response = await models.VnUser.logout(ctx);
} catch (e) {
error = e;
}

View File

@ -1,14 +1,14 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('VnUser setPassword()', () => {
it('should throw an error when password does not meet requirements', async() => {
let req = app.models.VnUser.setPassword(1, 'insecurePass');
let req = models.VnUser.setPassword(1, 'insecurePass');
await expectAsync(req).toBeRejected();
});
it('should update password when it passes requirements', async() => {
let req = app.models.VnUser.setPassword(1, 'Very$ecurePa22.');
let req = models.VnUser.setPassword(1, 'Very$ecurePa22.');
await expectAsync(req).toBeResolved();
});

View File

@ -20,7 +20,7 @@
"relations": {
"user": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "userFk"
}
},

View File

@ -31,7 +31,7 @@
},
"author": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "authorFk"
}
}

View File

@ -26,7 +26,7 @@
},
"user": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "userFk"
}
}

View File

@ -1,8 +1,8 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('loopback model Company', () => {
it('should check that the company FTH doesnt exists', async() => {
let result = await app.models.Company.findOne({where: {code: 'FTH'}});
let result = await models.Company.findOne({where: {code: 'FTH'}});
expect(result).toBeFalsy();
});

View File

@ -1,6 +1,6 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('Dms', () => {
const Dms = app.models.Dms;
const Dms = models.Dms;
describe('getFile()', () => {
it('should return a response with text content-type', async() => {
@ -23,7 +23,7 @@ describe('Dms', () => {
it('should return an error for a record does not exists', async() => {
let error = {};
try {
await app.models.Dms.getFile('NotExistentId');
await models.Dms.getFile('NotExistentId');
} catch (e) {
error = e;
}

View File

@ -26,7 +26,7 @@
"relations": {
"user": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "userFk"
}
}

View File

@ -39,9 +39,9 @@
"model": "Company",
"foreignKey": "companyFk"
},
"account": {
"VnUser": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "userFk"
}
}

View File

@ -48,7 +48,7 @@
"relations": {
"user": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "userFk"
}
},

View File

@ -1,7 +1,7 @@
const md5 = require('md5');
// const vnModel = require('vn-loopback/common/mixins/vn-model');
const vnModel = require('vn-loopback/common/models/vn-model');
module.exports = function(Self) {
// vnModel(Self);
vnModel(Self);
require('../methods/vn-user/signIn')(Self);
require('../methods/vn-user/signOut')(Self);

View File

@ -25,16 +25,16 @@ module.exports = Self => {
});
Self.sync = async function(userName, password, force) {
let $ = Self.app.models;
let user = await $.VnUser.findOne({
const models = Self.app.models;
const user = await models.VnUser.findOne({
fields: ['id'],
where: {name: userName}
});
let isSync = !await $.UserSync.exists(userName);
const isSync = !await models.UserSync.exists(userName);
if (!force && isSync && user) return;
await $.AccountConfig.syncUser(userName, password);
await $.UserSync.destroyById(userName);
await models.AccountConfig.syncUser(userName, password);
await models.UserSync.destroyById(userName);
};
};

View File

@ -1,9 +1,9 @@
{
"name": "MailAliasAccount",
"name": "MailAliasVnUser",
"base": "VnModel",
"options": {
"mysql": {
"table": "account.mailAliasAccount"
"table": "VnUser.mailAliasVnUser"
}
},
"properties": {
@ -20,8 +20,8 @@
},
"user": {
"type": "belongsTo",
"model": "Account",
"foreignKey": "account"
"model": "VnUser",
"foreignKey": "VnUser"
}
}
}

View File

@ -3,11 +3,11 @@
"base": "VnModel",
"options": {
"mysql": {
"table": "account.mailForward"
"table": "VnUser.mailForward"
}
},
"properties": {
"account": {
"VnUser": {
"id": true
},
"forwardTo": {
@ -18,8 +18,8 @@
"relations": {
"user": {
"type": "belongsTo",
"model": "Account",
"foreignKey": "account"
"model": "VnUser",
"foreignKey": "VnUser"
}
}
}

View File

@ -23,7 +23,7 @@
"relations": {
"user": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "user_id"
}
}

View File

@ -1,9 +1,9 @@
{
"name": "UserAccount",
"name": "UserVnUser",
"base": "VnModel",
"options": {
"mysql": {
"table": "account.account"
"table": "VnUser.VnUser"
}
},
"properties": {
@ -14,13 +14,13 @@
"relations": {
"user": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "id"
},
"aliases": {
"type": "hasMany",
"model": "MailAliasAccount",
"foreignKey": "account"
"model": "MailAliasVnUser",
"foreignKey": "VnUser"
}
}
}

View File

@ -48,7 +48,7 @@
"relations": {
"user": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "userFk"
}
},

View File

@ -48,7 +48,7 @@
"relations": {
"user": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "userFk"
}
},

View File

@ -34,12 +34,12 @@
},
"user": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "userFk"
},
"account": {
"VnUser": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "userFk"
},
"company": {

View File

@ -116,7 +116,7 @@
"isRelevant": {
"type": "boolean"
},
"accountingAccount": {
"VnUseringVnUser": {
"type": "string"
},
"created": {
@ -149,9 +149,9 @@
},
"relations": {
"account": {
"VnUser": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "id"
},
"payMethod": {
@ -161,7 +161,7 @@
},
"salesPersonUser": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "salesPersonFk"
},
"province": {

View File

@ -54,7 +54,7 @@
},
"user": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "userFk"
}
}

View File

@ -38,7 +38,7 @@
"relations": {
"sender": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "senderFk"
}
}

View File

@ -16,7 +16,7 @@
"type": "date",
"required": true
},
"isAccountable": {
"isVnUserable": {
"type": "boolean"
},
"serie": {
@ -51,7 +51,7 @@
},
"worker": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "workerFk"
},
"company": {

View File

@ -48,7 +48,7 @@
"relations": {
"user": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "userFk"
}
},

View File

@ -48,7 +48,7 @@
"relations": {
"user": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "userFk"
}
},

View File

@ -21,10 +21,10 @@
"type": "array"
},
"defaultPriority": {
"type": "int"
"type": "number"
},
"defaultTag": {
"type": "int"
"type": "number"
}
},
"relations": {

View File

@ -1,16 +1,16 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('AgencyMode byWarehhouse()', () => {
const warehouseId = 1;
it('should return all the agencies', async() => {
const where = {};
const tx = await app.models.Zone.beginTransaction({});
const tx = await models.Zone.beginTransaction({});
try {
const options = {transaction: tx};
const agencies = await app.models.AgencyMode.byWarehouse({where}, options);
const agencies = await models.AgencyMode.byWarehouse({where}, options);
expect(agencies.length).toBeGreaterThan(10);
@ -24,12 +24,12 @@ describe('AgencyMode byWarehhouse()', () => {
it('should return only the agencies for a warehouse', async() => {
const where = {warehouseFk: warehouseId};
const tx = await app.models.Zone.beginTransaction({});
const tx = await models.Zone.beginTransaction({});
try {
const options = {transaction: tx};
const agencies = await app.models.AgencyMode.byWarehouse({where}, options);
const agencies = await models.AgencyMode.byWarehouse({where}, options);
const validWarehouse = agencies.every(agency => agency.warehouseFk = warehouseId);
expect(agencies.length).toEqual(6);

View File

@ -1,4 +1,4 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('agency getShipped()', () => {
it('should return a shipment date', async() => {
@ -8,12 +8,12 @@ describe('agency getShipped()', () => {
const agencyModeFk = 7;
const warehouseFk = 1;
const tx = await app.models.Agency.beginTransaction({});
const tx = await models.Agency.beginTransaction({});
try {
const options = {transaction: tx};
const result = await app.models.Agency.getShipped(landed, addressFk, agencyModeFk, warehouseFk, options);
const result = await models.Agency.getShipped(landed, addressFk, agencyModeFk, warehouseFk, options);
expect(result).toBeDefined();
@ -32,12 +32,12 @@ describe('agency getShipped()', () => {
const agencyModeFk = 7;
const warehouseFk = 1;
const tx = await app.models.Agency.beginTransaction({});
const tx = await models.Agency.beginTransaction({});
try {
const options = {transaction: tx};
const result = await app.models.Agency.getShipped(landed, addressFk, agencyModeFk, warehouseFk, options);
const result = await models.Agency.getShipped(landed, addressFk, agencyModeFk, warehouseFk, options);
expect(result).toBeUndefined();

View File

@ -1,14 +1,14 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
describe('Agency landsThatDay()', () => {
const today = new Date();
it('should return a list of agencies that can land a shipment on a day for an address', async() => {
const tx = await app.models.Agency.beginTransaction({});
const tx = await models.Agency.beginTransaction({});
try {
const options = {transaction: tx};
const agencies = await app.models.Agency.landsThatDay(101, today, options);
const agencies = await models.Agency.landsThatDay(101, today, options);
expect(agencies.length).toBeGreaterThanOrEqual(3);

View File

@ -1,11 +1,11 @@
const app = require('vn-loopback/server/server');
const {models} = require('vn-loopback/server/server');
module.exports = Self => {
app.on('started', function() {
let models = ['Zone', 'ZoneEvent', 'ZoneExclusion'];
for (let modelName of models) {
let Model = app.models[modelName];
let Model = models[modelName];
Model.observe('after save', doCalc);
Model.observe('after delete', doCalc);

View File

@ -48,7 +48,7 @@
"relations": {
"user": {
"type": "belongsTo",
"model": "Account",
"model": "VnUser",
"foreignKey": "userFk"
}
},

34079
package-lock.json generated

File diff suppressed because it is too large Load Diff