@@ -164,7 +164,7 @@ describe('GET embed report', () => {
164
164
165
165
it ( 'should return 404 when report name not mock and not in EMBED_REPORTS_MAPPING' , ( done ) => {
166
166
const cfg = sinon . stub ( config , 'get' ) ;
167
- cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( false ) ;
167
+ cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( ' false' ) ;
168
168
request ( server )
169
169
. get ( `/v5/projects/${ project1 . id } /reports/embed?reportName=random` )
170
170
. set ( {
@@ -176,10 +176,27 @@ describe('GET embed report', () => {
176
176
} ) ;
177
177
} ) ;
178
178
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
+
179
196
it ( 'should return 500 when get admin user error' , ( done ) => {
180
197
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' ) ;
183
200
cfg . withArgs ( 'lookerConfig.EMBED_REPORTS_MAPPING' ) . returns ( '{"mock-concrete-customer": "/embed/looks/2"}' ) ;
184
201
request ( server )
185
202
. get ( `/v5/projects/${ project1 . id } /reports/embed?reportName=mock` )
@@ -195,8 +212,8 @@ describe('GET embed report', () => {
195
212
196
213
it ( 'should return 404 when the project template or product template is not found' , ( done ) => {
197
214
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' ) ;
200
217
cfg . withArgs ( 'lookerConfig.EMBED_REPORTS_MAPPING' ) . returns ( '{"mock-concrete-customer": "/embed/looks/2"}' ) ;
201
218
request ( server )
202
219
. get ( `/v5/projects/${ project0 . id } /reports/embed?reportName=mock` )
@@ -210,10 +227,48 @@ describe('GET embed report', () => {
210
227
} ) ;
211
228
} ) ;
212
229
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
+
213
268
it ( 'should return customer url' , ( done ) => {
214
269
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' ) ;
217
272
cfg . withArgs ( 'lookerConfig.EMBED_REPORTS_MAPPING' )
218
273
. returns ( '{"mock-concrete-customer": "/customer/embed/looks/2"}' ) ;
219
274
request ( server )
@@ -233,9 +288,9 @@ describe('GET embed report', () => {
233
288
should . exist ( resJson ) ;
234
289
resJson . should . equal ( 'generatedUrl' ) ;
235
290
const [ user , project , member , embedUrl ] = gem . lastCall . args ;
236
- user . userId . should . equal ( 40051331 ) ;
291
+ user . userId . should . equal ( testUtil . userIds . member ) ;
237
292
project . should . deep . equal ( { id : project1 . id } ) ;
238
- member . userId . should . equal ( 40051331 ) ;
293
+ member . userId . should . equal ( testUtil . userIds . member ) ;
239
294
member . role . should . equal ( 'customer' ) ;
240
295
embedUrl . should . equal ( '/customer/embed/looks/2' ) ;
241
296
done ( ) ;
@@ -245,13 +300,13 @@ describe('GET embed report', () => {
245
300
246
301
it ( 'should return admin url' , ( done ) => {
247
302
const cfg = sinon . stub ( config , 'get' ) ;
248
- const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrl ' , ( ) => 'generatedUrl' ) ;
303
+ const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrlForProject ' , ( ) => 'generatedUrl' ) ;
249
304
const getAdmin = sinon . stub ( util , 'getTopcoderUser' , ( ) => ( {
250
305
firstName : 'fn' ,
251
306
lastName : 'ln' ,
252
307
userId : 40051333 ,
253
308
} ) ) ;
254
- cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( false ) ;
309
+ cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( ' false' ) ;
255
310
cfg . withArgs ( 'lookerConfig.EMBED_REPORTS_MAPPING' ) . returns ( '{"mock-concrete-topcoder": "/admin/embed/looks/2"}' ) ;
256
311
request ( server )
257
312
. get ( `/v5/projects/${ project1 . id } /reports/embed?reportName=mock` )
@@ -271,9 +326,9 @@ describe('GET embed report', () => {
271
326
should . exist ( resJson ) ;
272
327
resJson . should . equal ( 'generatedUrl' ) ;
273
328
const [ user , project , member , embedUrl ] = gem . lastCall . args ;
274
- user . userId . should . equal ( 40051333 ) ;
329
+ user . userId . should . equal ( testUtil . userIds . admin ) ;
275
330
project . should . deep . equal ( { id : project1 . id } ) ;
276
- member . userId . should . equal ( 40051333 ) ;
331
+ member . userId . should . equal ( testUtil . userIds . admin ) ;
277
332
member . firstName . should . equal ( 'fn' ) ;
278
333
member . lastName . should . equal ( 'ln' ) ;
279
334
member . role . should . equal ( '' ) ;
@@ -285,8 +340,8 @@ describe('GET embed report', () => {
285
340
286
341
it ( 'should return copilot url' , ( done ) => {
287
342
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' ) ;
290
345
cfg . withArgs ( 'lookerConfig.EMBED_REPORTS_MAPPING' ) . returns ( '{"mock-concrete-copilot": "/copilot/embed/looks/2"}' ) ;
291
346
request ( server )
292
347
. get ( `/v5/projects/${ project1 . id } /reports/embed?reportName=mock` )
@@ -305,9 +360,9 @@ describe('GET embed report', () => {
305
360
should . exist ( resJson ) ;
306
361
resJson . should . equal ( 'generatedUrl' ) ;
307
362
const [ user , project , member , embedUrl ] = gem . lastCall . args ;
308
- user . userId . should . equal ( 40051332 ) ;
363
+ user . userId . should . equal ( testUtil . userIds . copilot ) ;
309
364
project . should . deep . equal ( { id : project1 . id } ) ;
310
- member . userId . should . equal ( 40051332 ) ;
365
+ member . userId . should . equal ( testUtil . userIds . copilot ) ;
311
366
member . role . should . equal ( 'copilot' ) ;
312
367
embedUrl . should . equal ( '/copilot/embed/looks/2' ) ;
313
368
done ( ) ;
@@ -317,13 +372,13 @@ describe('GET embed report', () => {
317
372
318
373
it ( 'should return admin url for project with product template' , ( done ) => {
319
374
const cfg = sinon . stub ( config , 'get' ) ;
320
- const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrl ' , ( ) => 'generatedUrl' ) ;
375
+ const gem = sinon . stub ( lookerSerivce , 'generateEmbedUrlForProject ' , ( ) => 'generatedUrl' ) ;
321
376
const getAdmin = sinon . stub ( util , 'getTopcoderUser' , ( ) => ( {
322
377
firstName : 'fn' ,
323
378
lastName : 'ln' ,
324
379
userId : 40051333 ,
325
380
} ) ) ;
326
- cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( false ) ;
381
+ cfg . withArgs ( 'lookerConfig.USE_MOCK' ) . returns ( ' false' ) ;
327
382
cfg . withArgs ( 'lookerConfig.EMBED_REPORTS_MAPPING' )
328
383
. returns ( '{"mock-prodCut-topcoder": "/admin/embed/looks/3"}' ) ;
329
384
request ( server )
@@ -344,9 +399,9 @@ describe('GET embed report', () => {
344
399
should . exist ( resJson ) ;
345
400
resJson . should . equal ( 'generatedUrl' ) ;
346
401
const [ user , project , member , embedUrl ] = gem . lastCall . args ;
347
- user . userId . should . equal ( 40051333 ) ;
402
+ user . userId . should . equal ( testUtil . userIds . admin ) ;
348
403
project . should . deep . equal ( { id : project3 . id } ) ;
349
- member . userId . should . equal ( 40051333 ) ;
404
+ member . userId . should . equal ( testUtil . userIds . admin ) ;
350
405
member . firstName . should . equal ( 'fn' ) ;
351
406
member . lastName . should . equal ( 'ln' ) ;
352
407
member . role . should . equal ( '' ) ;
0 commit comments