@@ -164,7 +164,7 @@ describe('GET embed report', () => {
164164
165165 it ( 'should return 404 when report name not mock and not in EMBED_REPORTS_MAPPING' , ( done ) => {
166166 const cfg = sinon . stub ( config , 'get' ) ;
167- cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( false ) ;
167+ cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( ' false' ) ;
168168 request ( server )
169169 . get ( `/v5/projects/${ project1 . id } /reports/embed?reportName=random` )
170170 . set ( {
@@ -176,10 +176,27 @@ describe('GET embed report', () => {
176176 } ) ;
177177 } ) ;
178178
179+ it ( 'should return 403 when report name not mock and not in EMBED_REPORTS_MAPPING' , ( done ) => {
180+ const cfg = sinon . stub ( config , 'get' ) ;
181+ cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( 'false' ) ;
182+ // allows only admin user
183+ cfg . withArgs ( 'lookerConfig.ALLOWED_USERS' ) . returns ( `[${ testUtil . userIds . admin } ]` ) ;
184+ cfg . withArgs ( 'lookerConfig.EMBED_REPORTS_MAPPING' ) . returns ( '{"mock": "/embed/looks/2"}' ) ;
185+ request ( server )
186+ . get ( `/v5/projects/${ project1 . id } /reports/embed?reportName=random` )
187+ . set ( {
188+ Authorization : `Bearer ${ testUtil . jwts . member } ` ,
189+ } )
190+ . expect ( 403 , ( err ) => {
191+ cfg . restore ( ) ;
192+ done ( err ) ;
193+ } ) ;
194+ } ) ;
195+
179196 it ( 'should return 500 when get admin user error' , ( done ) => {
180197 const cfg = sinon . stub ( config , 'get' ) ;
181- const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrl ' , ( ) => 'generatedUrl' ) ;
182- cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( false ) ;
198+ const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrlForProject ' , ( ) => 'generatedUrl' ) ;
199+ cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( ' false' ) ;
183200 cfg . withArgs ( 'lookerConfig.EMBED_REPORTS_MAPPING' ) . returns ( '{"mock-concrete-customer": "/embed/looks/2"}' ) ;
184201 request ( server )
185202 . get ( `/v5/projects/${ project1 . id } /reports/embed?reportName=mock` )
@@ -195,8 +212,8 @@ describe('GET embed report', () => {
195212
196213 it ( 'should return 404 when the project template or product template is not found' , ( done ) => {
197214 const cfg = sinon . stub ( config , 'get' ) ;
198- const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrl ' , ( ) => 'generatedUrl' ) ;
199- cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( false ) ;
215+ const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrlForProject ' , ( ) => 'generatedUrl' ) ;
216+ cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( ' false' ) ;
200217 cfg . withArgs ( 'lookerConfig.EMBED_REPORTS_MAPPING' ) . returns ( '{"mock-concrete-customer": "/embed/looks/2"}' ) ;
201218 request ( server )
202219 . get ( `/v5/projects/${ project0 . id } /reports/embed?reportName=mock` )
@@ -210,10 +227,48 @@ describe('GET embed report', () => {
210227 } ) ;
211228 } ) ;
212229
230+ it ( 'should return mock url' , ( done ) => {
231+ const cfg = sinon . stub ( config , 'get' ) ;
232+ const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrlForProject' , ( ) => 'generatedUrl' ) ;
233+ const getUser = sinon . stub ( util , 'getTopcoderUser' , ( ) => ( {
234+ firstName : 'fn' ,
235+ lastName : 'ln' ,
236+ userId : testUtil . userIds . member ,
237+ } ) ) ;
238+ cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( 'true' ) ;
239+ cfg . withArgs ( 'lookerConfig.EMBED_REPORTS_MAPPING' )
240+ . returns ( '{"mock": "/customer/embed/looks/2"}' ) ;
241+ request ( server )
242+ . get ( `/v5/projects/${ project1 . id } /reports/embed?reportName=mock` )
243+ . set ( {
244+ Authorization : `Bearer ${ testUtil . jwts . member } ` ,
245+ } )
246+ . expect ( 'Content-Type' , / j s o n / )
247+ . expect ( 200 )
248+ . end ( ( err , res ) => {
249+ getUser . restore ( ) ;
250+ gem . restore ( ) ;
251+ cfg . restore ( ) ;
252+ if ( err ) {
253+ done ( err ) ;
254+ } else {
255+ const resJson = res . body ;
256+ should . exist ( resJson ) ;
257+ resJson . should . equal ( 'generatedUrl' ) ;
258+ const [ user , project , member , embedUrl ] = gem . lastCall . args ;
259+ user . userId . should . equal ( testUtil . userIds . member ) ;
260+ project . should . deep . equal ( { id : project1 . id } ) ;
261+ member . userId . should . equal ( testUtil . userIds . member ) ;
262+ embedUrl . should . equal ( '/customer/embed/looks/2' ) ;
263+ done ( ) ;
264+ }
265+ } ) ;
266+ } ) ;
267+
213268 it ( 'should return customer url' , ( done ) => {
214269 const cfg = sinon . stub ( config , 'get' ) ;
215- const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrl ' , ( ) => 'generatedUrl' ) ;
216- cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( false ) ;
270+ const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrlForProject ' , ( ) => 'generatedUrl' ) ;
271+ cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( ' false' ) ;
217272 cfg . withArgs ( 'lookerConfig.EMBED_REPORTS_MAPPING' )
218273 . returns ( '{"mock-concrete-customer": "/customer/embed/looks/2"}' ) ;
219274 request ( server )
@@ -233,9 +288,9 @@ describe('GET embed report', () => {
233288 should . exist ( resJson ) ;
234289 resJson . should . equal ( 'generatedUrl' ) ;
235290 const [ user , project , member , embedUrl ] = gem . lastCall . args ;
236- user . userId . should . equal ( 40051331 ) ;
291+ user . userId . should . equal ( testUtil . userIds . member ) ;
237292 project . should . deep . equal ( { id : project1 . id } ) ;
238- member . userId . should . equal ( 40051331 ) ;
293+ member . userId . should . equal ( testUtil . userIds . member ) ;
239294 member . role . should . equal ( 'customer' ) ;
240295 embedUrl . should . equal ( '/customer/embed/looks/2' ) ;
241296 done ( ) ;
@@ -245,13 +300,13 @@ describe('GET embed report', () => {
245300
246301 it ( 'should return admin url' , ( done ) => {
247302 const cfg = sinon . stub ( config , 'get' ) ;
248- const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrl ' , ( ) => 'generatedUrl' ) ;
303+ const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrlForProject ' , ( ) => 'generatedUrl' ) ;
249304 const getAdmin = sinon . stub ( util , 'getTopcoderUser' , ( ) => ( {
250305 firstName : 'fn' ,
251306 lastName : 'ln' ,
252307 userId : 40051333 ,
253308 } ) ) ;
254- cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( false ) ;
309+ cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( ' false' ) ;
255310 cfg . withArgs ( 'lookerConfig.EMBED_REPORTS_MAPPING' ) . returns ( '{"mock-concrete-topcoder": "/admin/embed/looks/2"}' ) ;
256311 request ( server )
257312 . get ( `/v5/projects/${ project1 . id } /reports/embed?reportName=mock` )
@@ -271,9 +326,9 @@ describe('GET embed report', () => {
271326 should . exist ( resJson ) ;
272327 resJson . should . equal ( 'generatedUrl' ) ;
273328 const [ user , project , member , embedUrl ] = gem . lastCall . args ;
274- user . userId . should . equal ( 40051333 ) ;
329+ user . userId . should . equal ( testUtil . userIds . admin ) ;
275330 project . should . deep . equal ( { id : project1 . id } ) ;
276- member . userId . should . equal ( 40051333 ) ;
331+ member . userId . should . equal ( testUtil . userIds . admin ) ;
277332 member . firstName . should . equal ( 'fn' ) ;
278333 member . lastName . should . equal ( 'ln' ) ;
279334 member . role . should . equal ( '' ) ;
@@ -285,8 +340,8 @@ describe('GET embed report', () => {
285340
286341 it ( 'should return copilot url' , ( done ) => {
287342 const cfg = sinon . stub ( config , 'get' ) ;
288- const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrl ' , ( ) => 'generatedUrl' ) ;
289- cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( false ) ;
343+ const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrlForProject ' , ( ) => 'generatedUrl' ) ;
344+ cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( ' false' ) ;
290345 cfg . withArgs ( 'lookerConfig.EMBED_REPORTS_MAPPING' ) . returns ( '{"mock-concrete-copilot": "/copilot/embed/looks/2"}' ) ;
291346 request ( server )
292347 . get ( `/v5/projects/${ project1 . id } /reports/embed?reportName=mock` )
@@ -305,9 +360,9 @@ describe('GET embed report', () => {
305360 should . exist ( resJson ) ;
306361 resJson . should . equal ( 'generatedUrl' ) ;
307362 const [ user , project , member , embedUrl ] = gem . lastCall . args ;
308- user . userId . should . equal ( 40051332 ) ;
363+ user . userId . should . equal ( testUtil . userIds . copilot ) ;
309364 project . should . deep . equal ( { id : project1 . id } ) ;
310- member . userId . should . equal ( 40051332 ) ;
365+ member . userId . should . equal ( testUtil . userIds . copilot ) ;
311366 member . role . should . equal ( 'copilot' ) ;
312367 embedUrl . should . equal ( '/copilot/embed/looks/2' ) ;
313368 done ( ) ;
@@ -317,13 +372,13 @@ describe('GET embed report', () => {
317372
318373 it ( 'should return admin url for project with product template' , ( done ) => {
319374 const cfg = sinon . stub ( config , 'get' ) ;
320- const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrl ' , ( ) => 'generatedUrl' ) ;
375+ const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrlForProject ' , ( ) => 'generatedUrl' ) ;
321376 const getAdmin = sinon . stub ( util , 'getTopcoderUser' , ( ) => ( {
322377 firstName : 'fn' ,
323378 lastName : 'ln' ,
324379 userId : 40051333 ,
325380 } ) ) ;
326- cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( false ) ;
381+ cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( ' false' ) ;
327382 cfg . withArgs ( 'lookerConfig.EMBED_REPORTS_MAPPING' )
328383 . returns ( '{"mock-prodCut-topcoder": "/admin/embed/looks/3"}' ) ;
329384 request ( server )
@@ -344,9 +399,9 @@ describe('GET embed report', () => {
344399 should . exist ( resJson ) ;
345400 resJson . should . equal ( 'generatedUrl' ) ;
346401 const [ user , project , member , embedUrl ] = gem . lastCall . args ;
347- user . userId . should . equal ( 40051333 ) ;
402+ user . userId . should . equal ( testUtil . userIds . admin ) ;
348403 project . should . deep . equal ( { id : project3 . id } ) ;
349- member . userId . should . equal ( 40051333 ) ;
404+ member . userId . should . equal ( testUtil . userIds . admin ) ;
350405 member . firstName . should . equal ( 'fn' ) ;
351406 member . lastName . should . equal ( 'ln' ) ;
352407 member . role . should . equal ( '' ) ;
0 commit comments