Skip to content

test: [M3-9596] - VPC tests for restricted user #12238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-12238-tests-1747405842720.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Vpc tests for restricted user ([#12238](https://github.com/linode/manager/pull/12238))
68 changes: 65 additions & 3 deletions packages/manager/cypress/e2e/core/vpc/vpc-create.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { linodeFactory, regionFactory } from '@linode/utilities';
import { grantsFactory, profileFactory } from '@linode/utilities';
import { subnetFactory, vpcFactory } from '@src/factories';
import { mockGetUser } from 'support/intercepts/account';
/**
* @file Integration tests for VPC create flow.
*/

import { linodeFactory, regionFactory } from '@linode/utilities';
import { subnetFactory, vpcFactory } from '@src/factories';
import {
mockGetProfile,
mockGetProfileGrants,
} from 'support/intercepts/profile';
import { mockGetRegions } from 'support/intercepts/regions';
import {
mockCreateVPC,
Expand All @@ -21,6 +26,7 @@
} from 'support/util/random';
import { extendRegion } from 'support/util/regions';

import { accountUserFactory } from 'src/factories';
import { getUniqueLinodesFromSubnets } from 'src/features/VPCs/utils';

import type { Subnet, VPC } from '@linode/api-v4';
Expand Down Expand Up @@ -328,3 +334,59 @@
cy.findByText('No Subnets are assigned.').should('be.visible');
});
});

describe('restricted user cannot create vpc', () => {
beforeEach(() => {
const mockProfile = profileFactory.build({
restricted: true,
username: randomLabel(),
});

const mockUser = accountUserFactory.build({
restricted: true,
user_type: 'default',
username: mockProfile.username,
});

const mockGrants = grantsFactory.build({
global: {
add_vpcs: false,
},
});

mockGetProfile(mockProfile);
mockGetProfileGrants(mockGrants);
mockGetUser(mockUser);
});

/*
* - Verifies that restricted user cannot create vpc on landing page
*/
it('create vpc is disabled on landing page', () => {
cy.visitWithLogin('/vpcs');
ui.button
.findByTitle('Create VPC')
.should('be.visible')
.should('be.disabled');

Check warning on line 370 in packages/manager/cypress/e2e/core/vpc/vpc-create.spec.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Define a constant instead of duplicating this literal 3 times. Raw Output: {"ruleId":"sonarjs/no-duplicate-string","severity":1,"message":"Define a constant instead of duplicating this literal 3 times.","line":370,"column":15,"nodeType":"Literal","endLine":370,"endColumn":28}
});

/*
* - Verifies that restricted user cannot create vpc in Create page
*/
it('create vpc create page is disabled', () => {
cy.visitWithLogin('/vpcs/create');
cy.findByText(
"You don't have permissions to create a new VPC. Please contact an account administrator for details."
);
cy.get('[data-testid="formVpcCreate"]').within(() => {
ui.buttonGroup
.findButtonByTitle('Create VPC')
.should('be.visible')
.should('be.disabled');
// all form inputs are disabled
cy.get('input').each((input) => {
cy.wrap(input).should('be.disabled');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const VPCCreate = () => {
/>
{userCannotAddVPC && CannotCreateVPCNotice}
<Grid>
<form onSubmit={handleSubmit(onCreateVPC)}>
<form data-testid="formVpcCreate" onSubmit={handleSubmit(onCreateVPC)}>
{errors.root?.message && (
<Notice text={errors.root.message} variant="error" />
)}
Expand Down