diff --git a/back/tests.js b/back/tests.js index efade4d7d..c313df172 100644 --- a/back/tests.js +++ b/back/tests.js @@ -59,9 +59,9 @@ async function test() { const JunitReporter = require('jasmine-reporters'); jasmine.addReporter(new JunitReporter.JUnitXmlReporter()); - jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; jasmine.exitOnCompletion = true; } + jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 900000; const backSpecs = [ './back/**/*[sS]pec.js', diff --git a/loopback/locale/en.json b/loopback/locale/en.json index c5e8d4fcf..69f4b8e08 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -68,6 +68,7 @@ "Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} ({{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [{{ticketId}}]({{{ticketUrl}}})", "Change quantity": "{{concept}} change of {{oldQuantity}} to {{newQuantity}}", "Claim will be picked": "The product from the claim [({{claimId}})]({{{claimUrl}}}) from the client *{{clientName}}* will be picked", + "Claim state has changed to": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *{{newState}}*", "Claim state has changed to incomplete": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *incomplete*", "Claim state has changed to canceled": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *canceled*", "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9c26e7856..fc5b8ba0b 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -135,6 +135,7 @@ "Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} ({{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [{{ticketId}}]({{{ticketUrl}}})", "Change quantity": "{{concept}} cambia de {{oldQuantity}} a {{newQuantity}}", "Claim will be picked": "Se recogerá el género de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*", + "Claim state has changed to": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *{{newState}}*", "Claim state has changed to incomplete": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *incompleta*", "Claim state has changed to canceled": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *anulado*", "Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}", diff --git a/modules/claim/back/methods/claim/specs/updateClaim.spec.js b/modules/claim/back/methods/claim/specs/updateClaim.spec.js index 85ada869a..0922c0953 100644 --- a/modules/claim/back/methods/claim/specs/updateClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaim.spec.js @@ -1,8 +1,9 @@ const app = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); - -describe('Update Claim', () => { +const i18n = require('i18n'); +fdescribe('Update Claim', () => { let url; + let claimStatesMap = {}; beforeAll(async() => { url = await app.models.Url.getUrl(); const activeCtx = { @@ -16,6 +17,8 @@ describe('Update Claim', () => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: activeCtx }); + const claimStates = await app.models.ClaimState.find(); + claimStatesMap = claimStates.reduce((acc, state) => ({...acc, [state.code]: state.id}), {}); }); const newDate = Date.vnNew(); const originalData = { @@ -29,7 +32,7 @@ describe('Update Claim', () => { observation: 'observation' }; - it(`should throw an error as the user doesn't have rights`, async() => { + fit(`should throw an error as the user doesn't have rights`, async() => { const tx = await app.models.Claim.beginTransaction({}); let error; @@ -62,7 +65,7 @@ describe('Update Claim', () => { expect(error.message).toEqual(`You don't have enough privileges to change that field`); }); - it(`should success to update the claimState to 'canceled' and send a rocket message`, async() => { + fit(`should success to update the claimState to 'canceled' and send a rocket message`, async() => { const tx = await app.models.Claim.beginTransaction({}); try { @@ -103,6 +106,86 @@ describe('Update Claim', () => { } }); + it(`should success to update the claimState to 'pending' and send a rocket message`, async() => { + const tx = await app.models.Claim.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const newClaim = await app.models.Claim.create(originalData, options); + + const chatModel = app.models.Chat; + spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); + + const pendingState = claimStatesMap.pending; + const claimManagerId = 72; + const ctx = { + req: { + accessToken: {userId: claimManagerId}, + headers: {origin: url} + }, + args: { + observation: 'valid observation', + claimStateFk: pendingState, + hasToPickUp: false + } + }; + ctx.req.__ = i18n; + await app.models.Claim.updateClaim(ctx, newClaim.id, options); + + let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options); + + expect(updatedClaim.observation).toEqual(ctx.args.observation); + expect(chatModel.sendCheckingPresence).toHaveBeenCalled(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it(`should success to update the claimState to 'incomplete' and send a rocket message`, async() => { + const tx = await app.models.Claim.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const newClaim = await app.models.Claim.create(originalData, options); + + const chatModel = app.models.Chat; + spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); + + const incompleteState = 5; + const claimManagerId = 72; + const ctx = { + req: { + accessToken: {userId: claimManagerId}, + headers: {origin: url} + }, + args: { + observation: 'valid observation', + claimStateFk: incompleteState, + hasToPickUp: false + } + }; + ctx.req.__ = (value, params) => { + return params.nickname; + }; + await app.models.Claim.updateClaim(ctx, newClaim.id, options); + + let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options); + + expect(updatedClaim.observation).toEqual(ctx.args.observation); + expect(chatModel.sendCheckingPresence).toHaveBeenCalled(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + it(`should success to update the claimState to 'incomplete' and send a rocket message`, async() => { const tx = await app.models.Claim.beginTransaction({}); diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index d99528413..488410633 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -96,12 +96,10 @@ module.exports = Self => { // When claimState has been changed if (args.claimStateFk) { const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions); - if (newState.hasToNotify) { - if (newState.code == 'incomplete') - await notifyStateChange(ctx, salesPerson.id, claim, newState.code); - if (newState.code == 'canceled') - await notifyStateChange(ctx, claim.workerFk, claim, newState.code); - } + // if (newState.code == 'incomplete') + await notifyStateChange(ctx, salesPerson.id, claim, newState.code); + if (newState.code == 'canceled') + await notifyStateChange(ctx, claim.workerFk, claim, newState.code); } if (tx) await tx.commit(); @@ -113,17 +111,18 @@ module.exports = Self => { } }; - async function notifyStateChange(ctx, workerId, claim, state) { + async function notifyStateChange(ctx, id, claim, state) { const models = Self.app.models; const url = await models.Url.getUrl(); const $t = ctx.req.__; // $translate - const message = $t(`Claim state has changed to ${state}`, { + const message = $t(`Claim state has changed to`, { claimId: claim.id, clientName: claim.client().name, - claimUrl: `${url}claim/${claim.id}/summary` + claimUrl: `${url}claim/${claim.id}/summary`, + newState: state }); - await models.Chat.sendCheckingPresence(ctx, workerId, message); + await models.Chat.sendCheckingPresence(ctx, id, message); } async function notifyPickUp(ctx, workerId, claim) {