const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');

describe('ticket-request deny()', () => {
    beforeAll(async() => {
        const activeCtx = {
            accessToken: {userId: 9},
            http: {
                req: {
                    headers: {origin: 'http://localhost'}
                }
            }
        };
        spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
            active: activeCtx
        });
    });

    it('should return the denied ticket request', async() => {
        const tx = await models.TicketRequest.beginTransaction({});

        try {
            const options = {transaction: tx};

            const ctx = {
                req: {
                    accessToken: {userId: 9},
                    headers: {origin: 'http://localhost'}
                },
                args: {id: 4, observation: 'my observation'},
            };

            ctx.req.__ = value => {
                return value;
            };

            const result = await models.TicketRequest.deny(ctx, options);

            expect(result.id).toEqual(4);

            await tx.rollback();
        } catch (e) {
            await tx.rollback();
            throw e;
        }
    });
});