/* eslint-disable no-unused-expressions */

const chai = require('chai')
chai.use(require('chai-http'))
const expect = chai.expect

const constants = require('../constants.js')
const app = require('../../../src/index.js')
const helpers = require('../helpers.js')

const shortName = 'win_5'

describe('Text PUT CVE-ID/:id', () => {
  let cveId
  before(async () => {
    cveId = await helpers.cveIdReserveHelper(1, '2023', shortName, 'non-sequential')
  })
  context('State parameter Tests', () => {
    it('Endpoint should return a 400 when state org is set to published', async () => {
      await chai.request(app)
        .put(`/api/cve-id/${cveId}?state=PUBLISHED`)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
        })
    })
    it('Endpoint should allow the state parameter to be set to reserved', async () => {
      await chai.request(app)
        .put(`/api/cve-id/${cveId}?state=REJECTED`)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
        })
    })
    it('Endpoint should still not allow a REJECTED endpoint to be set to published', async () => {
      await chai.request(app)
        .put(`/api/cve-id/${cveId}?state=PUBLISHED`)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
        })
    })
  })
})
