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-8146] - Cypress tests for refactored Linode Create via CLI flow #10765

Closed
wants to merge 2 commits into from
Closed
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-10765-tests-1723152376908.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Cypress tests for refactored Linode Create via CLI flow ([#10765](https://github.com/linode/manager/pull/10765))
Copy link
Contributor

Choose a reason for hiding this comment

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

I may be misunderstanding the point of this ticket, but based on the comment on L4-L5 of this file:

// TODO Delete this test file when `linodeCreateRefactor` feature flag is retired.
// Move out any tests (e.g. region select test) for flows that aren't covered by new tests in the meantime.

It sounds like we wouldn't want to make updates in this file, but rather write a new test file that tests CLI in the refactored (v2) flow. Since this test suite mocks the linode create feature flag false, we don't seem to be doing that here.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { chooseRegion } from 'support/util/regions';
import { getRegionById } from 'support/util/regions';
import {
accountFactory,
createLinodeRequestFactory,
subnetFactory,
vpcFactory,
linodeFactory,
Expand All @@ -29,6 +30,8 @@ import {
import { authenticate } from 'support/api/authentication';
import { cleanUp } from 'support/util/cleanup';
import { mockGetRegions } from 'support/intercepts/regions';
import { API_ROOT } from 'src/constants';
import { oauthToken } from 'support/constants/api';
import {
dcPricingPlanPlaceholder,
dcPricingMockLinodeTypes,
Expand Down Expand Up @@ -179,6 +182,20 @@ describe('create linode', () => {
const linodeLabel = randomLabel();
const linodePass = randomString(32);
const linodeRegion = chooseRegion();
const linodeType = 'g6-dedicated-2';
const linodeImage = 'linode/debian11';
const payload = createLinodeRequestFactory.build({
authorized_users: [],
backups_enabled: false,
booted: true,
image: linodeImage,
label: linodeLabel,
private_ip: false,
region: linodeRegion.id,
root_pass: linodePass,
tags: [],
type: linodeType,
});

cy.visitWithLogin('/linodes/create');

Expand All @@ -188,7 +205,7 @@ describe('create linode', () => {
.should('exist')
.click();

cy.get('[id="g6-dedicated-2"]').click();
cy.get(`[id="${linodeType}"]`).click();

cy.findByLabelText('Linode Label')
.should('be.visible')
Expand All @@ -207,42 +224,93 @@ describe('create linode', () => {
.should('be.enabled')
.click();

// Confirm that clicking "Create Using Command Line" opens modal
ui.dialog
.findByTitle('Create Linode')
.should('be.visible')
.within(() => {
// Switch to cURL view if necessary.
// Switch to cURL view.
cy.findByText('cURL')
.should('be.visible')
.should('have.attr', 'data-selected');

// Confirm that cURL command has expected details.
// Confirm that displayed cURL command matches selected options (e.g. region, image, plan, label, password, add-ons, etc.)
[
`"region": "${linodeRegion.id}"`,
`"type": "g6-dedicated-2"`,
`"label": "${linodeLabel}"`,
`"root_pass": "${linodePass}"`,
'"booted": true',
`"authorized_users": ${payload.authorized_users}`,
`"backups_enabled": ${payload.backups_enabled}`,
`"booted": ${payload.booted}`,
`"image": "${payload.image}"`,
`"label": "${payload.label}"`,
`"private_ip": ${payload.private_ip},`,
`"region": "${payload.region}"`,
`"root_pass": "${payload.root_pass}"`,
`"tags": ${payload.tags}`,
`"type": "${payload.type}"`,
`${API_ROOT}/linode/instances`,
].forEach((line: string) =>
cy.findByText(line, { exact: false }).should('be.visible')
);

// Switch to "Linode CLI" view
cy.findByText('Linode CLI').should('be.visible').click();

[
`--region ${linodeRegion.id}`,
'--type g6-dedicated-2',
`--label ${linodeLabel}`,
`--root_pass ${linodePass}`,
`--booted true`,
].forEach((line: string) => cy.contains(line).should('be.visible'));
// Confirm that displayed Linode CLI command matches selected options (e.g. region, image, plan, label, password, add-ons, etc.)
cy.get('code').then(($code) => {
const codeText = $code.text();
[
'linode-cli linodes create',
`--backups_enabled ${payload.backups_enabled}`,
`--booted ${payload.booted}`,
`--image ${payload.image}`,
`--label ${payload.label}`,
`--private_ip ${payload.private_ip}`,
`--region ${payload.region}`,
`--root_pass ${payload.root_pass}`,
`--type ${payload.type}`,
].forEach((line: string) => expect(codeText).to.contains(line));
});

ui.buttonGroup
.findButtonByTitle('Close')
.should('be.visible')
.should('be.enabled')
.click();
});

// Continue on testing when the personal access token is given.
if (oauthToken) {
const curlRequest = `curl -H "Content-Type: application/json" \
-H "Authorization: Bearer ${oauthToken}" \
-X POST -d '{
"authorized_users": [],
"backups_enabled": ${payload.backups_enabled},
"booted": ${payload.booted},
"image": "${payload.image}",
"label": "${payload.label}",
"private_ip": ${payload.private_ip},
"region": "${payload.region}",
"root_pass": "${payload.root_pass}",
"tags": [],
"type": "${payload.type}"
}' ${API_ROOT}/linode/instances`;
cy.exec(curlRequest).then((res) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The CI error is being caused by executing the curl command. It seems like the jenkins instance doesn't have curl installed on it.

Stderr:
/usr/bin/bash: line 1: curl: command not found

@jdamore-linode can we update the jenkins docker config to install cURL if we want to go ahead with this approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

@cliu-akamai (cc @hkhalil-akamai) we probably shouldn't be doing this E2E, and instead should mock the relevant events to trigger/test the redirect behavior, even though this is really, really cool as it is.

(I'm only reluctant to do this because we wouldn't have the normal security guardrails available, like ensuring that the created Linode can't connect to the internet, etc. -- basically none of the protections that were added by #10538 and #10633 would apply to this cURL call)

// Check the linode instance details
expect(res.code).to.equal(0);

const resBody = JSON.parse(res.stdout);
expect(resBody.id).to.not.NaN;
expect(resBody.image).to.equal(payload.image);
expect(resBody.label).to.equal(payload.label);
expect(resBody.region).to.equal(payload.region);
expect(resBody.type).to.equal(payload.type);
});

cy.visitWithLogin('/linodes/');

// Confirm that the linode is created.
cy.findByText(linodeLabel).should('be.visible');
cy.findByText('Provisioning', { exact: false }).should('be.visible');
Comment on lines +308 to +312
Copy link
Contributor

Choose a reason for hiding this comment

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

Not quite what the acceptance criteria requested here: Confirm Cloud Manager behavior to automatically redirect to created Linode after CLI command is executed. Isn't the redirect to the Linode's details page?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it doesn't redirect after sending the CLI.

}
});

/*
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Copy link
Contributor

Choose a reason for hiding this comment

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

How did this get in here?

Original file line number Diff line number Diff line change
Expand Up @@ -5653,15 +5653,10 @@ camelcase@^7.0.0:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-7.0.1.tgz#f02e50af9fd7782bc8b88a3558c32fd3a388f048"
integrity sha512-xlx1yCK2Oc1APsPXDL2LdlNP6+uu8OCDdhOBSVT279M/S+y75O30C2VuD8T2ogdePBBl7PfPF4504tnLgX3zfw==

caniuse-lite@^1.0.30001580:
version "1.0.30001585"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001585.tgz#0b4e848d84919c783b2a41c13f7de8ce96744401"
integrity sha512-yr2BWR1yLXQ8fMpdS/4ZZXpseBgE7o4g41x3a6AJOqZuOi+iE/WdJYAuZ6Y95i4Ohd2Y+9MzIWRR+uGABH4s3Q==

caniuse-lite@^1.0.30001587:
version "1.0.30001618"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001618.tgz#fad74fa006aef0f01e8e5c0a5540c74d8d36ec6f"
integrity sha512-p407+D1tIkDvsEAPS22lJxLQQaG8OTBEqo0KhzfABGk0TU4juBNDSfH0hyAp/HRyx+M8L17z/ltyhxh27FTfQg==
caniuse-lite@^1.0.30001580, caniuse-lite@^1.0.30001587:
version "1.0.30001651"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001651.tgz"
integrity sha512-9Cf+Xv1jJNe1xPZLGuUXLNkE1BoDkqRqYyFJ9TDYSqhduqA4hu4oR9HluGoWYQC/aj8WHjsGVV+bwkh0+tegRg==

canvg@^3.0.6:
version "3.0.10"
Expand Down Expand Up @@ -11362,7 +11357,7 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==

"prettier-fallback@npm:prettier@^3", prettier@^3.1.1:
"prettier-fallback@npm:prettier@^3":
version "3.2.5"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.2.5.tgz#e52bc3090586e824964a8813b09aba6233b28368"
integrity sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==
Expand All @@ -11374,6 +11369,11 @@ prettier-linter-helpers@^1.0.0:
dependencies:
fast-diff "^1.1.2"

prettier@^3.1.1:
version "3.2.5"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.2.5.tgz#e52bc3090586e824964a8813b09aba6233b28368"
integrity sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==

prettier@~2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
Expand Down
Loading