1
+ import { linodeFactory , regionFactory } from '@linode/utilities' ;
2
+ import { grantsFactory , profileFactory } from '@linode/utilities' ;
3
+ import { subnetFactory , vpcFactory } from '@src/factories' ;
4
+ import { mockGetUser } from 'support/intercepts/account' ;
1
5
/**
2
6
* @file Integration tests for VPC create flow.
3
7
*/
4
-
5
- import { linodeFactory , regionFactory } from '@linode/utilities' ;
6
- import { subnetFactory , vpcFactory } from '@src/factories' ;
8
+ import {
9
+ mockGetProfile ,
10
+ mockGetProfileGrants ,
11
+ } from 'support/intercepts/profile' ;
7
12
import { mockGetRegions } from 'support/intercepts/regions' ;
8
13
import {
9
14
mockCreateVPC ,
@@ -21,6 +26,7 @@ import {
21
26
} from 'support/util/random' ;
22
27
import { extendRegion } from 'support/util/regions' ;
23
28
29
+ import { accountUserFactory } from 'src/factories' ;
24
30
import { getUniqueResourcesFromSubnets } from 'src/features/VPCs/utils' ;
25
31
26
32
import type { Subnet , VPC } from '@linode/api-v4' ;
@@ -332,3 +338,59 @@ describe('VPC create flow', () => {
332
338
cy . findByText ( 'No Subnets are assigned.' ) . should ( 'be.visible' ) ;
333
339
} ) ;
334
340
} ) ;
341
+
342
+ describe ( 'restricted user cannot create vpc' , ( ) => {
343
+ beforeEach ( ( ) => {
344
+ const mockProfile = profileFactory . build ( {
345
+ restricted : true ,
346
+ username : randomLabel ( ) ,
347
+ } ) ;
348
+
349
+ const mockUser = accountUserFactory . build ( {
350
+ restricted : true ,
351
+ user_type : 'default' ,
352
+ username : mockProfile . username ,
353
+ } ) ;
354
+
355
+ const mockGrants = grantsFactory . build ( {
356
+ global : {
357
+ add_vpcs : false ,
358
+ } ,
359
+ } ) ;
360
+
361
+ mockGetProfile ( mockProfile ) ;
362
+ mockGetProfileGrants ( mockGrants ) ;
363
+ mockGetUser ( mockUser ) ;
364
+ } ) ;
365
+
366
+ /*
367
+ * - Verifies that restricted user cannot create vpc on landing page
368
+ */
369
+ it ( 'create vpc is disabled on landing page' , ( ) => {
370
+ cy . visitWithLogin ( '/vpcs' ) ;
371
+ ui . button
372
+ . findByTitle ( 'Create VPC' )
373
+ . should ( 'be.visible' )
374
+ . should ( 'be.disabled' ) ;
375
+ } ) ;
376
+
377
+ /*
378
+ * - Verifies that restricted user cannot create vpc in Create page
379
+ */
380
+ it ( 'create vpc create page is disabled' , ( ) => {
381
+ cy . visitWithLogin ( '/vpcs/create' ) ;
382
+ cy . findByText (
383
+ "You don't have permissions to create a new VPC. Please contact an account administrator for details."
384
+ ) ;
385
+ cy . get ( '[data-testid="formVpcCreate"]' ) . within ( ( ) => {
386
+ ui . buttonGroup
387
+ . findButtonByTitle ( 'Create VPC' )
388
+ . should ( 'be.visible' )
389
+ . should ( 'be.disabled' ) ;
390
+ // all form inputs are disabled
391
+ cy . get ( 'input' ) . each ( ( input ) => {
392
+ cy . wrap ( input ) . should ( 'be.disabled' ) ;
393
+ } ) ;
394
+ } ) ;
395
+ } ) ;
396
+ } ) ;
0 commit comments