2021-03-23 15:19:45 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2021-03-24 11:45:26 +00:00
|
|
|
const LoopBackContext = require('loopback-context');
|
|
|
|
|
|
|
|
describe('Client Model', () => {
|
|
|
|
const activeCtx = {
|
|
|
|
accessToken: {userId: 9},
|
|
|
|
http: {
|
|
|
|
req: {
|
|
|
|
headers: {origin: 'http://localhost'},
|
|
|
|
[`__`]: value => {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const ctx = {req: activeCtx};
|
|
|
|
const chatModel = app.models.Chat;
|
2021-06-23 11:24:23 +00:00
|
|
|
const client = {id: 1101, name: 'Bruce Banner'};
|
|
|
|
const previousWorkerId = 1106; // DavidCharlesHaller
|
|
|
|
const currentWorkerId = 1107; // HankPym
|
2021-03-24 11:45:26 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
|
|
|
active: activeCtx
|
|
|
|
});
|
2021-03-23 15:19:45 +00:00
|
|
|
});
|
|
|
|
|
2021-03-24 11:45:26 +00:00
|
|
|
describe('notifyAssignment()', () => {
|
|
|
|
it('should call to the Chat send() method for both workers', async() => {
|
|
|
|
spyOn(chatModel, 'send').and.callThrough();
|
2021-03-23 15:19:45 +00:00
|
|
|
|
2021-03-24 11:45:26 +00:00
|
|
|
await app.models.Client.notifyAssignment(client, previousWorkerId, currentWorkerId);
|
2021-03-23 15:19:45 +00:00
|
|
|
|
2021-03-24 11:45:26 +00:00
|
|
|
expect(chatModel.send).toHaveBeenCalledWith(ctx, '@DavidCharlesHaller', `Client assignment has changed`);
|
|
|
|
expect(chatModel.send).toHaveBeenCalledWith(ctx, '@HankPym', `Client assignment has changed`);
|
2021-03-23 15:19:45 +00:00
|
|
|
});
|
|
|
|
|
2021-03-24 11:45:26 +00:00
|
|
|
it('should call to the Chat send() method for the previous worker', async() => {
|
|
|
|
spyOn(chatModel, 'send').and.callThrough();
|
2021-03-23 15:19:45 +00:00
|
|
|
|
2021-03-24 11:45:26 +00:00
|
|
|
await app.models.Client.notifyAssignment(client, null, currentWorkerId);
|
2021-03-23 15:19:45 +00:00
|
|
|
|
2021-03-24 11:45:26 +00:00
|
|
|
expect(chatModel.send).toHaveBeenCalledWith(ctx, '@HankPym', `Client assignment has changed`);
|
|
|
|
});
|
2021-03-23 15:19:45 +00:00
|
|
|
|
2021-03-24 11:45:26 +00:00
|
|
|
it('should call to the Chat send() method for the current worker', async() => {
|
|
|
|
spyOn(chatModel, 'send').and.callThrough();
|
2021-03-23 15:19:45 +00:00
|
|
|
|
2021-03-24 11:45:26 +00:00
|
|
|
await app.models.Client.notifyAssignment(client, previousWorkerId, null);
|
2021-03-23 15:19:45 +00:00
|
|
|
|
2021-03-24 11:45:26 +00:00
|
|
|
expect(chatModel.send).toHaveBeenCalledWith(ctx, '@DavidCharlesHaller', `Client assignment has changed`);
|
2021-03-23 15:19:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|