{"size": 818, "ext": "js", "max_stars_repo_path": "app/middleware/utils/handleError.test.js", "max_stars_repo_name": "ugurakcil/jwt-pro", "max_stars_repo_stars_event_min_datetime": "2018-09-11T19:27:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:53:40.000Z", "max_issues_repo_path": "app/middleware/utils/handleError.test.js", "max_issues_repo_name": "ugurakcil/jwt-pro", "max_issues_repo_issues_event_min_datetime": "2018-10-24T10:06:39.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T18:55:27.000Z", "max_forks_repo_path": "app/middleware/utils/handleError.test.js", "max_forks_repo_name": "ugurakcil/jwt-pro", "max_forks_repo_forks_event_min_datetime": "2018-09-21T09:10:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-19T07:31:59.000Z"}
{"max_stars_count": 780, "max_issues_count": 191, "max_forks_count": 304, "avg_line_length": 20.9743589744, "max_line_length": 139, "alphanum_fraction": 0.6320293399}
const { handleError } = require('./handleError')

const mockResponse = () => {
  const res = {}
  res.status = jest.fn().mockReturnValueOnce(res)
  res.json = jest.fn().mockReturnValueOnce(res)
  return res
}

const err = {
  message: 'error',
  code: 123
}

describe('handleError()', () => {
  it('should send the error object with the code and message provided and print the error code, message in development mode', async () => {
    process.env.NODE_ENV = 'development'

    const res = mockResponse()

    console.log = jest.fn()

    await handleError(res, err)

    expect(console.log).toHaveBeenCalledWith({
      code: 123,
      message: 'error'
    })

    expect(res.status).toHaveBeenCalledWith(123)

    expect(res.json).toHaveBeenCalledWith({
      errors: {
        msg: 'error'
      }
    })
  })
})
