-
Notifications
You must be signed in to change notification settings - Fork 358
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import { chooseRegion } from 'support/util/regions'; | |
import { getRegionById } from 'support/util/regions'; | ||
import { | ||
accountFactory, | ||
createLinodeRequestFactory, | ||
subnetFactory, | ||
vpcFactory, | ||
linodeFactory, | ||
|
@@ -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, | ||
|
@@ -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'); | ||
|
||
|
@@ -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') | ||
|
@@ -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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
@jdamore-linode can we update the jenkins docker config to install cURL if we want to go ahead with this approach? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not quite what the acceptance criteria requested here: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it doesn't redirect after sending the CLI. |
||
} | ||
}); | ||
|
||
/* | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How did this get in here? |
There was a problem hiding this comment.
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:
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.