forked from outline/outline
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zod schemas for routes under
/plugins
(outline#6378)
* fix: schema for slack routes * fix: slack.post * fix: email
- Loading branch information
1 parent
7e61a51
commit 3561b79
Showing
7 changed files
with
185 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { z } from "zod"; | ||
import { Client } from "@shared/types"; | ||
import { BaseSchema } from "@server/routes/api/schema"; | ||
|
||
export const EmailSchema = BaseSchema.extend({ | ||
body: z.object({ | ||
email: z.string().email(), | ||
client: z.nativeEnum(Client).default(Client.Web), | ||
}), | ||
}); | ||
|
||
export type EmailReq = z.infer<typeof EmailSchema>; | ||
|
||
export const EmailCallbackSchema = BaseSchema.extend({ | ||
query: z.object({ | ||
token: z.string(), | ||
client: z.nativeEnum(Client).default(Client.Web), | ||
}), | ||
}); | ||
|
||
export type EmailCallbackReq = z.infer<typeof EmailCallbackSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import isEmpty from "lodash/isEmpty"; | ||
import { z } from "zod"; | ||
import { BaseSchema } from "@server/routes/api/schema"; | ||
|
||
export const SlackCommandsSchema = BaseSchema.extend({ | ||
query: z | ||
.object({ | ||
code: z.string().nullish(), | ||
state: z.string().uuid().nullish(), | ||
error: z.string().nullish(), | ||
}) | ||
.refine((req) => !(isEmpty(req.code) && isEmpty(req.error)), { | ||
message: "one of code or error is required", | ||
}), | ||
}); | ||
|
||
export type SlackCommandsReq = z.infer<typeof SlackCommandsSchema>; | ||
|
||
export const SlackPostSchema = BaseSchema.extend({ | ||
query: z | ||
.object({ | ||
code: z.string().nullish(), | ||
state: z.string().uuid().nullish(), | ||
error: z.string().nullish(), | ||
}) | ||
.refine((req) => !(isEmpty(req.code) && isEmpty(req.error)), { | ||
message: "one of code or error is required", | ||
}), | ||
}); | ||
|
||
export type SlackPostReq = z.infer<typeof SlackPostSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { getTestServer } from "@server/test/support"; | ||
|
||
const server = getTestServer(); | ||
|
||
describe("#slack.commands", () => { | ||
it("should fail with status 400 bad request if query param state is not a uuid", async () => { | ||
const res = await server.get("/auth/slack.commands?state=123"); | ||
const body = await res.json(); | ||
expect(res.status).toEqual(400); | ||
expect(body.message).toEqual("state: Invalid uuid"); | ||
}); | ||
|
||
it("should fail with status 400 bad request when both code and error are missing in query params", async () => { | ||
const res = await server.get( | ||
"/auth/slack.commands?state=182d14d5-0dbd-4521-ac52-25484c25c96e" | ||
); | ||
const body = await res.json(); | ||
expect(res.status).toEqual(400); | ||
expect(body.message).toEqual("query: one of code or error is required"); | ||
}); | ||
}); | ||
|
||
describe("#slack.post", () => { | ||
it("should fail with status 400 bad request if query param state is not a uuid", async () => { | ||
const res = await server.get("/auth/slack.post?state=123"); | ||
const body = await res.json(); | ||
expect(res.status).toEqual(400); | ||
expect(body.message).toEqual("state: Invalid uuid"); | ||
}); | ||
|
||
it("should fail with status 400 bad request when both code and error are missing in query params", async () => { | ||
const res = await server.get( | ||
"/auth/slack.post?state=182d14d5-0dbd-4521-ac52-25484c25c96e" | ||
); | ||
const body = await res.json(); | ||
expect(res.status).toEqual(400); | ||
expect(body.message).toEqual("query: one of code or error is required"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters