Skip to content

Commit ac0ede2

Browse files
dmcintyr-akamaihasyed-akamai
authored andcommitted
test: [M3-9596] - VPC tests for restricted user (linode#12238)
* vpc tests for restricted user * Added changeset: Vpc tests for restricted user * change testid name
1 parent 3d1f604 commit ac0ede2

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 { getUniqueResourcesFromSubnets } from 'src/features/VPCs/utils';
2531

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

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)