11const express = require ( 'express' )
22const app = express ( )
33const chai = require ( 'chai' )
4+ const sinon = require ( 'sinon' )
45const expect = chai . expect
6+ const mongoose = require ( 'mongoose' )
57chai . use ( require ( 'chai-http' ) )
68
79// Body Parser Middleware
@@ -14,33 +16,35 @@ const orgFixtures = require('./mockObjects.org')
1416const orgController = require ( '../../../src/controller/org.controller/org.controller' )
1517const orgParams = require ( '../../../src/controller/org.controller/org.middleware' )
1618
17- describe . skip ( 'Testing the GET /org endpoint in Org Controller' , ( ) => {
19+ describe ( 'Testing the GET /org endpoint in Org Controller' , ( ) => {
20+ let mockSession
21+ beforeEach ( ( ) => {
22+ // Stub Mongoose session methods
23+ mockSession = {
24+ startTransaction : sinon . stub ( ) ,
25+ commitTransaction : sinon . stub ( ) . resolves ( ) ,
26+ abortTransaction : sinon . stub ( ) . resolves ( ) ,
27+ endSession : sinon . stub ( ) . resolves ( )
28+ }
29+ sinon . stub ( mongoose , 'startSession' ) . resolves ( mockSession )
30+ } )
31+ afterEach ( ( ) => {
32+ sinon . restore ( )
33+ } )
1834 context ( 'Positive Tests' , ( ) => {
1935 it ( 'Page query param not provided: should list non-paginated orgs because orgs fit in one page' , async ( ) => {
20- const itemsPerPage = 500
21-
2236 class GetAllOrgs {
23- async aggregatePaginate ( ) {
24- const res = {
25- itemsList : orgFixtures . allOrgs ,
26- itemCount : orgFixtures . allOrgs . length ,
27- itemsPerPage : itemsPerPage ,
28- currentPage : 1 ,
29- pageCount : 1 ,
30- pagingCounter : 1 ,
31- hasPrevPage : false ,
32- hasNextPage : false ,
33- prevPage : null ,
34- nextPage : null
37+ async getAllOrgs ( ) {
38+ return {
39+ organizations : orgFixtures . allOrgs
3540 }
36- return res
3741 }
3842 }
3943
4044 app . route ( '/org-all-cnas-non-paginated' )
4145 . get ( ( req , res , next ) => {
4246 const factory = {
43- getOrgRepository : ( ) => { return new GetAllOrgs ( ) }
47+ getBaseOrgRepository : ( ) => { return new GetAllOrgs ( ) }
4448 }
4549 req . ctx . repositories = factory
4650 next ( )
@@ -66,10 +70,10 @@ describe.skip('Testing the GET /org endpoint in Org Controller', () => {
6670 const itemsPerPage = 5
6771
6872 class GetAllOrgs {
69- async aggregatePaginate ( ) {
73+ async getAllOrgs ( ) {
7074 const res = {
71- itemsList : [ orgFixtures . allOrgs [ 0 ] , orgFixtures . allOrgs [ 1 ] , orgFixtures . allOrgs [ 3 ] , orgFixtures . allOrgs [ 3 ] , orgFixtures . allOrgs [ 4 ] ] ,
72- itemCount : orgFixtures . allOrgs . length ,
75+ organizations : [ orgFixtures . allOrgs [ 0 ] , orgFixtures . allOrgs [ 1 ] , orgFixtures . allOrgs [ 3 ] , orgFixtures . allOrgs [ 3 ] , orgFixtures . allOrgs [ 4 ] ] ,
76+ totalCount : orgFixtures . allOrgs . length ,
7377 itemsPerPage : itemsPerPage ,
7478 currentPage : 1 ,
7579 pageCount : 2 ,
@@ -86,10 +90,10 @@ describe.skip('Testing the GET /org endpoint in Org Controller', () => {
8690 app . route ( '/org-all-cnas-paginated' )
8791 . get ( ( req , res , next ) => {
8892 const factory = {
89- getOrgRepository : ( ) => { return new GetAllOrgs ( ) }
93+ getBaseOrgRepository : ( ) => { return new GetAllOrgs ( ) }
9094 }
9195 req . ctx . repositories = factory
92- // temporary fix for #920: force pagnation
96+ // temporary fix for #920: force pagination
9397 req . TEST_PAGINATOR_LIMIT = itemsPerPage
9498 next ( )
9599 } , orgParams . parseGetParams , orgController . ORG_ALL )
@@ -114,10 +118,10 @@ describe.skip('Testing the GET /org endpoint in Org Controller', () => {
114118 const itemsPerPage = 5
115119
116120 class GetAllOrgs {
117- async aggregatePaginate ( ) {
121+ async getAllOrgs ( ) {
118122 const res = {
119- itemsList : [ orgFixtures . allOrgs [ 5 ] , orgFixtures . allOrgs [ 6 ] , orgFixtures . allOrgs [ 7 ] , orgFixtures . allOrgs [ 8 ] ] ,
120- itemCount : orgFixtures . allOrgs . length ,
123+ organizations : [ orgFixtures . allOrgs [ 5 ] , orgFixtures . allOrgs [ 6 ] , orgFixtures . allOrgs [ 7 ] , orgFixtures . allOrgs [ 8 ] ] ,
124+ totalCount : orgFixtures . allOrgs . length ,
121125 itemsPerPage : itemsPerPage ,
122126 currentPage : 2 ,
123127 pageCount : 2 ,
@@ -134,7 +138,7 @@ describe.skip('Testing the GET /org endpoint in Org Controller', () => {
134138 app . route ( '/org-all-cnas-paginated-2' )
135139 . get ( ( req , res , next ) => {
136140 const factory = {
137- getOrgRepository : ( ) => { return new GetAllOrgs ( ) }
141+ getBaseOrgRepository : ( ) => { return new GetAllOrgs ( ) }
138142 }
139143 req . ctx . repositories = factory
140144 // temporary fix for #920: force pagnation
@@ -159,21 +163,10 @@ describe.skip('Testing the GET /org endpoint in Org Controller', () => {
159163 } )
160164
161165 it ( 'Page query param provided: should return an empty list because no org exists' , async ( ) => {
162- const itemsPerPage = 5
163-
164166 class GetAllOrgs {
165- async aggregatePaginate ( ) {
167+ async getAllOrgs ( ) {
166168 const res = {
167- itemsList : [ ] ,
168- itemCount : 0 ,
169- itemsPerPage : itemsPerPage ,
170- currentPage : 1 ,
171- pageCount : 1 ,
172- pagingCounter : 1 ,
173- hasPrevPage : false ,
174- hasNextPage : false ,
175- prevPage : null ,
176- nextPage : null
169+ organizations : [ ]
177170 }
178171 return res
179172 }
@@ -182,7 +175,7 @@ describe.skip('Testing the GET /org endpoint in Org Controller', () => {
182175 app . route ( '/org-all-cnas-empty' )
183176 . get ( ( req , res , next ) => {
184177 const factory = {
185- getOrgRepository : ( ) => { return new GetAllOrgs ( ) }
178+ getBaseOrgRepository : ( ) => { return new GetAllOrgs ( ) }
186179 }
187180 req . ctx . repositories = factory
188181 next ( )
0 commit comments