Skip to content

Commit

Permalink
refactor: [M3-8291] - Enforce Factory.each to start increment at 1 (#…
Browse files Browse the repository at this point in the history
…10619)

* Initial commit - save work

* save progress

* save progress

* last one

* comment and cleanup

* cleanup

* Added changeset: Enforce Factory.each to start increment at 1

* exclude cypress for now

* comment

* Going the proxy route in order to satisfy cypress

* feedback @dwiley-akamai @mjac0bs

* Remove hard-coded plan type labels in test assertions

* feedback @bnussman-akamai

* small cleanup

---------

Co-authored-by: Joe D'Amore <jdamore@linode.com>
  • Loading branch information
abailly-akamai and Joe D'Amore authored Jun 29, 2024
1 parent 482fa5b commit e64101c
Show file tree
Hide file tree
Showing 83 changed files with 302 additions and 196 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

Make `Factory.each` start incrementing at 1 instead of 0 ([#10619](https://github.com/linode/manager/pull/10619))
45 changes: 28 additions & 17 deletions packages/manager/cypress/e2e/core/kubernetes/lke-update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
kubeLinodeFactory,
linodeFactory,
} from 'src/factories';
import { extendType } from 'src/utilities/extendType';
import { latestKubernetesVersion } from 'support/constants/lke';
import {
mockGetCluster,
Expand Down Expand Up @@ -785,6 +786,7 @@ describe('LKE cluster updates for DC-specific prices', () => {
*/
it('can resize pools with DC-specific prices', () => {
const dcSpecificPricingRegion = getRegionById('us-east');
const mockPlanType = extendType(dcPricingMockLinodeTypes[0]);

const mockCluster = kubernetesClusterFactory.build({
k8s_version: latestKubernetesVersion,
Expand All @@ -796,7 +798,7 @@ describe('LKE cluster updates for DC-specific prices', () => {

const mockNodePoolResized = nodePoolFactory.build({
count: 3,
type: dcPricingMockLinodeTypes[0].id,
type: mockPlanType.id,
nodes: kubeLinodeFactory.buildList(3),
});

Expand All @@ -812,19 +814,19 @@ describe('LKE cluster updates for DC-specific prices', () => {
id: node.instance_id ?? undefined,
ipv4: [randomIp()],
region: dcSpecificPricingRegion.id,
type: dcPricingMockLinodeTypes[0].id,
type: mockPlanType.id,
});
}
);

const mockNodePoolDrawerTitle = 'Resize Pool: Linode 0 GB Plan';
const mockNodePoolDrawerTitle = `Resize Pool: ${mockPlanType.formattedLabel} Plan`;

mockGetCluster(mockCluster).as('getCluster');
mockGetClusterPools(mockCluster.id, [mockNodePoolInitial]).as(
'getNodePools'
);
mockGetLinodes(mockLinodes).as('getLinodes');
mockGetLinodeType(dcPricingMockLinodeTypes[0]).as('getLinodeType');
mockGetLinodeType(mockPlanType).as('getLinodeType');
mockGetKubernetesVersions().as('getVersions');
mockGetDashboardUrl(mockCluster.id);
mockGetApiEndpoints(mockCluster.id);
Expand Down Expand Up @@ -938,23 +940,25 @@ describe('LKE cluster updates for DC-specific prices', () => {
},
});

const mockPlanType = extendType(dcPricingMockLinodeTypes[0]);

const mockNewNodePool = nodePoolFactory.build({
count: 2,
type: dcPricingMockLinodeTypes[0].id,
type: mockPlanType.id,
nodes: kubeLinodeFactory.buildList(2),
});

const mockNodePool = nodePoolFactory.build({
count: 1,
type: dcPricingMockLinodeTypes[0].id,
type: mockPlanType.id,
nodes: kubeLinodeFactory.buildList(1),
});

mockGetCluster(mockCluster).as('getCluster');
mockGetClusterPools(mockCluster.id, [mockNodePool]).as('getNodePools');
mockGetKubernetesVersions().as('getVersions');
mockAddNodePool(mockCluster.id, mockNewNodePool).as('addNodePool');
mockGetLinodeType(dcPricingMockLinodeTypes[0]).as('getLinodeType');
mockGetLinodeType(mockPlanType).as('getLinodeType');
mockGetLinodeTypes(dcPricingMockLinodeTypes);
mockGetDashboardUrl(mockCluster.id);
mockGetApiEndpoints(mockCluster.id);
Expand All @@ -963,7 +967,9 @@ describe('LKE cluster updates for DC-specific prices', () => {
cy.wait(['@getCluster', '@getNodePools', '@getVersions', '@getLinodeType']);

// Assert that initial node pool is shown on the page.
cy.findByText('Linode 0 GB', { selector: 'h2' }).should('be.visible');
cy.findByText(mockPlanType.formattedLabel, { selector: 'h2' }).should(
'be.visible'
);

// Confirm total price is listed in Kube Specs.
cy.findByText('$14.40/month').should('be.visible');
Expand All @@ -987,7 +993,7 @@ describe('LKE cluster updates for DC-specific prices', () => {
.should('be.visible')
.should('be.enabled')
.click();
cy.findByText('Linode 0 GB')
cy.findByText(mockPlanType.formattedLabel)
.should('be.visible')
.closest('tr')
.within(() => {
Expand Down Expand Up @@ -1024,6 +1030,7 @@ describe('LKE cluster updates for DC-specific prices', () => {
*/
it('can resize pools with region prices of $0', () => {
const dcSpecificPricingRegion = getRegionById('us-southeast');
const mockPlanType = extendType(dcPricingMockLinodeTypes[2]);

const mockCluster = kubernetesClusterFactory.build({
k8s_version: latestKubernetesVersion,
Expand All @@ -1035,7 +1042,7 @@ describe('LKE cluster updates for DC-specific prices', () => {

const mockNodePoolResized = nodePoolFactory.build({
count: 3,
type: dcPricingMockLinodeTypes[2].id,
type: mockPlanType.id,
nodes: kubeLinodeFactory.buildList(3),
});

Expand All @@ -1051,19 +1058,19 @@ describe('LKE cluster updates for DC-specific prices', () => {
id: node.instance_id ?? undefined,
ipv4: [randomIp()],
region: dcSpecificPricingRegion.id,
type: dcPricingMockLinodeTypes[2].id,
type: mockPlanType.id,
});
}
);

const mockNodePoolDrawerTitle = 'Resize Pool: Linode 2 GB Plan';
const mockNodePoolDrawerTitle = `Resize Pool: ${mockPlanType.formattedLabel} Plan`;

mockGetCluster(mockCluster).as('getCluster');
mockGetClusterPools(mockCluster.id, [mockNodePoolInitial]).as(
'getNodePools'
);
mockGetLinodes(mockLinodes).as('getLinodes');
mockGetLinodeType(dcPricingMockLinodeTypes[2]).as('getLinodeType');
mockGetLinodeType(mockPlanType).as('getLinodeType');
mockGetKubernetesVersions().as('getVersions');
mockGetDashboardUrl(mockCluster.id);
mockGetApiEndpoints(mockCluster.id);
Expand Down Expand Up @@ -1160,6 +1167,8 @@ describe('LKE cluster updates for DC-specific prices', () => {
it('can add node pools with region prices of $0', () => {
const dcSpecificPricingRegion = getRegionById('us-southeast');

const mockPlanType = extendType(dcPricingMockLinodeTypes[2]);

const mockCluster = kubernetesClusterFactory.build({
k8s_version: latestKubernetesVersion,
region: dcSpecificPricingRegion.id,
Expand All @@ -1170,21 +1179,21 @@ describe('LKE cluster updates for DC-specific prices', () => {

const mockNewNodePool = nodePoolFactory.build({
count: 2,
type: dcPricingMockLinodeTypes[2].id,
type: mockPlanType.id,
nodes: kubeLinodeFactory.buildList(2),
});

const mockNodePool = nodePoolFactory.build({
count: 1,
type: dcPricingMockLinodeTypes[2].id,
type: mockPlanType.id,
nodes: kubeLinodeFactory.buildList(1),
});

mockGetCluster(mockCluster).as('getCluster');
mockGetClusterPools(mockCluster.id, [mockNodePool]).as('getNodePools');
mockGetKubernetesVersions().as('getVersions');
mockAddNodePool(mockCluster.id, mockNewNodePool).as('addNodePool');
mockGetLinodeType(dcPricingMockLinodeTypes[2]).as('getLinodeType');
mockGetLinodeType(mockPlanType).as('getLinodeType');
mockGetLinodeTypes(dcPricingMockLinodeTypes);
mockGetDashboardUrl(mockCluster.id);
mockGetApiEndpoints(mockCluster.id);
Expand All @@ -1193,7 +1202,9 @@ describe('LKE cluster updates for DC-specific prices', () => {
cy.wait(['@getCluster', '@getNodePools', '@getVersions', '@getLinodeType']);

// Assert that initial node pool is shown on the page.
cy.findByText('Linode 2 GB', { selector: 'h2' }).should('be.visible');
cy.findByText(mockPlanType.formattedLabel, { selector: 'h2' }).should(
'be.visible'
);

// Confirm total price of $0 is listed in Kube Specs.
cy.findByText('$0.00/month').should('be.visible');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Box } from 'src/components/Box';
import { styled } from '@mui/material/styles';
import * as React from 'react';

import Minus from 'src/assets/icons/LKEminusSign.svg';
import Plus from 'src/assets/icons/LKEplusSign.svg';
import { Box } from 'src/components/Box';
import { Button } from 'src/components/Button/Button';
import { TextField } from 'src/components/TextField';

const sxTextFieldBase = {
'&::-webkit-inner-spin-button': {
'-webkit-appearance': 'none',
WebkitAppearance: 'none',
margin: 0,
},
'&::-webkit-outer-spin-button': {
'-webkit-appearance': 'none',
WebkitAppearance: 'none',
margin: 0,
},
'-moz-appearance': 'textfield',
MozAppearance: 'textfield',
padding: '0 8px',
textAlign: 'right',
};
Expand Down
10 changes: 6 additions & 4 deletions packages/manager/src/components/ImageSelect/ImageSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,23 @@ describe('imagesToGroupedItems', () => {
isCloudInitCompatible: false,
isDistributedCompatible: false,
label: 'Slackware 14.1',
value: 'private/4',
value: 'private/5',
},
{
className: 'fl-tux',
created: '2022-10-20T14:05:30',
isCloudInitCompatible: false,
isDistributedCompatible: false,
label: 'Slackware 14.1',
value: 'private/5',
value: 'private/6',
},
],
},
];

expect(imagesToGroupedItems(images)).toStrictEqual(expected);
});

it('should add suffix `deprecated` to images at end of life ', () => {
const images = [
...imageFactory.buildList(2, {
Expand All @@ -76,15 +78,15 @@ describe('imagesToGroupedItems', () => {
isCloudInitCompatible: false,
isDistributedCompatible: false,
label: 'Debian 9 (deprecated)',
value: 'private/6',
value: 'private/7',
},
{
className: 'fl-tux',
created: '2017-06-16T20:02:29',
isCloudInitCompatible: false,
isDistributedCompatible: false,
label: 'Debian 9 (deprecated)',
value: 'private/7',
value: 'private/8',
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { StackScript } from './StackScript';

describe('StackScript', () => {
it('should render the StackScript label, id, and username', () => {
const stackScript = stackScriptFactory.build();
const stackScript = stackScriptFactory.build({ id: 1234 });
renderWithTheme(<StackScript data={stackScript} userCanModify />);

expect(screen.getByText(stackScript.label)).toBeInTheDocument();
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ActivePromotion,
RegionalNetworkUtilization,
} from '@linode/api-v4/lib/account/types';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';

export const promoFactory = Factory.Sync.makeFactory<ActivePromotion>({
credit_monthly_cap: '20.00',
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/accountAgreements.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Agreements } from '@linode/api-v4/lib/account';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';

export const accountAgreementsFactory = Factory.Sync.makeFactory<Agreements>({
eu_model: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/accountAvailability.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccountAvailability } from '@linode/api-v4';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';

import { pickRandom } from 'src/utilities/random';

Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/accountLogin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccountLogin } from '@linode/api-v4';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';

export const accountLoginFactory = Factory.Sync.makeFactory<AccountLogin>({
datetime: '2021-05-21T14:27:51',
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/accountMaintenance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccountMaintenance } from '@linode/api-v4/lib/account/types';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';

import { pickRandom, randomDate } from 'src/utilities/random';

Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/accountOAuth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OAuthClient } from '@linode/api-v4';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';

export const oauthClientFactory = Factory.Sync.makeFactory<OAuthClient>({
id: Factory.each((id) => String(id)),
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/accountPayment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PaymentMethod } from '@linode/api-v4';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';

export const paymentMethodFactory = Factory.Sync.makeFactory<PaymentMethod>({
created: '2021-05-21T14:27:51',
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/accountSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccountSettings } from '@linode/api-v4/lib/account/types';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';

export const accountSettingsFactory = Factory.Sync.makeFactory<AccountSettings>(
{
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/accountUsers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { User } from '@linode/api-v4';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';

export const accountUserFactory = Factory.Sync.makeFactory<User>({
email: 'support@linode.com',
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/aclb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';

import { pickRandom } from 'src/utilities/random';

Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/betas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Beta, AccountBeta } from '@linode/api-v4';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';
import { DateTime } from 'luxon';

export const betaFactory = Factory.Sync.makeFactory<Beta>({
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
PaymentResponse,
} from '@linode/api-v4/lib/account';
import { APIWarning } from '@linode/api-v4/lib/types';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';

export const invoiceItemFactory = Factory.Sync.makeFactory<InvoiceItem>({
amount: 5,
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Config } from '@linode/api-v4/lib/linodes/types';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';

export const configFactory = Factory.Sync.makeFactory<Config>({
comments: '',
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/databases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
MySQLReplicationType,
PostgresReplicationType,
} from '@linode/api-v4/lib/databases/types';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';
import { v4 } from 'uuid';

import { pickRandom, randomDate } from 'src/utilities/random';
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/disk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Disk } from '@linode/api-v4/lib/linodes/types';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';

export const linodeDiskFactory = Factory.Sync.makeFactory<Disk>({
created: '2018-01-01',
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
DomainRecord,
ZoneFile,
} from '@linode/api-v4/lib/domains/types';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';

export const domainFactory = Factory.Sync.makeFactory<Domain>({
axfr_ips: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/factories/entityTransfers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
EntityTransfer,
TransferEntities,
} from '@linode/api-v4/lib/entity-transfers/types';
import * as Factory from 'factory.ts';
import Factory from 'src/factories/factoryProxy';
import { DateTime } from 'luxon';
import { v4 } from 'uuid';

Expand Down
Loading

0 comments on commit e64101c

Please sign in to comment.