11const express = require ( 'express' )
22const app = express ( )
33const chai = require ( 'chai' )
4+ const sinon = require ( 'sinon' )
45const expect = chai . expect
56chai . use ( require ( 'chai-http' ) )
7+ const mongoose = require ( 'mongoose' )
68
79// Body Parser Middleware
810app . use ( express . json ( ) ) // Allows us to handle raw JSON data
@@ -19,7 +21,22 @@ const orgFixtures = require('./mockObjects.org')
1921const orgController = require ( '../../../src/controller/org.controller/org.controller' )
2022const 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