Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e2315c

Browse files
committed
Clean up api and mocks
1 parent 507b54a commit 0e2315c

File tree

3 files changed

+17
-33
lines changed

3 files changed

+17
-33
lines changed

site/src/api/index.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,6 @@ export const provisioners: Types.Provisioner[] = [
1717
},
1818
]
1919

20-
export namespace Project {
21-
export const create = async (request: Types.CreateProjectRequest): Promise<Types.Project> => {
22-
const response = await fetch(`/api/v2/projects/${request.organizationId}/`, {
23-
method: "POST",
24-
headers: {
25-
"Content-Type": "application/json",
26-
},
27-
body: JSON.stringify(request),
28-
})
29-
30-
const body = await response.json()
31-
await mutate("/api/v2/projects")
32-
if (!response.ok) {
33-
throw new Error(body.message)
34-
}
35-
36-
return body
37-
}
38-
}
39-
4020
export namespace Workspace {
4121
export const create = async (request: Types.CreateWorkspaceRequest): Promise<Types.Workspace> => {
4222
const response = await fetch(`/api/v2/users/me/workspaces`, {

site/src/test_helpers/entities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ export const MockWorkspace: Workspace = {
3939
created_at: "",
4040
updated_at: "",
4141
project_id: MockProject.id,
42-
owner_id: MockUser.id
42+
owner_id: MockUser.id,
4343
}

site/src/test_helpers/handlers.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,24 @@ import { rest } from "msw"
22
import * as M from "./entities"
33

44
export const handlers = [
5-
rest.post("/api/v2/users/me/workspaces", async (req, res, ctx) => {
6-
return res(ctx.status(200), ctx.json(M.MockWorkspace))
7-
}),
8-
rest.get("/api/v2/projects/:organizationId", async (req, res, ctx) => {
9-
return res(ctx.status(200), ctx.json(M.MockProject))
5+
// organizations
6+
rest.get("/api/v2/organizations/:organizationId", async (req, res, ctx) => {
7+
return res(ctx.status(200), ctx.json(M.MockOrganization))
108
}),
11-
rest.get("/api/v2/users/me/organizations/:organizationId", async (req, res, ctx) => {
9+
rest.get("/api/v2/organizations/:organizationId/projects/:projectId", async (req, res, ctx) => {
1210
return res(ctx.status(200), ctx.json(M.MockProject))
1311
}),
14-
rest.get("/api/v2/workspaces/:workspaceId", async (req, res, ctx) => {
15-
return res(ctx.status(200), ctx.json(M.MockWorkspace))
16-
}),
12+
13+
// projects
1714
rest.get("/api/v2/projects/:projectId", async (req, res, ctx) => {
1815
return res(ctx.status(200), ctx.json(M.MockProject))
1916
}),
20-
rest.get("/api/v2/organizations/:organizationId", async (req, res, ctx) => {
21-
return res(ctx.status(200), ctx.json(M.MockOrganization))
17+
18+
// users
19+
rest.post("/api/v2/users/me/workspaces", async (req, res, ctx) => {
20+
return res(ctx.status(200), ctx.json(M.MockWorkspace))
2221
}),
23-
rest.get("/api/v2/organizations/:organizationId/projects/:projectId", async (req, res, ctx) => {
22+
rest.get("/api/v2/users/me/organizations/:organizationId", async (req, res, ctx) => {
2423
return res(ctx.status(200), ctx.json(M.MockOrganization))
2524
}),
2625
rest.post("/api/v2/users/login", async (req, res, ctx) => {
@@ -35,4 +34,9 @@ export const handlers = [
3534
rest.get("/api/v2/users/me/keys", async (req, res, ctx) => {
3635
return res(ctx.status(200), ctx.json(M.MockAPIKey))
3736
}),
37+
38+
// workspaces
39+
rest.get("/api/v2/workspaces/:workspaceId", async (req, res, ctx) => {
40+
return res(ctx.status(200), ctx.json(M.MockWorkspace))
41+
}),
3842
]

0 commit comments

Comments
 (0)