- Notifications
You must be signed in to change notification settings - Fork928
chore: add e2e test against an external auth provider during workspace creation#12985
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
638ce38
e150061
eb40352
5a9ddaf
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -31,6 +31,7 @@ import { | ||
type Resource, | ||
Response, | ||
type RichParameter, | ||
type ExternalAuthProviderResource, | ||
} from "./provisionerGenerated"; | ||
// requiresEnterpriseLicense will skip the test if we're not running with an enterprise license | ||
@@ -49,6 +50,7 @@ export const createWorkspace = async ( | ||
templateName: string, | ||
richParameters: RichParameter[] = [], | ||
buildParameters: WorkspaceBuildParameter[] = [], | ||
useExternalAuthProvider: string | undefined = undefined, | ||
Comment on lines 50 to +53 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. I think that with the new parameter, the function is getting a little unwieldy, and if you're looking at things from the consumer side, it's hard to tell which of the five arguments correspond to what Maybe this could be refactored to an object, so that we have sort of have named arguments? typeCreateWorkspaceInputs=Readonly<{// Required propertiespage:Page;templateName:string;// Optional propertiesrichParameters?:readonlyRichParameter[];buildParameters?:readonlyWorkspaceBuildParameter[];externalAuthProvider?:string;}> 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. I agree in principle, but I think 5 params is still manageable and not worth refactoring the 26 usages of this function IMHO. Happy to discuss. | ||
): Promise<string> => { | ||
await page.goto(`/templates/${templateName}/workspace`, { | ||
waitUntil: "domcontentloaded", | ||
@@ -59,6 +61,25 @@ export const createWorkspace = async ( | ||
await page.getByLabel("name").fill(name); | ||
await fillParameters(page, richParameters, buildParameters); | ||
if (useExternalAuthProvider !== undefined) { | ||
// Create a new context for the popup which will be created when clicking the button | ||
const popupPromise = page.waitForEvent("popup"); | ||
// Find the "Login with <Provider>" button | ||
const externalAuthLoginButton = page | ||
.getByRole("button") | ||
.getByText("Login with GitHub"); | ||
await expect(externalAuthLoginButton).toBeVisible(); | ||
// Click it | ||
await externalAuthLoginButton.click(); | ||
// Wait for authentication to occur | ||
const popup = await popupPromise; | ||
await popup.waitForSelector("text=You are now authenticated."); | ||
} | ||
await page.getByTestId("form-submit").click(); | ||
await expectUrl(page).toHavePathName("/@admin/" + name); | ||
@@ -648,6 +669,37 @@ export const echoResponsesWithParameters = ( | ||
}; | ||
}; | ||
export const echoResponsesWithExternalAuth = ( | ||
providers: ExternalAuthProviderResource[], | ||
): EchoProvisionerResponses => { | ||
return { | ||
parse: [ | ||
{ | ||
parse: {}, | ||
}, | ||
], | ||
plan: [ | ||
{ | ||
plan: { | ||
externalAuthProviders: providers, | ||
}, | ||
}, | ||
], | ||
apply: [ | ||
{ | ||
apply: { | ||
externalAuthProviders: providers, | ||
resources: [ | ||
{ | ||
name: "example", | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}; | ||
}; | ||
export const fillParameters = async ( | ||
page: Page, | ||
richParameters: RichParameter[] = [], | ||