{"size": 1088, "ext": "js", "max_stars_repo_path": "test/example.test.js", "max_stars_repo_name": "Eomm/fastify-explorer", "max_stars_repo_stars_event_min_datetime": "2020-02-06T20:08:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-06T20:08:05.000Z", "max_issues_repo_path": "test/example.test.js", "max_issues_repo_name": "Eomm/fastify-explorer", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/example.test.js", "max_forks_repo_name": "Eomm/fastify-explorer", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.2, "max_line_length": 93, "alphanum_fraction": 0.6167279412}
'use strict'

const t = require('tap')
const test = t.test

const buildAppToTest = require('../example/application')

test('call my route', t => {
  t.plan(3)
  const fastify = buildAppToTest({ logger: false })
  fastify.inject('/my-route', (err, res) => {
    t.error(err)
    t.equals(res.statusCode, 200)
    t.equals(res.payload, 'The doc is: null') // empty mongo :)
    fastify.close()
  })
})

test('call my route and fail', t => {
  t.plan(4)
  const fastify = buildAppToTest({ logger: false }, true)

  fastify.ready(err => {
    t.error(err)

    // this mongo instance would be unreachable
    const mongoInsideFastify = fastify.giveMe('routes-explorer', 'mongo')

    // monkey patching only this instance, the next `buildAppToTest` call all will be cleared
    mongoInsideFastify.client.close(() => {
      fastify.inject('/my-route', (err, res) => {
        t.error(err)
        t.equals(res.statusCode, 501) // this is a customized http status code
        t.deepEquals(res.json(), { ops: 'fail' }) // empty mongo :)
        fastify.close(() => {})
      })
    })
  })
})
