Send message to comercial by RocketChat #1897
|
@ -59,8 +59,8 @@ async function test() {
|
||||||
const JunitReporter = require('jasmine-reporters');
|
const JunitReporter = require('jasmine-reporters');
|
||||||
jasmine.addReporter(new JunitReporter.JUnitXmlReporter());
|
jasmine.addReporter(new JunitReporter.JUnitXmlReporter());
|
||||||
|
|
||||||
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
|
|
||||||
jasmine.exitOnCompletion = true;
|
jasmine.exitOnCompletion = true;
|
||||||
|
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 900000;
|
||||||
}
|
}
|
||||||
|
|
||||||
const backSpecs = [
|
const backSpecs = [
|
||||||
|
|
|
@ -69,8 +69,7 @@
|
||||||
"Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} ({{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [{{ticketId}}]({{{ticketUrl}}})",
|
"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}}",
|
"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 will be picked": "The product from the claim [({{claimId}})]({{{claimUrl}}}) from the client *{{clientName}}* will be picked",
|
||||||
"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": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *{{newState}}*",
|
||||||
"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",
|
"Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member",
|
||||||
"Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member",
|
"Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member",
|
||||||
"Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}",
|
"Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}",
|
||||||
|
|
|
@ -136,8 +136,7 @@
|
||||||
"Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} ({{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [{{ticketId}}]({{{ticketUrl}}})",
|
"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}}",
|
"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 will be picked": "Se recogerá el género de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*",
|
||||||
"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": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *{{newState}}*",
|
||||||
"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}}",
|
"Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}",
|
||||||
"ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto",
|
"ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto",
|
||||||
"Distance must be lesser than 1000": "La distancia debe ser inferior a 1000",
|
"Distance must be lesser than 1000": "La distancia debe ser inferior a 1000",
|
||||||
|
@ -332,6 +331,7 @@
|
||||||
"quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mínima",
|
"quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mínima",
|
||||||
"Cannot past travels with entries": "No se pueden pasar envíos con entradas",
|
"Cannot past travels with entries": "No se pueden pasar envíos con entradas",
|
||||||
"It was not able to remove the next expeditions:": "No se pudo eliminar las siguientes expediciones: {{expeditions}}",
|
"It was not able to remove the next expeditions:": "No se pudo eliminar las siguientes expediciones: {{expeditions}}",
|
||||||
|
"This claim has been updated": "La reclamación con Id: {{claimId}}, ha sido actualizada",
|
||||||
"This user does not have an assigned tablet": "Este usuario no tiene tablet asignada",
|
"This user does not have an assigned tablet": "Este usuario no tiene tablet asignada",
|
||||||
"Incorrect pin": "Pin incorrecto.",
|
"Incorrect pin": "Pin incorrecto.",
|
||||||
"You already have the mailAlias": "Ya tienes este alias de correo",
|
"You already have the mailAlias": "Ya tienes este alias de correo",
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
const i18n = require('i18n');
|
||||||
describe('Update Claim', () => {
|
describe('Update Claim', () => {
|
||||||
let url;
|
let url;
|
||||||
|
let claimStatesMap = {};
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
url = await app.models.Url.getUrl();
|
url = await app.models.Url.getUrl();
|
||||||
const activeCtx = {
|
const activeCtx = {
|
||||||
|
@ -16,6 +17,8 @@ describe('Update Claim', () => {
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
active: activeCtx
|
active: activeCtx
|
||||||
});
|
});
|
||||||
|
const claimStates = await app.models.ClaimState.find();
|
||||||
|
claimStatesMap = claimStates.reduce((acc, state) => ({...acc, [state.code]: state.id}), {});
|
||||||
});
|
});
|
||||||
const newDate = Date.vnNew();
|
const newDate = Date.vnNew();
|
||||||
const originalData = {
|
const originalData = {
|
||||||
|
@ -62,6 +65,123 @@ describe('Update Claim', () => {
|
||||||
expect(error.message).toEqual(`You don't have enough privileges to change that field`);
|
expect(error.message).toEqual(`You don't have enough privileges to change that field`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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 'managed' 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 managedState = claimStatesMap.managed;
|
||||||
|
const claimManagerId = 72;
|
||||||
|
const ctx = {
|
||||||
|
req: {
|
||||||
|
accessToken: {userId: claimManagerId},
|
||||||
|
headers: {origin: url}
|
||||||
|
},
|
||||||
|
args: {
|
||||||
|
observation: 'valid observation',
|
||||||
|
claimStateFk: managedState,
|
||||||
|
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 'resolved' 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 resolvedState = claimStatesMap.resolved;
|
||||||
|
const claimManagerId = 72;
|
||||||
|
const ctx = {
|
||||||
|
req: {
|
||||||
|
accessToken: {userId: claimManagerId},
|
||||||
|
headers: {origin: url}
|
||||||
|
},
|
||||||
|
args: {
|
||||||
|
observation: 'valid observation',
|
||||||
|
claimStateFk: resolvedState,
|
||||||
|
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 'canceled' and send a rocket message`, async() => {
|
it(`should success to update the claimState to 'canceled' and send a rocket message`, async() => {
|
||||||
const tx = await app.models.Claim.beginTransaction({});
|
const tx = await app.models.Claim.beginTransaction({});
|
||||||
|
|
||||||
|
@ -73,7 +193,7 @@ describe('Update Claim', () => {
|
||||||
const chatModel = app.models.Chat;
|
const chatModel = app.models.Chat;
|
||||||
spyOn(chatModel, 'sendCheckingPresence').and.callThrough();
|
spyOn(chatModel, 'sendCheckingPresence').and.callThrough();
|
||||||
|
|
||||||
const canceledState = 4;
|
const canceledState = claimStatesMap.canceled;
|
||||||
const claimManagerId = 72;
|
const claimManagerId = 72;
|
||||||
const ctx = {
|
const ctx = {
|
||||||
req: {
|
req: {
|
||||||
|
@ -86,9 +206,7 @@ describe('Update Claim', () => {
|
||||||
hasToPickUp: false
|
hasToPickUp: false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ctx.req.__ = (value, params) => {
|
ctx.req.__ = i18n.__;
|
||||||
return params.nickname;
|
|
||||||
};
|
|
||||||
await app.models.Claim.updateClaim(ctx, newClaim.id, options);
|
await app.models.Claim.updateClaim(ctx, newClaim.id, options);
|
||||||
|
|
||||||
let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options);
|
let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options);
|
||||||
|
@ -127,9 +245,7 @@ describe('Update Claim', () => {
|
||||||
hasToPickUp: false
|
hasToPickUp: false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ctx.req.__ = (value, params) => {
|
ctx.req.__ = i18n.__;
|
||||||
return params.nickname;
|
|
||||||
};
|
|
||||||
await app.models.Claim.updateClaim(ctx, newClaim.id, options);
|
await app.models.Claim.updateClaim(ctx, newClaim.id, options);
|
||||||
|
|
||||||
let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options);
|
let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options);
|
||||||
|
@ -168,9 +284,7 @@ describe('Update Claim', () => {
|
||||||
hasToPickUp: true
|
hasToPickUp: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ctx.req.__ = (value, params) => {
|
ctx.req.__ = i18n.__;
|
||||||
return params.nickname;
|
|
||||||
};
|
|
||||||
await app.models.Claim.updateClaim(ctx, newClaim.id, options);
|
await app.models.Claim.updateClaim(ctx, newClaim.id, options);
|
||||||
|
|
||||||
let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options);
|
let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options);
|
||||||
|
|
|
@ -96,12 +96,9 @@ module.exports = Self => {
|
||||||
// When claimState has been changed
|
// When claimState has been changed
|
||||||
if (args.claimStateFk) {
|
if (args.claimStateFk) {
|
||||||
const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions);
|
const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions);
|
||||||
if (newState.hasToNotify) {
|
await notifyStateChange(ctx, salesPerson.id, claim, newState.code);
|
||||||
jsegarra marked this conversation as resolved
|
|||||||
if (newState.code == 'incomplete')
|
if (newState.code == 'canceled')
|
||||||
await notifyStateChange(ctx, salesPerson.id, claim, newState.code);
|
await notifyStateChange(ctx, claim.workerFk, claim, newState.code);
|
||||||
if (newState.code == 'canceled')
|
|
||||||
await notifyStateChange(ctx, claim.workerFk, claim, newState.code);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
@ -113,15 +110,16 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function notifyStateChange(ctx, workerId, claim, state) {
|
async function notifyStateChange(ctx, workerId, claim, newState) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const url = await models.Url.getUrl();
|
const url = await models.Url.getUrl();
|
||||||
const $t = ctx.req.__; // $translate
|
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,
|
claimId: claim.id,
|
||||||
clientName: claim.client().name,
|
clientName: claim.client().name,
|
||||||
claimUrl: `${url}claim/${claim.id}/summary`
|
claimUrl: `${url}claim/${claim.id}/summary`,
|
||||||
|
newState
|
||||||
});
|
});
|
||||||
await models.Chat.sendCheckingPresence(ctx, workerId, message);
|
await models.Chat.sendCheckingPresence(ctx, workerId, message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,4 +27,4 @@
|
||||||
label="Cancel">
|
label="Cancel">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
</vn-button-bar>
|
</vn-button-bar>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue
borrar