feat: refs #7322 add addressFk parameter to transferClient method and update tests
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
b78603275f
commit
f165d17869
|
@ -22,14 +22,16 @@ describe('Ticket transferClient()', () => {
|
|||
it('should throw an error as the ticket is not editable', async() => {
|
||||
try {
|
||||
const ticketId = 4;
|
||||
await models.Ticket.transferClient(ctx, ticketId, clientId, options);
|
||||
const addressFk = null;
|
||||
await models.Ticket.transferClient(ctx, ticketId, clientId, addressFk, options);
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual('This ticket is locked');
|
||||
}
|
||||
});
|
||||
|
||||
it('should be assigned a different clientFk and nickname in the original ticket', async() => {
|
||||
await models.Ticket.transferClient(ctx, 2, clientId, options);
|
||||
const addressFk = null;
|
||||
await models.Ticket.transferClient(ctx, 2, clientId, addressFk, 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);
|
||||
|
@ -39,7 +41,8 @@ describe('Ticket transferClient()', () => {
|
|||
});
|
||||
|
||||
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 addressFk = null;
|
||||
await models.Ticket.transferClient(ctx, originalTicketId, clientId, addressFk, options);
|
||||
|
||||
const [originalTicket, refundTicket] = await models.Ticket.find({
|
||||
where: {id: {inq: [originalTicketId, refundTicketId]}}
|
||||
|
@ -59,4 +62,38 @@ describe('Ticket transferClient()', () => {
|
|||
expect(originalTicket.nickname).toEqual(address.nickname);
|
||||
expect(refundTicket.nickname).toEqual(address.nickname);
|
||||
});
|
||||
|
||||
it('should be assigned a different addressFk and nickname in the original and refund ticket', async() => {
|
||||
const addressFk = 131;
|
||||
await models.Ticket.transferClient(ctx, originalTicketId, clientId, addressFk, options);
|
||||
|
||||
const [originalTicket, refundTicket] = await models.Ticket.find({
|
||||
where: {id: {inq: [originalTicketId, refundTicketId]}}
|
||||
}, options);
|
||||
|
||||
const claim = await models.Claim.findOne({
|
||||
where: {ticketFk: originalTicketId}
|
||||
}, options);
|
||||
|
||||
const address = await models.Address.findById(addressFk, {fields: ['id', 'nickname', 'clientFk']}, options);
|
||||
|
||||
expect(originalTicket.clientFk).toEqual(clientId);
|
||||
expect(originalTicket.clientFk).toEqual(address.clientFk);
|
||||
expect(refundTicket.clientFk).toEqual(clientId);
|
||||
expect(refundTicket.clientFk).toEqual(address.clientFk);
|
||||
expect(claim.clientFk).toEqual(clientId);
|
||||
expect(claim.clientFk).toEqual(address.clientFk);
|
||||
|
||||
expect(originalTicket.nickname).toEqual(address.nickname);
|
||||
expect(refundTicket.nickname).toEqual(address.nickname);
|
||||
});
|
||||
|
||||
it('should be thrown an error if the new address is not belong to the client', async() => {
|
||||
const addressFk = 1;
|
||||
try {
|
||||
await models.Ticket.transferClient(ctx, originalTicketId, clientId, addressFk, options);
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual('The address does not belong to the client');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -23,7 +23,7 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.transferClient = async(ctx, id, clientFk, options, addressFk) => {
|
||||
Self.transferClient = async(ctx, id, clientFk, addressFk, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
@ -48,7 +48,9 @@ module.exports = Self => {
|
|||
{fields: ['id', 'defaultAddressFk']}, myOptions);
|
||||
|
||||
const address = await models.Address.findById(addressFk ? addressFk : client.defaultAddressFk,
|
||||
{fields: ['id', 'nickname']}, myOptions);
|
||||
{fields: ['id', 'nickname', 'clientFk']}, myOptions);
|
||||
|
||||
if (address.clientFk !== clientFk) throw new UserError('The address does not belong to the client');
|
||||
|
||||
const attributes = {clientFk, addressFk: address.id, nickname: address.nickname};
|
||||
|
||||
|
|
Loading…
Reference in New Issue