updated unit test
gitea/salix/2094-claim_send_chat This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-02-13 14:39:33 +01:00
parent 39470e837b
commit be07e33e5f
1 changed files with 37 additions and 7 deletions

View File

@ -1,6 +1,6 @@
const app = require('vn-loopback/server/server');
describe('regularizeClaim()', () => {
fdescribe('regularizeClaim()', () => {
const claimFk = 1;
const pendentState = 1;
const resolvedState = 3;
@ -21,15 +21,20 @@ describe('regularizeClaim()', () => {
done();
});
it('should change claim state to resolved', async() => {
const ctx = {req: {
accessToken: {userId: 18},
headers: {origin: 'http://localhost'}}
it('should send a chat message with value "Trash" and then change claim state to resolved', async() => {
const ctx = {
req: {
accessToken: {userId: 18},
headers: {origin: 'http://localhost'}
}
};
ctx.req.__ = value => {
return value;
ctx.req.__ = (value, params) => {
return params.nickname;
};
let params = {claimFk: claimFk};
const chatModel = app.models.Chat;
spyOn(chatModel, 'sendCheckingPresence').and.callThrough();
claimEnds = await app.models.ClaimEnd.importTicketSales(ctx, {
claimFk: claimFk,
@ -49,5 +54,30 @@ describe('regularizeClaim()', () => {
expect(trashTicket.addressFk).toEqual(trashAddress);
expect(claimBefore.claimStateFk).toEqual(pendentState);
expect(claimAfter.claimStateFk).toEqual(resolvedState);
expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Trash');
});
it('should send a chat message with value "Bueno" and then change claim state to resolved', async() => {
const ctx = {
req: {
accessToken: {userId: 18},
headers: {origin: 'http://localhost'}
}
};
ctx.req.__ = (value, params) => {
return params.nickname;
};
let params = {claimFk: claimFk};
const chatModel = app.models.Chat;
spyOn(chatModel, 'sendCheckingPresence').and.callThrough();
claimEnds.forEach(async claimEnd => {
claimEnd.updateAttributes({claimDestinationFk: 1});
});
await app.models.Claim.regularizeClaim(ctx, params);
expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Bueno');
});
});