Skip to content

Commit 91c6e32

Browse files
authored
Merge pull request #1517 from CVEProject/dr_1500_quota_unit_tests
Fixed idQuota tests
2 parents 358ae9e + 83ae111 commit 91c6e32

File tree

2 files changed

+81
-8
lines changed

2 files changed

+81
-8
lines changed

src/controller/org.controller/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,6 @@ router.get('/org/:shortname/id_quota',
554554
}
555555
*/
556556

557-
param(['registry']).optional().isBoolean(),
558-
mw.handleRegistryParameter,
559557
mw.validateUser,
560558
param(['shortname']).isString().trim().notEmpty().isLength({ min: CONSTANTS.MIN_SHORTNAME_LENGTH, max: CONSTANTS.MAX_SHORTNAME_LENGTH }),
561559
parseError,

test/unit-tests/org/orgGetIdQuotaTest.js

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const express = require('express')
22
const app = express()
33
const chai = require('chai')
4+
const sinon = require('sinon')
45
const expect = chai.expect
56
chai.use(require('chai-http'))
7+
const mongoose = require('mongoose')
68

79
// Body Parser Middleware
810
app.use(express.json()) // Allows us to handle raw JSON data
@@ -19,7 +21,22 @@ const orgFixtures = require('./mockObjects.org')
1921
const orgController = require('../../../src/controller/org.controller/org.controller')
2022
const orgParams = require('../../../src/controller/org.controller/org.middleware')
2123

