feat: refs #6760 refs #actualiza campo nickname
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
aaf95e3cff
commit
5f06ae5cf4
|
@ -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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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 = [];
|
||||||
|
|
Loading…
Reference in New Issue