Merge pull request 'feat: refs #6760 refs #actualiza campo nickname' (!2883) from 6760-transferClient into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2883
Reviewed-by: Javier Segarra <jsegarra@verdnatura.es>
This commit is contained in:
Javi Gallego 2024-08-28 10:38:45 +00:00
commit a4e09884db
2 changed files with 19 additions and 7 deletions

View File

@ -8,6 +8,7 @@ describe('Ticket transferClient()', () => {
const ctx = beforeAll.getCtx(); const ctx = beforeAll.getCtx();
let options; let options;
let tx; let tx;
beforeEach(async() => { beforeEach(async() => {
options = {transaction: tx}; options = {transaction: tx};
tx = await models.Ticket.beginTransaction({}); tx = await models.Ticket.beginTransaction({});
@ -21,21 +22,23 @@ describe('Ticket transferClient()', () => {
it('should throw an error as the ticket is not editable', async() => { it('should throw an error as the ticket is not editable', async() => {
try { try {
const ticketId = 4; const ticketId = 4;
const clientId = 1;
await models.Ticket.transferClient(ctx, ticketId, clientId, options); await models.Ticket.transferClient(ctx, ticketId, clientId, options);
} catch (e) { } catch (e) {
expect(e.message).toEqual(`This ticket is locked`); expect(e.message).toEqual('This ticket is locked');
} }
}); });
it('should be assigned a different clientFk in the original ticket', async() => { it('should be assigned a different clientFk and nickname in the original ticket', async() => {
await models.Ticket.transferClient(ctx, 2, clientId, options); await models.Ticket.transferClient(ctx, 2, clientId, options);
const afterTransfer = await models.Ticket.findById(2, null, options); const afterTransfer = await models.Ticket.findById(2, null, options);
const client = await models.Client.findById(clientId, {fields: ['defaultAddressFk']}, options);
const address = await models.Address.findById(client.defaultAddressFk, {fields: ['nickname']}, options);
expect(afterTransfer.clientFk).toEqual(clientId); expect(afterTransfer.clientFk).toEqual(clientId);
expect(afterTransfer.nickname).toEqual(address.nickname);
}); });
it('should be assigned a different clientFk in the original and refund ticket and claim', async() => { it('should be assigned a different clientFk and nickname in the original and refund ticket and claim', async() => {
await models.Ticket.transferClient(ctx, originalTicketId, clientId, options); await models.Ticket.transferClient(ctx, originalTicketId, clientId, options);
const [originalTicket, refundTicket] = await models.Ticket.find({ const [originalTicket, refundTicket] = await models.Ticket.find({
@ -46,8 +49,14 @@ describe('Ticket transferClient()', () => {
where: {ticketFk: originalTicketId} where: {ticketFk: originalTicketId}
}, options); }, options);
const client = await models.Client.findById(clientId, {fields: ['defaultAddressFk']}, options);
const address = await models.Address.findById(client.defaultAddressFk, {fields: ['nickname']}, options);
expect(originalTicket.clientFk).toEqual(clientId); expect(originalTicket.clientFk).toEqual(clientId);
expect(refundTicket.clientFk).toEqual(clientId); expect(refundTicket.clientFk).toEqual(clientId);
expect(claim.clientFk).toEqual(clientId); expect(claim.clientFk).toEqual(clientId);
expect(originalTicket.nickname).toEqual(address.nickname);
expect(refundTicket.nickname).toEqual(address.nickname);
}); });
}); });

View File

@ -1,6 +1,6 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('transferClient', { Self.remoteMethodCtx('transferClient', {
description: 'Transfering ticket to another client', description: 'Transferring ticket to another client',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [{
arg: 'id', arg: 'id',
@ -40,10 +40,13 @@ module.exports = Self => {
include: [{relation: 'refundTicket'}, {relation: 'originalTicket'}] include: [{relation: 'refundTicket'}, {relation: 'originalTicket'}]
}, myOptions); }, myOptions);
const {defaultAddressFk: addressFk} = await models.Client.findById(clientFk, const client = await models.Client.findById(clientFk,
{fields: ['id', 'defaultAddressFk']}, myOptions); {fields: ['id', 'defaultAddressFk']}, myOptions);
const attributes = {clientFk, addressFk}; const address = await models.Address.findById(client.defaultAddressFk,
{fields: ['id', 'nickname']}, myOptions);
const attributes = {clientFk, addressFk: client.defaultAddressFk, nickname: address.nickname};
const tickets = []; const tickets = [];
const ticketIds = []; const ticketIds = [];