Skip to content

Commit ff3951c

Browse files
test: [M3-9596] - VPC tests for restricted user (#12238)
* vpc tests for restricted user * Added changeset: Vpc tests for restricted user * change testid name
1 parent 47f6425 commit ff3951c

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Tests
3+
---
4+
5+
Vpc tests for restricted user ([#12238](https://github.com/linode/manager/pull/12238))

packages/manager/cypress/e2e/core/vpc/vpc-create.spec.ts

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
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';
15
/**
26
* @file Integration tests for VPC create flow.
37
*/
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';
712
import { mockGetRegions } from 'support/intercepts/regions';
813
import {
914
mockCreateVPC,
@@ -21,6 +26,7 @@ import {
2126
} from 'support/util/random';
2227
import { extendRegion } from 'support/util/regions';
2328

29+
import { accountUserFactory } from 'src/factories';
2430
import { getUniqueLinodesFromSubnets } from 'src/features/VPCs/utils';
2531

2632
import type { Subnet, VPC } from '@linode/api-v4';
@@ -328,3 +334,59 @@ describe('VPC create flow', () => {
328334
cy.findByText('No Subnets are assigned.').should('be.visible');
329335
});
330336
});
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+
});

packages/manager/src/features/VPCs/VPCCreate/VPCCreate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const VPCCreate = () => {
4747
/>
4848
{userCannotAddVPC && CannotCreateVPCNotice}
4949
<Grid>
50-
<form onSubmit={handleSubmit(onCreateVPC)}>
50+
<form data-testid="formVpcCreate" onSubmit={handleSubmit(onCreateVPC)}>
5151
{errors.root?.message && (
5252
<Notice text={errors.root.message} variant="error" />
5353
)}

0 commit comments

Comments
 (0)