Merge branch '2094-claim_send_chat' of verdnatura/salix into dev
gitea/salix/dev This commit has test failures Details

This commit is contained in:
Carlos Jimenez Ruiz 2020-02-13 22:54:22 +00:00 committed by Gitea
commit 2d2aea5ea3
5 changed files with 67 additions and 33 deletions

View File

@ -36,7 +36,7 @@ module.exports = Self => {
relation: 'department'
}
});
const department = workerDepartment.department();
const department = workerDepartment && workerDepartment.department();
const channelName = department.chatName;
if (channelName)

View File

@ -61,7 +61,7 @@
"MESSAGE_BOUGHT_UNITS": "Bought {{quantity}} units of {{concept}} (#{{itemId}}) for the ticket id [#{{ticketId}}]({{{url}}})",
"MESSAGE_INSURANCE_CHANGE": "I have changed the insurence credit of client [{{clientName}} (#{{clientId}})]({{{url}}}) to *{{credit}} €*",
"MESSAGE_CHANGED_PAYMETHOD": "I have changed the pay method for client [{{clientName}} (#{{clientId}})]({{{url}}})",
"MESSAGE_CLAIM_ITEM_REGULARIZE": "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}}})",
"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",
"Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}"

View File

@ -124,7 +124,7 @@
"MESSAGE_BOUGHT_UNITS": "Se ha comprado {{quantity}} unidades de {{concept}} (#{{itemId}}) para el ticket id [#{{ticketId}}]({{{url}}})",
"MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} (#{{clientId}})]({{{url}}}) a *{{credit}} €*",
"MESSAGE_CHANGED_PAYMETHOD": "He cambiado la forma de pago del cliente [{{clientName}} (#{{clientId}})]({{{url}}})",
"MESSAGE_CLAIM_ITEM_REGULARIZE": "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}}})",
"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"
}

View File

@ -37,27 +37,43 @@ module.exports = Self => {
for (let i = 0; i < claimEnds.length; i++) {
const claimEnd = claimEnds[i];
const destination = claimEnd.claimDestination();
const addressFk = destination && destination.addressFk;
const sale = await getSale(claimEnd.saleFk, options);
const addressId = destination && destination.addressFk;
if (!addressFk) continue;
let address;
if (addressId)
address = await models.Address.findById(addressId, null, options);
const salesPerson = sale.ticket().client().salesPerson();
if (salesPerson) {
const nickname = address && address.nickname || destination.description;
const origin = ctx.req.headers.origin;
const message = $t('Sent units from ticket', {
quantity: sale.quantity,
concept: sale.concept,
itemId: sale.itemFk,
ticketId: sale.ticketFk,
nickname: nickname,
ticketUrl: `${origin}/#!/ticket/${sale.ticketFk}/summary`,
itemUrl: `${origin}/#!/item/${sale.itemFk}/summary`
});
await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message);
}
if (!address) continue;
let sale = await getSale(claimEnd.saleFk, options);
let ticketFk = await getTicketId({
addressFk: addressFk,
addressFk: addressId,
companyFk: sale.ticket().companyFk,
warehouseFk: sale.ticket().warehouseFk
}, options);
let address = await models.Address.findOne({
where: {id: addressFk}
}, options);
if (!ticketFk) {
ticketFk = await createTicket(ctx, {
clientId: address.clientFk,
warehouseId: sale.ticket().warehouseFk,
companyId: sale.ticket().companyFk,
addressId: addressFk
addressId: addressId
}, options);
}
@ -69,21 +85,6 @@ module.exports = Self => {
price: sale.price,
discount: 100
}, options);
const salesPerson = sale.ticket().client().salesPerson();
if (salesPerson) {
const origin = ctx.req.headers.origin;
const message = $t('MESSAGE_CLAIM_ITEM_REGULARIZE', {
quantity: sale.quantity,
concept: sale.concept,
itemId: sale.itemFk,
ticketId: sale.ticketFk,
nickname: address.nickname,
ticketUrl: `${origin}/#!/ticket/${sale.ticketFk}/summary`,
itemUrl: `${origin}/#!/item/${sale.itemFk}/summary`
});
await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message);
}
}
let claim = await Self.findById(params.claimFk, null, options);

View File

@ -5,6 +5,7 @@ describe('regularizeClaim()', () => {
const pendentState = 1;
const resolvedState = 3;
const trashDestination = 2;
const okDestination = 1;
const trashAddress = 12;
let claimEnds = [];
let trashTicket;
@ -21,15 +22,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 +55,32 @@ describe('regularizeClaim()', () => {
expect(trashTicket.addressFk).toEqual(trashAddress);
expect(claimBefore.claimStateFk).toEqual(pendentState);
expect(claimAfter.claimStateFk).toEqual(resolvedState);
expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Trash');
expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(4);
});
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: okDestination});
});
await app.models.Claim.regularizeClaim(ctx, params);
expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Bueno');
expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(4);
});
});