-
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.
Added ping pong api endpoints to uuid.rocks package
- Loading branch information
Showing
7 changed files
with
71 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { z } from "zod"; | ||
|
||
import type { | ||
PingPongJsonSchema, | ||
PingPongSchema, | ||
} from "./ping-pong.validators"; | ||
|
||
export type PingPong = z.infer<typeof PingPongSchema>; | ||
|
||
export type PingPongJson = z.infer<typeof PingPongJsonSchema>; |
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,9 @@ | ||
import { z } from "zod"; | ||
|
||
export const PingPongSchema = z.union([z.literal("ping"), z.literal("pong")]); | ||
|
||
export const PingPongJsonSchema = z.object({ | ||
country: z.string(), | ||
ip: z.string().ip({ version: "v4" }), | ||
ping: PingPongSchema, | ||
}); |
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
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,33 @@ | ||
import { describe, it, expect } from "vitest"; | ||
|
||
import { PingPongJsonSchema, PingPongSchema } from "../src/zod"; | ||
import { useTestClient } from "./_client"; | ||
|
||
describe.concurrent("uuid.rocks - ping pong", () => { | ||
it("GET - /api/ping", async () => { | ||
const client = useTestClient({ json: false }); | ||
|
||
const pingPong = await client("/api/ping"); | ||
|
||
expect(pingPong).toBeDefined(); | ||
expect(pingPong).toBeTypeOf("string"); | ||
|
||
expect(PingPongSchema.safeParse(pingPong).success).toBe(true); | ||
}); | ||
|
||
it("GET - /api/ping?json", async () => { | ||
const client = useTestClient({ json: true }); | ||
|
||
const pingPongJson = await client("/api/ping?json"); | ||
|
||
expect(pingPongJson).toBeDefined(); | ||
expect(pingPongJson.country).toBeDefined(); | ||
expect(pingPongJson.country).toBeTypeOf("string"); | ||
expect(pingPongJson.ip).toBeDefined(); | ||
expect(pingPongJson.ip).toBeTypeOf("string"); | ||
expect(pingPongJson.ping).toBeDefined(); | ||
expect(pingPongJson.ping).toBeTypeOf("string"); | ||
|
||
expect(PingPongJsonSchema.safeParse(pingPongJson).success).toBe(true); | ||
}); | ||
}); |