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 { getUniqueLinodesFromSubnets } from 'src/features/VPCs/utils' ;
25
31
26
32
import type { Subnet , VPC } from '@linode/api-v4' ;
@@ -328,3 +334,59 @@ describe('VPC create flow', () => {
328
334
cy . findByText ( 'No Subnets are assigned.' ) . should ( 'be.visible' ) ;
329
335
} ) ;
330
336
} ) ;
337
+
338
+ describe ( 'restricted user cannot create vpc' , ( ) => {
339
+ beforeEach ( ( ) => {
340
+ const mockProfile = profileFactory . build ( {
341
+ restricted : true ,
342
+ username : randomLabel ( ) ,
343
+ } ) ;
344
+
345
+ const mockUser = accountUserFactory . build ( {
346
+ restricted : true ,
347
+ user_type : 'default' ,
348
+ username : mockProfile . username ,
349
+ } ) ;
350
+
351
+ const mockGrants = grantsFactory . build ( {
352
+ global : {
353
+ add_vpcs : false ,
354
+ } ,
355
+ } ) ;
356
+
357
+ mockGetProfile ( mockProfile ) ;
358
+ mockGetProfileGrants ( mockGrants ) ;
359
+ mockGetUser ( mockUser ) ;
360
+ } ) ;
361
+
362
+ /*
363
+ * - Verifies that restricted user cannot create vpc on landing page
364
+ */
365
+ it ( 'create vpc is disabled on landing page' , ( ) => {
366
+ cy . visitWithLogin ( '/vpcs' ) ;
367
+ ui . button
368
+ . findByTitle ( 'Create VPC' )
369
+ . should ( 'be.visible' )
370
+ . should ( 'be.disabled' ) ;
371
+ } ) ;
372
+
373
+ /*
374
+ * - Verifies that restricted user cannot create vpc in Create page
375
+ */
376
+ it ( 'create vpc create page is disabled' , ( ) => {
377
+ cy . visitWithLogin ( '/vpcs/create' ) ;
378
+ cy . findByText (
379
+ "You don't have permissions to create a new VPC. Please contact an account administrator for details."
380
+ ) ;
381
+ cy . get ( '[data-testid="formVpcCreate"]' ) . within ( ( ) => {
382
+ ui . buttonGroup
383
+ . findButtonByTitle ( 'Create VPC' )
384
+ . should ( 'be.visible' )
385
+ . should ( 'be.disabled' ) ;
386
+ // all form inputs are disabled
387
+ cy . get ( 'input' ) . each ( ( input ) => {
388
+ cy . wrap ( input ) . should ( 'be.disabled' ) ;
389
+ } ) ;
390
+ } ) ;
391
+ } ) ;
392
+ } ) ;
0 commit comments