1
+ import { ProductActionsResponse } from '@kong/sdk-portal-js'
1
2
import { product , versions } from '../fixtures/consts'
2
3
import petstoreJson from '../fixtures/oas_specs/petstoreJson.json'
3
4
import petstoreJson3 from '../fixtures/oas_specs/petstoreJson3.0.json'
@@ -330,18 +331,23 @@ describe('Spec Renderer Page', () => {
330
331
rbac_enabled : true
331
332
} ) . as ( 'getPortalContext' )
332
333
333
- cy . intercept ( 'GET' , 'api/v2/portals/*/developers/me/permissions' , {
334
+ const response : ProductActionsResponse = {
335
+ actions : {
336
+ register : false ,
337
+ view : false ,
338
+ view_documentation : false
339
+ }
340
+ }
341
+
342
+ cy . intercept ( 'GET' , '/api/v2/products/*/actions' , {
334
343
statusCode : 200 ,
335
- body : [ {
336
- resource : 'krn:konnect:reg/*:org/*:portals/*/services/*' ,
337
- actions : [ ]
338
- } ] ,
344
+ body : response ,
339
345
delay : 300
340
- } ) . as ( 'getPermissions ' )
346
+ } ) . as ( 'getProductActions ' )
341
347
342
348
cy . visit ( `/spec/${ product . id } ` )
343
349
344
- cy . wait ( '@getPermissions ' )
350
+ cy . wait ( '@getProductActions ' )
345
351
346
352
cy . get ( '[data-testid="forbidden"]' ) . should ( 'exist' )
347
353
} )
@@ -351,39 +357,41 @@ describe('Spec Renderer Page', () => {
351
357
rbac_enabled : true
352
358
} ) . as ( 'getPortalContext' )
353
359
354
- cy . intercept ( 'GET' , 'api/v2/portals/*/developers/me/permissions' , {
360
+ const response : ProductActionsResponse = {
361
+ actions : {
362
+ register : true ,
363
+ view : true ,
364
+ view_documentation : true
365
+ }
366
+ }
367
+
368
+ cy . intercept ( 'GET' , '/api/v2/products/*/actions' , {
355
369
statusCode : 200 ,
356
- body : [ {
357
- resource : 'krn:konnect:reg/*:org/*:portals/*/services/*' ,
358
- actions : [
359
- '#view' ,
360
- '#consume'
361
- ]
362
- } ] ,
370
+ body : response ,
363
371
delay : 300
364
- } ) . as ( 'getPermissions ' )
372
+ } ) . as ( 'getProductActions ' )
365
373
366
374
cy . visit ( `/spec/${ product . id } ` )
367
375
368
- cy . wait ( '@getPermissions ' )
376
+ cy . wait ( '@getProductActions ' )
369
377
370
378
cy . get ( '[data-testid="kong-public-ui-spec-details-swagger"]' , { timeout : 12000 } )
371
379
. get ( '.info h2' ) . should ( 'contain' , 'Swagger Petstore' )
372
380
373
381
cy . get ( '[data-testid="register-button"]' ) . should ( 'exist' )
374
382
} )
375
383
376
- it ( 'does not call developers/me/permissions if rbac not enabled' , ( ) => {
384
+ it ( 'does not retrieve product actions if rbac not enabled' , ( ) => {
377
385
cy . intercept ( 'GET' , '**/api/v2/portal' , {
378
386
rbac_enabled : false
379
387
} ) . as ( 'getPortalContext' )
380
388
381
- cy . intercept ( 'get' , 'api/v2/portals /*/developers/me/permissions ' , cy . spy ( ) . as ( 'apiNotCalled' ) )
389
+ cy . intercept ( 'get' , '/ api/v2/products /*/actions ' , cy . spy ( ) . as ( 'apiNotCalled' ) )
382
390
383
391
cy . visit ( `/spec/${ product . id } ` )
384
392
385
393
cy . get ( '[data-testid="kong-public-ui-spec-details-swagger"]' , { timeout : 12000 } )
386
- . get ( '.info h2' ) . should ( 'contain' , 'Swagger Petstore' )
394
+ . get ( '.info h2' ) . should ( 'contain' , 'Swagger Petstore' )
387
395
388
396
cy . get ( '[data-testid="register-button"]' ) . should ( 'exist' )
389
397
@@ -405,12 +413,12 @@ describe('Spec Renderer Page', () => {
405
413
cy . mockAppearance ( )
406
414
} )
407
415
408
- it ( 'allows seeing spec when portal is public and rbac enabled, does not call developers/me/permissions ' , ( ) => {
416
+ it ( 'allows seeing spec when portal is public and rbac enabled, does not retrieve product actions ' , ( ) => {
409
417
cy . intercept ( 'GET' , '**/portal_api/portal/portal_context' , {
410
418
rbac_enabled : true
411
419
} ) . as ( 'getPortalContext' )
412
420
413
- cy . intercept ( 'get' , 'api/v2/portals /*/developers/me/permissions ' , cy . spy ( ) . as ( 'apiNotCalled' ) )
421
+ cy . intercept ( 'get' , '/ api/v2/products /*/actions ' , cy . spy ( ) . as ( 'apiNotCalled' ) )
414
422
415
423
cy . visit ( `/spec/${ product . id } ` )
416
424
0 commit comments