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
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2883 Reviewed-by: Javier Segarra <jsegarra@verdnatura.es>
This commit is contained in:
commit
a4e09884db
|
@ -8,6 +8,7 @@ describe('Ticket transferClient()', () => {
|
|||
const ctx = beforeAll.getCtx();
|
||||
let options;
|
||||
let tx;
|
||||
|
||||
beforeEach(async() => {
|
||||
options = {transaction: tx};
|
||||
tx = await models.Ticket.beginTransaction({});
|
||||
|
@ -21,21 +22,23 @@ describe('Ticket transferClient()', () => {
|
|||
it('should throw an error as the ticket is not editable', async() => {
|
||||
try {
|
||||
const ticketId = 4;
|
||||
const clientId = 1;
|
||||
await models.Ticket.transferClient(ctx, ticketId, clientId, options);
|
||||
} 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);
|
||||
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.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);
|
||||
|
||||
const [originalTicket, refundTicket] = await models.Ticket.find({
|
||||
|
@ -46,8 +49,14 @@ describe('Ticket transferClient()', () => {
|
|||
where: {ticketFk: originalTicketId}
|
||||
}, 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(refundTicket.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 => {
|
||||
Self.remoteMethodCtx('transferClient', {
|
||||
description: 'Transfering ticket to another client',
|
||||
description: 'Transferring ticket to another client',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
|
@ -40,10 +40,13 @@ module.exports = Self => {
|
|||
include: [{relation: 'refundTicket'}, {relation: 'originalTicket'}]
|
||||
}, myOptions);
|
||||
|
||||
const {defaultAddressFk: addressFk} = await models.Client.findById(clientFk,
|
||||
const client = await models.Client.findById(clientFk,
|
||||
{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 ticketIds = [];
|
||||
|
|
Loading…
Reference in New Issue