This commit is contained in:
parent
ce1bdaec17
commit
7614b48c9a
|
@ -80,34 +80,6 @@ describe('sale transferSales()', () => {
|
||||||
expect(error.message).toEqual(`Can't transfer claimed sales`);
|
expect(error.message).toEqual(`Can't transfer claimed sales`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to transfer claimed sales if the role is claimManager', async() => {
|
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
|
||||||
|
|
||||||
let error;
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
const claimManagerId = 72;
|
|
||||||
const myActiveCtx = {
|
|
||||||
accessToken: {userId: claimManagerId},
|
|
||||||
};
|
|
||||||
const myCtx = {req: myActiveCtx};
|
|
||||||
|
|
||||||
const ticketId = 11;
|
|
||||||
const receiverTicketId = null;
|
|
||||||
const sales = await models.Ticket.getSales(ticketId, options);
|
|
||||||
|
|
||||||
await models.Ticket.transferSales(myCtx, ticketId, receiverTicketId, sales, options);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(error).toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should transfer the sales from a ticket to a new one', async() => {
|
it('should transfer the sales from a ticket to a new one', async() => {
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
|
||||||
|
|
|
@ -77,9 +77,8 @@ module.exports = Self => {
|
||||||
|
|
||||||
const saleIds = sales.map(sale => sale.id);
|
const saleIds = sales.map(sale => sale.id);
|
||||||
|
|
||||||
const isClaimManager = await models.Account.hasRole(userId, 'claimManager');
|
|
||||||
const hasClaimedSales = await models.ClaimBeginning.findOne({where: {saleFk: {inq: saleIds}}});
|
const hasClaimedSales = await models.ClaimBeginning.findOne({where: {saleFk: {inq: saleIds}}});
|
||||||
if (hasClaimedSales && !isClaimManager)
|
if (hasClaimedSales)
|
||||||
throw new UserError(`Can't transfer claimed sales`);
|
throw new UserError(`Can't transfer claimed sales`);
|
||||||
|
|
||||||
for (const sale of sales) {
|
for (const sale of sales) {
|
||||||
|
|
Loading…
Reference in New Issue