|
| 1 | +/* eslint-disable no-unused-expressions */ |
| 2 | + |
| 3 | +const chai = require('chai') |
| 4 | +chai.use(require('chai-http')) |
| 5 | +const expect = chai.expect |
| 6 | + |
| 7 | +const constants = require('../constants.js') |
| 8 | +const app = require('../../../src/index.js') |
| 9 | + |
| 10 | +describe('Test get /cve_count for CVE records', () => { |
| 11 | + context('Positive Tests', () => { |
| 12 | + it('Get /cve_count should allow any user to get count', async () => { |
| 13 | + await chai.request(app) |
| 14 | + .get('/api/cve_count') |
| 15 | + .then((res, err) => { |
| 16 | + expect(err).to.be.undefined |
| 17 | + expect(res).to.have.status(200) |
| 18 | + expect(res.body).to.have.property('totalCount').that.is.a('number') |
| 19 | + }) |
| 20 | + }) |
| 21 | + it('Get /cve_count should allow privledged user to get count also', async () => { |
| 22 | + await chai.request(app) |
| 23 | + .get('/api/cve_count') |
| 24 | + .set(constants.headers) |
| 25 | + .then((res, err) => { |
| 26 | + expect(err).to.be.undefined |
| 27 | + expect(res).to.have.status(200) |
| 28 | + expect(res.body).to.have.property('totalCount').that.is.a('number') |
| 29 | + }) |
| 30 | + }) |
| 31 | + it('Get /cve_count should return count with valid parameters', async () => { |
| 32 | + await chai.request(app) |
| 33 | + .get('/api/cve_count?state=PUBLISHED') |
| 34 | + .set(constants.headers) |
| 35 | + .then((res, err) => { |
| 36 | + expect(err).to.be.undefined |
| 37 | + expect(res).to.have.status(200) |
| 38 | + expect(res.body).to.have.property('totalCount').that.is.a('number') |
| 39 | + }) |
| 40 | + }) |
| 41 | + }) |
| 42 | + context('Negative Tests', () => { |
| 43 | + it('Get /cve should NOT allow any user to get count', async () => { |
| 44 | + await chai.request(app) |
| 45 | + .get('/api/cve?count_only=1') |
| 46 | + .then((res, err) => { |
| 47 | + expect(err).to.be.undefined |
| 48 | + expect(res).to.have.status(400) |
| 49 | + }) |
| 50 | + }) |
| 51 | + it('Get /cve_count should fail if it is passed invalid parameters', async () => { |
| 52 | + await chai.request(app) |
| 53 | + .get('/api/cve_count?time_modified.gt=2022-13-01T00:00:00Z') |
| 54 | + .set(constants.headers) |
| 55 | + .then((res, err) => { |
| 56 | + expect(err).to.be.undefined |
| 57 | + expect(res).to.have.status(400) |
| 58 | + expect(res.body.message).to.contain('Parameters were invalid') |
| 59 | + }) |
| 60 | + }) |
| 61 | + it('Get /cve_count should fail if it is `state` parameter value is invalid ', async () => { |
| 62 | + await chai.request(app) |
| 63 | + .get('/api/cve_count?state=SUCESS') |
| 64 | + .set(constants.headers) |
| 65 | + .then((res, err) => { |
| 66 | + expect(err).to.be.undefined |
| 67 | + expect(res).to.have.status(400) |
| 68 | + expect(res.body.message).to.contain('Parameters were invalid') |
| 69 | + }) |
| 70 | + }) |
| 71 | + }) |
| 72 | +}) |
0 commit comments