mirror of https://github.com/coder/coder.git
fix: create workspace with optional auth providers (#12729)
This commit is contained in:
parent
c674128105
commit
0966fe2560
|
@ -233,6 +233,46 @@ describe("CreateWorkspacePage", () => {
|
|||
);
|
||||
});
|
||||
|
||||
it("optional external auth is optional", async () => {
|
||||
jest
|
||||
.spyOn(API, "getWorkspaceQuota")
|
||||
.mockResolvedValueOnce(MockWorkspaceQuota);
|
||||
jest
|
||||
.spyOn(API, "getUsers")
|
||||
.mockResolvedValueOnce({ users: [MockUser], count: 1 });
|
||||
jest.spyOn(API, "createWorkspace").mockResolvedValueOnce(MockWorkspace);
|
||||
jest
|
||||
.spyOn(API, "getTemplateVersionExternalAuth")
|
||||
.mockResolvedValue([
|
||||
{ ...MockTemplateVersionExternalAuthGithub, optional: true },
|
||||
]);
|
||||
|
||||
renderCreateWorkspacePage();
|
||||
await waitForLoaderToBeRemoved();
|
||||
|
||||
const nameField = await screen.findByLabelText(nameLabelText);
|
||||
// have to use fireEvent b/c userEvent isn't cleaning up properly between tests
|
||||
fireEvent.change(nameField, {
|
||||
target: { value: "test" },
|
||||
});
|
||||
|
||||
// Ensure we're not logged in
|
||||
await screen.findByText("Login with GitHub");
|
||||
|
||||
const submitButton = screen.getByText(createWorkspaceText);
|
||||
await userEvent.click(submitButton);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(API.createWorkspace).toBeCalledWith(
|
||||
MockUser.organization_ids[0],
|
||||
MockUser.id,
|
||||
expect.objectContaining({
|
||||
...MockWorkspaceRequest,
|
||||
}),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it("auto create a workspace if uses mode=auto", async () => {
|
||||
const param = "first_parameter";
|
||||
const paramValue = "It works!";
|
||||
|
|
|
@ -21,6 +21,7 @@ const meta: Meta<typeof CreateWorkspacePageView> = {
|
|||
template: MockTemplate,
|
||||
parameters: [],
|
||||
externalAuth: [],
|
||||
hasAllRequiredExternalAuth: true,
|
||||
mode: "form",
|
||||
permissions: {
|
||||
createWorkspaceForUser: true,
|
||||
|
@ -134,6 +135,7 @@ export const ExternalAuth: Story = {
|
|||
optional: true,
|
||||
},
|
||||
],
|
||||
hasAllRequiredExternalAuth: false,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -159,6 +161,7 @@ export const ExternalAuthError: Story = {
|
|||
optional: true,
|
||||
},
|
||||
],
|
||||
hasAllRequiredExternalAuth: false,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
|
|||
externalAuth,
|
||||
externalAuthPollingState,
|
||||
startPollingExternalAuth,
|
||||
hasAllRequiredExternalAuth,
|
||||
parameters,
|
||||
autofillParameters,
|
||||
permissions,
|
||||
|
@ -92,7 +93,6 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
|
|||
onCancel,
|
||||
}) => {
|
||||
const [owner, setOwner] = useState(defaultOwner);
|
||||
const requiresExternalAuth = externalAuth.some((auth) => !auth.authenticated);
|
||||
const [suggestedName, setSuggestedName] = useState(() =>
|
||||
generateWorkspaceName(),
|
||||
);
|
||||
|
@ -117,7 +117,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
|
|||
}),
|
||||
enableReinitialize: true,
|
||||
onSubmit: (request) => {
|
||||
if (requiresExternalAuth) {
|
||||
if (!hasAllRequiredExternalAuth) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -144,10 +144,6 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
|
|||
[autofillParameters],
|
||||
);
|
||||
|
||||
const hasAllRequiredExternalAuth = externalAuth.every(
|
||||
(auth) => auth.optional || auth.authenticated,
|
||||
);
|
||||
|
||||
return (
|
||||
<Margins size="medium">
|
||||
<PageHeader actions={<Button onClick={onCancel}>Cancel</Button>}>
|
||||
|
|
Loading…
Reference in New Issue