Updated unit test
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2020-06-04 07:53:06 +02:00
parent f39719cc46
commit 0695ec01bc
3 changed files with 17 additions and 10 deletions

View File

@ -103,11 +103,9 @@ describe('regularizeClaim()', () => {
claimEnd.updateAttributes({claimDestinationFk: okDestination}); claimEnd.updateAttributes({claimDestinationFk: okDestination});
}); });
const claim = await app.models.Claim.findById(claimFk);
await claim.updateAttribute('hasToPickUp', true);
await app.models.Claim.regularizeClaim(ctx, claimFk); await app.models.Claim.regularizeClaim(ctx, claimFk);
expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Bueno'); expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Bueno');
expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(5); expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(4);
}); });
}); });

View File

@ -70,19 +70,25 @@ describe('Update Claim', () => {
}); });
it('should change some sensible fields as salesAssistant', async() => { it('should change some sensible fields as salesAssistant', async() => {
const chatModel = app.models.Chat;
spyOn(chatModel, 'sendCheckingPresence').and.callThrough();
const salesAssistantId = 21; const salesAssistantId = 21;
let data = { let data = {
claimStateFk: 3, claimStateFk: 3,
workerFk: 5, workerFk: 5,
observation: 'another valid observation' observation: 'another valid observation',
hasToPickUp: true
}; };
let ctx = { const ctx = {
req: { req: {
accessToken: { accessToken: {userId: salesAssistantId},
userId: salesAssistantId headers: {origin: 'http://localhost'}
}
} }
}; };
ctx.req.__ = (value, params) => {
return params.nickname;
};
await app.models.Claim.updateClaim(ctx, newInstance.id, data); await app.models.Claim.updateClaim(ctx, newInstance.id, data);
let claimUpdated = await app.models.Claim.findById(newInstance.id); let claimUpdated = await app.models.Claim.findById(newInstance.id);
@ -90,5 +96,6 @@ describe('Update Claim', () => {
expect(claimUpdated.observation).toEqual(data.observation); expect(claimUpdated.observation).toEqual(data.observation);
expect(claimUpdated.claimStateFk).toEqual(data.claimStateFk); expect(claimUpdated.claimStateFk).toEqual(data.claimStateFk);
expect(claimUpdated.workerFk).toEqual(data.workerFk); expect(claimUpdated.workerFk).toEqual(data.workerFk);
expect(chatModel.sendCheckingPresence).toHaveBeenCalled();
}); });
}); });

View File

@ -46,9 +46,11 @@ module.exports = Self => {
if (!canUpdate || !hasRights) if (!canUpdate || !hasRights)
throw new UserError(`You don't have enough privileges to change that field`); throw new UserError(`You don't have enough privileges to change that field`);
const updatedClaim = await claim.updateAttributes(data);
// Get sales person from claim client // Get sales person from claim client
const salesPerson = claim.client().salesPerson(); const salesPerson = claim.client().salesPerson();
if (salesPerson && claim.hasToPickUp) { if (salesPerson && updatedClaim.hasToPickUp) {
const origin = ctx.req.headers.origin; const origin = ctx.req.headers.origin;
const message = $t('Claim will be picked', { const message = $t('Claim will be picked', {
claimId: claim.id, claimId: claim.id,
@ -58,7 +60,7 @@ module.exports = Self => {
await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message); await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message);
} }
return await claim.updateAttributes(data); return updatedClaim;
}; };
async function canChangeState(ctx, id) { async function canChangeState(ctx, id) {