Skip to content

added new routes test #6879

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

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
4 changes: 3 additions & 1 deletion site/e2e/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ const globalSetup = async (): Promise<void> => {
axios.defaults.baseURL = `http://localhost:${constants.defaultPort}`

// Create first user
await createFirstUser({
const firstUser = await createFirstUser({
email: constants.email,
username: constants.username,
password: constants.password,
trial: false,
})

process.env.FIRST_USER = JSON.stringify(firstUser)

// Authenticated storage
const authenticatedRequestContext = await request.newContext()
await authenticatedRequestContext.post(
Expand Down
31 changes: 31 additions & 0 deletions site/e2e/tests/workspaceAccess.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { test, expect } from "@playwright/test"
import { getStatePath } from "../helpers"
import { createTemplate, createTemplateVersion, getOrganization } from "api/api"

test.use({ storageState: getStatePath("authState") })

test("admin can view own workspace", async ({ page, baseURL }) => {
// import the user response and get the org id off of that
const { FIRST_USER } = process.env
const { user_id, organization_id } = JSON.parse(FIRST_USER as any)

console.log("organizationId", organization_id)

const org = await getOrganization(organization_id)
console.log("org", org)

// const { id } = await createTemplateVersion(organization_id, {
// storage_method: "file",
// provisioner: "terraform",
// tags: {},
// })

// console.log("templateVID", id)
// // Create template
// await createTemplate(organization_id, {
// name: "my-template",
// template_version_id: id,
// })
// await page.goto(`${baseURL}/templates`, { waitUntil: "networkidle" })
// await expect(page).toHaveTitle("Templates - Coder")
})
85 changes: 45 additions & 40 deletions site/src/pages/WorkspacePage/WorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { firstOrItem } from "util/array"
import { quotaMachine } from "xServices/quotas/quotasXService"
import { workspaceMachine } from "xServices/workspace/workspaceXService"
import { WorkspaceReadyPage } from "./WorkspaceReadyPage"
import { RequirePermission } from "components/RequirePermission/RequirePermission"

export const WorkspacePage: FC = () => {
const { username: usernameQueryParam, workspace: workspaceQueryParam } =
Expand Down Expand Up @@ -42,46 +43,50 @@ export const WorkspacePage: FC = () => {
}, [username, quotaSend])

return (
<ChooseOne>
<Cond condition={workspaceState.matches("error")}>
<div className={styles.error}>
{Boolean(getWorkspaceError) && (
<AlertBanner severity="error" error={getWorkspaceError} />
)}
{Boolean(getTemplateWarning) && (
<AlertBanner severity="error" error={getTemplateWarning} />
)}
{Boolean(getTemplateParametersWarning) && (
<AlertBanner
severity="error"
error={getTemplateParametersWarning}
/>
)}
{Boolean(checkPermissionsError) && (
<AlertBanner severity="error" error={checkPermissionsError} />
)}
{Boolean(getQuotaError) && (
<AlertBanner severity="error" error={getQuotaError} />
)}
</div>
</Cond>
<Cond
condition={
Boolean(workspace) &&
workspaceState.matches("ready") &&
quotaState.matches("success")
}
>
<WorkspaceReadyPage
workspaceState={workspaceState}
quotaState={quotaState}
workspaceSend={workspaceSend}
/>
</Cond>
<Cond>
<Loader />
</Cond>
</ChooseOne>
<RequirePermission
isFeatureVisible={getWorkspaceError?.response?.status !== 404}
>
<ChooseOne>
<Cond condition={workspaceState.matches("error")}>
<div className={styles.error}>
{Boolean(getWorkspaceError) && (
<AlertBanner severity="error" error={getWorkspaceError} />
)}
{Boolean(getTemplateWarning) && (
<AlertBanner severity="error" error={getTemplateWarning} />
)}
{Boolean(getTemplateParametersWarning) && (
<AlertBanner
severity="error"
error={getTemplateParametersWarning}
/>
)}
{Boolean(checkPermissionsError) && (
<AlertBanner severity="error" error={checkPermissionsError} />
)}
{Boolean(getQuotaError) && (
<AlertBanner severity="error" error={getQuotaError} />
)}
</div>
</Cond>
<Cond
condition={
Boolean(workspace) &&
workspaceState.matches("ready") &&
quotaState.matches("success")
}
>
<WorkspaceReadyPage
workspaceState={workspaceState}
quotaState={quotaState}
workspaceSend={workspaceSend}
/>
</Cond>
<Cond>
<Loader />
</Cond>
</ChooseOne>
</RequirePermission>
)
}

Expand Down
5 changes: 3 additions & 2 deletions site/src/xServices/workspace/workspaceXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
displayError,
displaySuccess,
} from "../../components/GlobalSnackbar/utils"
import { AxiosError } from "axios"

const latestBuild = (builds: TypesGen.WorkspaceBuild[]) => {
// Cloning builds to not change the origin object with the sort()
Expand Down Expand Up @@ -56,7 +57,7 @@ export interface WorkspaceContext {
workspace?: TypesGen.Workspace
template?: TypesGen.Template
build?: TypesGen.WorkspaceBuild
getWorkspaceError?: Error | unknown
getWorkspaceError?: AxiosError
getTemplateWarning: Error | unknown
getTemplateParametersWarning: Error | unknown
// Builds
Expand Down Expand Up @@ -491,7 +492,7 @@ export const workspaceMachine = createMachine(
workspace: (_, event) => event.data,
}),
assignGetWorkspaceError: assign({
getWorkspaceError: (_, event) => event.data,
getWorkspaceError: (_, event) => event.data as AxiosError,
}),
clearGetWorkspaceError: (context) =>
assign({ ...context, getWorkspaceError: undefined }),
Expand Down