22-
describe.skip('Testing the GET /org/:shortname/id_quota endpoint in Org Controller', () => {
24+
describe('Testing the GET /org/:shortname/id_quota endpoint in Org Controller', () => {
25+
let mockSession
26+
beforeEach(() => {
27+
mockSession = {
28+
startTransaction: sinon.stub(),
29+
commitTransaction: sinon.stub().resolves(),
30+
abortTransaction: sinon.stub().resolves(),
31+
endSession: sinon.stub().resolves()
32+
}
33+
sinon.stub(mongoose, 'startSession').resolves(mockSession)
34+
})
35+
36+
afterEach(() => {
37+
sinon.restore()
38+
})
39+
2340
context('Negative Tests', () => {
2441
it('Org with a negative id_quota was not saved', (done) => {
2542
const org = new Org(orgFixtures.orgWithNegativeIdQuota)
@@ -53,12 +70,17 @@ describe.skip('Testing the GET /org/:shortname/id_quota endpoint in Org Controll
5370
async isSecretariat () {
5471
return false
5572
}
73+
74+
async findOneByShortName () {
75+
return 'microsoft'
76+
}
5677
}
5778

5879
app.route('/org-id_quota-not-owning-secretariat-org/:shortname')
5980
.get((req, res, next) => {
6081
const factory = {
61-
getOrgRepository: () => { return new OrgNotOwnerOrSecretariatIdQuota() }
82+
getOrgRepository: () => { return new OrgNotOwnerOrSecretariatIdQuota() },
83+
getBaseOrgRepository: () => { return new OrgNotOwnerOrSecretariatIdQuota() }
6284
}
6385
req.ctx.repositories = factory
6486
next()
@@ -90,12 +112,16 @@ describe.skip('Testing the GET /org/:shortname/id_quota endpoint in Org Controll
90112
async findOneByShortName () {
91113
return null
92114
}
115+
116+
async getOrg () {
117+
return null
118+
}
93119
}
94120

95121
app.route('/org-id_quota-org-does-not-exist/:shortname')
96122
.get((req, res, next) => {
97123
const factory = {
98-
getOrgRepository: () => { return new OrgDoesNotExistIdQuota() }
124+
getBaseOrgRepository: () => { return new OrgDoesNotExistIdQuota() }
99125
}
100126
req.ctx.repositories = factory
101127
next()
@@ -133,6 +159,18 @@ describe.skip('Testing the GET /org/:shortname/id_quota endpoint in Org Controll
133159
async getOrgUUID () {
134160
return orgFixtures.existentOrg.UUID
135161
}
162+
163+
async getOrg () {
164+
return orgFixtures.existentOrg.UUID
165+
}
166+
167+
async getOrgIdQuota () {
168+
return {
169+
id_quota: 1000,
170+
total_reserved: 0,
171+
available: 1000
172+
}
173+
}
136174
}
137175

138176
class CveIdSecretariatIdQuota {
@@ -144,7 +182,7 @@ describe.skip('Testing the GET /org/:shortname/id_quota endpoint in Org Controll
144182
app.route('/org-id_quota-secretariat/:shortname')
145183
.get((req, res, next) => {
146184
const factory = {
147-
getOrgRepository: () => { return new OrgSecretariatIdQuota() },
185+
getBaseOrgRepository: () => { return new OrgSecretariatIdQuota() },
148186
getCveIdRepository: () => { return new CveIdSecretariatIdQuota() }
149187
}
150188
req.ctx.repositories = factory
@@ -181,6 +219,18 @@ describe.skip('Testing the GET /org/:shortname/id_quota endpoint in Org Controll
181219
async getOrgUUID () {
182220
return orgFixtures.owningOrg.UUID
183221
}
222+
223+
async getOrg () {
224+
return orgFixtures.existentOrg.UUID
225+
}
226+
227+
async getOrgIdQuota () {
228+
return {
229+
id_quota: 5,
230+
total_reserved: 0,
231+
available: 5
232+
}
233+
}
184234
}
185235

186236
class CveIdOwnerIdQuota {
@@ -193,6 +243,7 @@ describe.skip('Testing the GET /org/:shortname/id_quota endpoint in Org Controll
193243
.get((req, res, next) => {
194244
const factory = {
195245
getOrgRepository: () => { return new OrgOwnerIdQuota() },
246+
getBaseOrgRepository: () => { return new OrgOwnerIdQuota() },
196247
getCveIdRepository: () => { return new CveIdOwnerIdQuota() }
197248
}
198249
req.ctx.repositories = factory
@@ -229,6 +280,18 @@ describe.skip('Testing the GET /org/:shortname/id_quota endpoint in Org Controll
229280
async getOrgUUID () {
230281
return orgFixtures.orgWithNegativeIdQuota.UUID
231282
}
283+
284+
async getOrg () {
285+
return orgFixtures.existentOrg.UUID
286+
}
287+
288+
async getOrgIdQuota () {
289+
return {
290+
id_quota: -1,
291+
total_reserved: 0,
292+
available: -1
293+
}
294+
}
232295
}
233296

234297
class CveIdExceedsMinQuota {
@@ -240,7 +303,7 @@ describe.skip('Testing the GET /org/:shortname/id_quota endpoint in Org Controll
240303
app.route('/org-id_quota-exceeds-min-quota-limit/:shortname')
241304
.get((req, res, next) => {
242305
const factory = {
243-
getOrgRepository: () => { return new OrgExceedsMinIdQuota() },
306+
getBaseOrgRepository: () => { return new OrgExceedsMinIdQuota() },
244307
getCveIdRepository: () => { return new CveIdExceedsMinQuota() }
245308
}
246309
req.ctx.repositories = factory
@@ -277,6 +340,18 @@ describe.skip('Testing the GET /org/:shortname/id_quota endpoint in Org Controll
277340
async getOrgUUID () {
278341
return orgFixtures.orgExceedingMaxIdQuota.UUID
279342
}
343+
344+
async getOrg () {
345+
return orgFixtures.existentOrg.UUID
346+
}
347+
348+
async getOrgIdQuota () {
349+
return {
350+
id_quota: 100500,
351+
total_reserved: 0,
352+
available: 100500
353+
}
354+
}
280355
}
281356

282357
class CveIdExceedsMaxQuota {
@@ -288,7 +363,7 @@ describe.skip('Testing the GET /org/:shortname/id_quota endpoint in Org Controll
288363
app.route('/org-id_quota-exceeds-max-quota-limit/:shortname')
289364
.get((req, res, next) => {
290365
const factory = {
291-
getOrgRepository: () => { return new OrgExceedsMaxIdQuota() },
366+
getBaseOrgRepository: () => { return new OrgExceedsMaxIdQuota() },
292367
getCveIdRepository: () => { return new CveIdExceedsMaxQuota() }
293368
}
294369
req.ctx.repositories = factory

0 commit comments

Comments
 (0)