text: const server = require('../../../test-utils/index')
  const chai = require('chai')
  const expect = chai.expect
  chai.use(require('chai-http'))
  
  const cveFixtures = require('./mockObjects.cve')
  const cveController = require('../../../src/controller/cve.controller/cve.controller')
  const cveParams = require('../../../src/controller/cve.controller/cve.middleware')
  const CONSTANTS = require('../../../src/constants')
  const nonExistentCveRecord = 'CVE-2020-1425'
  const cveIdPublic4 = 'CVE-2017-5832'
  const cveIdReject4 = 'CVE-2017-5835'
  
  const errors = require('../../../src/controller/cve.controller/error')
  const error = new errors.CveControllerError()
  
  class MyCveNegativeTests {
    async findOneByCveId () {
      return null
    }
  }
  
  class MyCvePositiveTests {
    async findOneByCveId (id) {
      if (id === cveIdPublic4) {
        return cveFixtures.cveRecordPublic4
      } else if (id === cveIdReject4) {
        return cveFixtures.cveRecordReject4
      }
    }
  }
  
  server.route('/cve-get-record-negative-tests/:id')
    .get((req, res, next) => {
      const factory = {
        getCveRepository: () => { return new MyCveNegativeTests() }
      }
      req.ctx.repositories = factory
      next()
    }, cveParams.parseGetParams, cveController.CVE_GET_SINGLE)
  
  server.route('/cve-get-record-positive-tests/:id')
    .get((req, res, next) => {
      const factory = {
        getCveRepository: () => { return new MyCvePositiveTests() }
      }
      req.ctx.repositories = factory
      next()
    }, cveParams.parseGetParams, cveController.CVE_GET_SINGLE)
  
  describe('Testing the GET /cve/:id endpoint in Cve Controller', () => {
    context('Negative Tests', () => {
      it('CVE_RECORD_DNE returned: The cve record does not exist for the provided cve id', (done) => {
        chai.request(server)
          .get(`/cve-get-record-negative-tests/${nonExistentCveRecord}`)
          .set(cveFixtures.secretariatHeader)
          .end((err, res) => {
            if (err) {
              done(err)
            }
  
            expect(res).to.have.status(404)
            expect(res).to.have.property('body').and.to.be.a('object')
            const errObj = error.cveRecordDne()
            expect(res.body.error).to.equal(errObj.error)
            expect(res.body.message).to.equal(errObj.message)
            done()
          })
      })
    })
  
    context('Positive Tests', () => {
      it('JSON schema v4.0 returned: The secretariat gets a cve record in PUBLIC state', (done) => {
        chai.request(server)
          .get(`/cve-get-record-positive-tests/${cveIdPublic4}`)
          .set(cveFixtures.secretariatHeader)
          .end((err, res) => {
            if (err) {
              done(err)
            }
  
            expect(res).to.have.status(200)
            expect(res).to.have.property('body').and.to.be.a('object')
            expect(res.body).to.have.nested.property('CVE_data_meta.ID').and.to.equal(cveIdPublic4)
            expect(res.body).to.have.nested.property('CVE_data_meta.STATE').and.to.equal(CONSTANTS.CVE_STATES.PUBLIC)
            done()
          })
      })
  
      it('JSON schema v4.0 returned: The secretariat gets a cve record in REJECT state', (done) => {
        chai.request(server)
          .get(`/cve-get-record-positive-tests/${cveIdReject4}`)
          .set(cveFixtures.secretariatHeader)
          .end((err, res) => {
            if (err) {
              done(err)
            }
  
            expect(res).to.have.status(200)
            expect(res).to.have.property('body').and.to.be.a('object')
            expect(res.body).to.have.nested.property('CVE_data_meta.ID').and.to.equal(cveIdReject4)
            expect(res.body).to.have.nested.property('CVE_data_meta.STATE').and.to.equal(CONSTANTS.CVE_STATES.REJECT)
            done()
          })
      })
    })
  })
  