Skip to content

Commit

Permalink
test: [M3-7139] - Enable TypeScript typechecking in Cypress directory (
Browse files Browse the repository at this point in the history
…#10086)

* Use ESM-friendly method to get directory name in Vite configs

* Extend Cypress tsconfig from Cloud Manager tsconfig

* Fix Cypress test directory tsc issues

* Add types for chai-string

* Typecheck Cypress during Git precommit hook

---------

Co-authored-by: Alban Bailly <abailly@akamai.com>
  • Loading branch information
jdamore-linode and abailly-akamai authored Jan 26, 2024
1 parent dfdab4b commit a8e51e7
Show file tree
Hide file tree
Showing 102 changed files with 418 additions and 359 deletions.
5 changes: 5 additions & 0 deletions packages/api-v4/.changeset/pr-10086-fixed-1705951593932.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Fixed
---

Accept `InterfacePayload` type when creating a Linode with interfaces specified ([#10086](https://github.com/linode/manager/pull/10086))
2 changes: 1 addition & 1 deletion packages/api-v4/src/linodes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export interface CreateLinodeRequest {
tags?: string[];
private_ip?: boolean;
authorized_users?: string[];
interfaces?: Interface[];
interfaces?: InterfacePayload[];
metadata?: UserData;
firewall_id?: number;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10086-tests-1705951537130.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Enable TypeScript type checks in the Cypress directory ([#10086](https://github.com/linode/manager/pull/10086))
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'support/intercepts/profile';
import { ui } from 'support/ui';
import { randomLabel, randomHex } from 'support/util/random';
import { OAuthClient } from '@linode/api-v4/types';
import type { OAuthClient } from '@linode/api-v4';

/**
* Creates an OAuth App with the given parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Integration tests for personal access token CRUD operations.
*/

import { Token } from '@linode/api-v4/types';
import { Token } from '@linode/api-v4';
import { appTokenFactory } from 'src/factories/oauth';
import { profileFactory } from 'src/factories/profile';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { createLinode } from '@linode/api-v4/lib/linodes';
import { getProfile } from '@linode/api-v4/lib/profile';
import { EntityTransfer, Linode, Profile } from '@linode/api-v4/types';
import { EntityTransfer, Linode, Profile } from '@linode/api-v4';
import { entityTransferFactory } from 'src/factories/entityTransfers';
import { linodeFactory } from 'src/factories';
import { createLinodeRequestFactory } from 'src/factories/linodes';
Expand All @@ -25,16 +25,18 @@ import { visitUrlWithManagedEnabled } from 'support/api/managed';
import { chooseRegion } from 'support/util/regions';
import { cleanUp } from 'support/util/cleanup';

import type { EntityTransferStatus } from '@linode/api-v4';

// Service transfer landing page URL.
const serviceTransferLandingUrl = '/account/service-transfers';

// Service transfer initiation page URL.
const serviceTransferCreateUrl = '/account/service-transfers/create';

// Possible status responses for service transfers.
const serviceTransferStatuses = [
const serviceTransferStatuses: EntityTransferStatus[] = [
'pending',
'complete',
'completed',
'failed',
'accepted',
'stale',
Expand Down Expand Up @@ -151,7 +153,7 @@ describe('Account service transfers', () => {
},
});

const sentTransfers = serviceTransferStatuses.map((status: string) => {
const sentTransfers = serviceTransferStatuses.map((status) => {
return entityTransferFactory.build({
is_sender: true,
entities: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'support/intercepts/profile';
import { ui } from 'support/ui';
import { randomLabel, randomString } from 'support/util/random';
import { Token, Profile } from '@linode/api-v4/types';
import { Token, Profile } from '@linode/api-v4';
import { getProfile } from '@linode/api-v4/lib/profile';
import { formatDate } from 'src/utilities/formatDate';
import { authenticate } from 'support/api/authentication';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Integration tests for account two-factor authentication functionality.
*/

import { SecurityQuestionsData } from '@linode/api-v4/types';
import { SecurityQuestionsData } from '@linode/api-v4';
import {
profileFactory,
securityQuestionsFactory,
Expand Down
36 changes: 8 additions & 28 deletions packages/manager/cypress/e2e/core/account/user-permissions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
mockAddUser,
mockGetUser,
mockGetUserGrants,
mockGetUserGrantsUnrestrictedAccess,
mockGetUsers,
mockUpdateUser,
mockUpdateUserGrants,
Expand Down Expand Up @@ -191,14 +192,11 @@ describe('User permission management', () => {
};

const mockUserGrantsUpdated = grantsFactory.build();
const mockUserGrants = {
...mockUserGrantsUpdated,
global: undefined,
};

// Initially mock user with unrestricted account access.
mockGetUsers([mockUser]).as('getUsers');
mockGetUser(mockUser).as('getUser');
mockGetUserGrants(mockUser.username, mockUserGrants).as('getUserGrants');
mockGetUserGrantsUnrestrictedAccess(mockUser.username).as('getUserGrants');

// Navigate to Users & Grants page, find mock user, click its "User Permissions" button.
cy.visitWithLogin('/account/users');
Expand Down Expand Up @@ -258,7 +256,7 @@ describe('User permission management', () => {

// Re-enable unrestricted account access, confirm page updates to reflect change.
mockUpdateUser(mockUser.username, mockUser);
mockGetUserGrants(mockUser.username, mockUserGrants);
mockGetUserGrantsUnrestrictedAccess(mockUser.username);
cy.findByLabelText('Toggle Full Account Access')
.should('be.visible')
.click();
Expand Down Expand Up @@ -651,15 +649,9 @@ describe('User permission management', () => {
restricted: false,
});

const mockUserGrantsUpdated = grantsFactory.build();
const mockUserGrants = {
...mockUserGrantsUpdated,
global: undefined,
};

mockGetUsers([mockUser]).as('getUsers');
mockGetUser(mockUser);
mockGetUserGrants(mockUser.username, mockUserGrants);
mockGetUserGrantsUnrestrictedAccess(mockUser.username);
mockAddUser(newUser).as('addUser');

// Navigate to Users & Grants page, find mock user, click its "User Permissions" button.
Expand Down Expand Up @@ -792,12 +784,6 @@ describe('User permission management', () => {
restricted: true,
});

const mockUserGrantsUpdated = grantsFactory.build();
const mockUserGrants = {
...mockUserGrantsUpdated,
global: undefined,
};

// TODO: Parent/Child - M3-7559 clean up when feature is live in prod and feature flag is removed.
mockAppendFeatureFlags({
parentChildAccountAccess: makeFeatureFlagData(false),
Expand All @@ -806,7 +792,7 @@ describe('User permission management', () => {

mockGetUsers([mockUser]).as('getUsers');
mockGetUser(mockUser);
mockGetUserGrants(mockUser.username, mockUserGrants);
mockGetUserGrantsUnrestrictedAccess(mockUser.username);
mockAddUser(newUser).as('addUser');

// Navigate to Users & Grants page, find mock user, click its "User Permissions" button.
Expand Down Expand Up @@ -919,12 +905,6 @@ describe('User permission management', () => {
restricted: false,
});

const mockUserGrantsUpdated = grantsFactory.build();
const mockUserGrants = {
...mockUserGrantsUpdated,
global: undefined,
};

// TODO: Parent/Child - M3-7559 clean up when feature is live in prod and feature flag is removed.
mockAppendFeatureFlags({
parentChildAccountAccess: makeFeatureFlagData(false),
Expand All @@ -933,8 +913,8 @@ describe('User permission management', () => {

mockGetUsers([mockUser, additionalUser]).as('getUsers');
mockGetUser(mockUser);
mockGetUserGrants(mockUser.username, mockUserGrants);
mockGetUserGrants(additionalUser.username, mockUserGrants);
mockGetUserGrantsUnrestrictedAccess(mockUser.username);
mockGetUserGrantsUnrestrictedAccess(additionalUser.username);
mockDeleteUser(additionalUser.username).as('deleteUser');

// Navigate to Users & Grants page, find mock user, click its "User Permissions" button.
Expand Down
21 changes: 11 additions & 10 deletions packages/manager/cypress/e2e/core/billing/billing-contact.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mockGetAccount, mockUpdateAccount } from 'support/intercepts/account';
import { accountFactory } from 'src/factories/account';
import type { Account } from '@linode/api-v4';

/* eslint-disable sonarjs/no-duplicate-string */
const accountData = accountFactory.build({
Expand Down Expand Up @@ -44,20 +45,20 @@ const newAccountData = accountFactory.build({
zip: '19108',
});

const checkAccountContactDisplay = (data) => {
const checkAccountContactDisplay = (accountInfo: Account) => {
cy.findByText('Billing Contact').should('be.visible');
cy.findByText(data['company']).should('be.visible');
cy.findByText(accountInfo['company']).should('be.visible');
cy.get('[data-qa-contact-name]').should('be.visible');
cy.findByText(data['first_name'], { exact: false });
cy.findByText(data['last_name'], { exact: false });
cy.contains(data['address_1']);
cy.contains(data['address_2']);
cy.findByText(data['state'], { exact: false });
cy.findByText(data['zip'], { exact: false });
cy.findByText(accountInfo['first_name'], { exact: false });
cy.findByText(accountInfo['last_name'], { exact: false });
cy.contains(accountInfo['address_1']);
cy.contains(accountInfo['address_2']);
cy.findByText(accountInfo['state'], { exact: false });
cy.findByText(accountInfo['zip'], { exact: false });
cy.get('[data-qa-contact-email="true"]').within(() => {
cy.findByText(data['email']);
cy.findByText(accountInfo['email']);
});
cy.findByText(data['phone']);
cy.findByText(accountInfo['phone']);
};

describe('Billing Contact', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Account invoices', () => {
to: DateTime.now().minus({ days: i }).plus({ hours }).toISO(),
quantity,
region: chooseRegion().id,
unit_price: randomNumber(5, 300) / 10000,
unit_price: `${randomNumber(5, 300) / 10000}`,
label: `${itemType} ${randomNumber(
1,
24
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CreditCardData } from '@linode/api-v4/types';
import type { CreditCardData } from '@linode/api-v4';
import { paymentMethodFactory } from '@src/factories/accountPayment';
import {
mockSetDefaultPaymentMethod,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mockGetPaymentMethods } from 'support/intercepts/account';
import { PaymentMethod, CreditCardData } from '@linode/api-v4/types';
import { PaymentMethod, CreditCardData } from '@linode/api-v4';
import { ui } from 'support/ui';

const mockPaymentMethods: PaymentMethod[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import {
import { mockGetEvents } from 'support/intercepts/events';
import { getRegionById } from 'support/util/regions';
import { ui } from 'support/ui';
import type { Database } from '@linode/api-v4';

describe('create a database cluster, mocked data', () => {
databaseConfigurations.forEach(
(configuration: databaseClusterConfiguration) => {
// @TODO Add assertions for DBaaS pricing.
it(`creates a ${configuration.linodeType} ${configuration.engine} v${configuration.version}.x ${configuration.clusterSize}-node cluster`, () => {
// Database mock immediately after instance has been created.
const databaseMock = databaseFactory.build({
const databaseMock: Database = databaseFactory.build({
label: configuration.label,
type: configuration.linodeType,
region: configuration.region.id,
Expand All @@ -31,13 +32,13 @@ describe('create a database cluster, mocked data', () => {
cluster_size: configuration.clusterSize,
engine: configuration.dbType,
hosts: {
primary: null,
secondary: null,
primary: undefined,
secondary: undefined,
},
});

// Database mock once instance has been provisioned.
const databaseMockActive = {
const databaseMockActive: Database = {
...databaseMock,
status: 'active',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
randomIp,
randomString,
} from 'support/util/random';
import { databaseFactory, databaseTypeFactory } from 'src/factories/databases';
import { databaseFactory } from 'src/factories/databases';
import { ui } from 'support/ui';
import { mockGetAccount } from 'support/intercepts/account';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Domain } from '@linode/api-v4/types';
import { Domain } from '@linode/api-v4';
import { domainFactory } from '@src/factories';
import { authenticate } from 'support/api/authentication';
import { fbtClick, getClick, getVisible } from 'support/helpers';
Expand All @@ -18,9 +18,9 @@ describe('Create a Domain', () => {
it('Creates first Domain', () => {
// Mock Domains to modify incoming response.
const mockDomains = new Array(2).fill(null).map(
(item: null, index: number): Domain => {
(_item: null, index: number): Domain => {
return domainFactory.build({
label: `Domain ${index}`,
domain: `Domain ${index}`,
});
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Domain } from '@linode/api-v4/types';
import { Domain } from '@linode/api-v4';
import { domainFactory } from '@src/factories';
import { containsClick } from 'support/helpers';
import { authenticate } from 'support/api/authentication';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ describe('Download a Zone file', () => {
.should('be.enabled')
.click();

mockGetDomains(mockDomain).as('getDomains');
mockGetDomains([mockDomain]).as('getDomains');
cy.visitWithLogin('/domains');
cy.wait('@getDomains');

mockGetDomain(mockDomain.id, mockDomain).as('getDomain');
mockGetDomainRecords(mockDomainRecords).as('getDomainRecords');
mockGetDomainRecords([mockDomainRecords]).as('getDomainRecords');
fbtVisible(mockDomain.domain);
fbtClick(mockDomain.domain);
cy.wait('@getDomain');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ImportZonePayload } from '@linode/api-v4/types';
import { ImportZonePayload } from '@linode/api-v4';
import { domainFactory } from '@src/factories';
import { authenticate } from 'support/api/authentication';
import { fbltClick } from 'support/helpers';
Expand All @@ -25,7 +25,7 @@ describe('Import a Zone', () => {
group: 'test-group',
});

mockGetDomains(mockDomain).as('getDomains');
mockGetDomains([mockDomain]).as('getDomains');
cy.visitWithLogin('/domains');
cy.wait('@getDomains');

Expand Down Expand Up @@ -86,7 +86,7 @@ describe('Import a Zone', () => {

// Fill out and import the zone.
mockImportDomain(mockDomain).as('importDomain');
mockGetDomains(mockDomain).as('getDomains');
mockGetDomains([mockDomain]).as('getDomains');
fbltClick('Domain').clear().type(zone.domain);
fbltClick('Remote Nameserver').clear().type(zone.remote_nameserver);
ui.buttonGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { authenticate } from 'support/api/authentication';
import { randomLabel } from 'support/util/random';
import { ui } from 'support/ui';
import { fbtVisible, fbtClick } from 'support/helpers';
import { chooseRegion } from 'support/util/regions';
import { cleanUp } from 'support/util/cleanup';

authenticate();
Expand All @@ -22,7 +21,6 @@ describe('delete firewall', () => {
it('deletes a firewall', () => {
const firewallRequest = firewallFactory.build({
label: randomLabel(),
region: chooseRegion().id,
});

cy.defer(createFirewall(firewallRequest), 'creating firewalls').then(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ describe('Migrate Linode With Firewall', () => {
id: randomNumber(),
label: randomLabel(),
status: 'enabled',
devices: {
linodes: [mockLinode.id],
},
});

mockGetFirewalls([mockFirewall]).as('getFirewalls');
Expand Down
Loading

0 comments on commit a8e51e7

Please sign in to comment.