Skip to content
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

test: [M3-7139] - Enable TypeScript typechecking in Cypress directory #10086

Merged
merged 30 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3eb113f
Use ESM-friendly method to get directory name in Vite configs
Jan 19, 2024
27c1162
Extend Cypress tsconfig from Cloud Manager tsconfig
Jan 19, 2024
51c6671
Fix Cypress tsc issues caused by `api-v4/types` imports
Jan 19, 2024
b2c2f6e
Fix tsc issue related to Service Transfer status types
Jan 19, 2024
344ffaa
Fix billing tests mismatched types and missing param types
Jan 19, 2024
ad8e688
Fix mismatched types in Cypress plugins dir
Jan 19, 2024
67d3d9f
Fix missing param annotations
Jan 19, 2024
bf74e67
Fix DBaaS test type issues
Jan 19, 2024
42cc2d9
Fix Domains test type issues
Jan 19, 2024
7fcb369
Fix domain ID mismatched type
Jan 19, 2024
79df5d5
Fix type errors in defer command
Jan 19, 2024
9da5039
Fix missing import, remove commented line
Jan 19, 2024
d70bee4
Fix Firewall update type errors
Jan 19, 2024
5a5714a
Fix type errors
Jan 19, 2024
2f15e9e
Fix `mockGetClusters` param annotation
Jan 19, 2024
def56a7
Various fixes
Jan 19, 2024
d217f0c
Add types for chai-string
Jan 19, 2024
95f7c31
WIP
Jan 22, 2024
04579ea
Fix TypeScript error stemming from misunderstanding of grants API for…
Jan 22, 2024
fb20b23
Fix OBJ enable test TS errors by casting mock cluster IDs
Jan 22, 2024
4f1a3af
Replace `Linode` type with `CreateLinodeRequest` to fix TS error
Jan 22, 2024
6d253f3
Use `InterfacePayload` type in Linode create request type so that `id…
Jan 22, 2024
4b70f02
Update yarn.lock
Jan 22, 2024
5701dc4
Typecheck Cypress during Git precommit hook
Jan 22, 2024
c669e8b
Merge branch 'develop' into exp-cypress-typecheck
Jan 22, 2024
265f4da
Add changesets
Jan 22, 2024
8761081
Fix domain record test by using domain creation payload factory
Jan 22, 2024
a91272e
Improve leftover types
abailly-akamai Jan 23, 2024
89fc6a7
Add TODO note for commented function
Jan 24, 2024
b4560de
Merge branch 'develop' into exp-cypress-typecheck
Jan 25, 2024
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/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[];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to draw attention to this change in case it's incorrect. Without this change, I encountered type errors in the config test because TypeScript expected id and active properties to be specified when creating a Linode with Interfaces via the API SDK's createLinode function.

Copy link
Contributor

@hkhalil-akamai hkhalil-akamai Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linode API docs show active in the request payload (after VPC beta), but I have a feeling that it's supposed to be a read-only property? Anyways I think InterfacePayload is correct and id definitely shouldn't be in there.

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 {
mockCreatePersonalAccessToken,
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
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 @@ -190,14 +191,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 @@ -257,7 +255,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 @@ -650,15 +648,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 @@ -791,12 +783,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 @@ -805,7 +791,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
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