const errorRouter = require('./error.api');
const httpMocks = require('node-mocks-http');
const Logger = require('../logger');

describe('error api', () => {
  let mockResponse;

  beforeEach(() => {
    mockResponse = {};
  });

  describe('log', () => {
    it('should log all given params', (done) => {
      Logger.error = jest.fn();

      const mockRequest = httpMocks.createRequest({
        url: '/log',
        method: 'POST',
        body: {
          message: 'testMessage',
          url: 'testUrl',
          lineNo: 1,
          colNo: 2,
        },
      });

      errorRouter.handle(mockRequest, mockResponse, () => {
        expect(Logger.error.mock.calls).toHaveLength(1);
        const logParams = Logger.error.mock.calls[0][0];
        expect(logParams).toContain('testMessage');
        expect(logParams).toContain('testUrl');
        expect(logParams).toContain(1);
        expect(logParams).toContain(2);
        done();
      });
    });

    it('should log stack if given', (done) => {
      Logger.error = jest.fn();

      const mockRequest = httpMocks.createRequest({
        url: '/log',
        method: 'POST',
        body: {
          error: {
            stack: 'errorStack',
          },
        },
      });

      errorRouter.handle(mockRequest, mockResponse, () => {
        expect(Logger.error.mock.calls).toHaveLength(2);
        expect(Logger.error.mock.calls[1][0]).toContain('errorStack');
        done();
      });
    });
  });
});

@@ -155,80 +155,8 @@
 %3E %7B%0A
-  let mockResponse;%0A%0A  beforeEach(() =%3E %7B%0A    mockResponse = %7B%7D;%0A  %7D);%0A%0A
   de
@@ -530,36 +530,26 @@
 ockRequest, 
-mockResponse
+%7B%7D
 , () =%3E %7B%0A  
@@ -1198,20 +1198,10 @@
 st, 
-mockResponse
+%7B%7D
 , ()

remove unnecessary shared variable