Skip to content

Commit da73128

Browse files
committed
test: add v1 versions tests
1 parent 73531d8 commit da73128

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { z } from "zod";
2-
import type { ApiErrorSchema, EMOJI_LOCK_SCHEMA } from "./schemas";
2+
import type { ApiErrorSchema, EMOJI_LOCK_SCHEMA, EmojiVersionSchema } from "./schemas";
33

44
export interface HonoContext {
55
Bindings: {
@@ -12,3 +12,4 @@ export type HonoBindings = HonoContext["Bindings"];
1212

1313
export type ApiError = z.infer<typeof ApiErrorSchema>;
1414
export type EmojiLock = z.infer<typeof EMOJI_LOCK_SCHEMA>;
15+
export type EmojiVersion = z.infer<typeof EmojiVersionSchema>;

test/routes/v1_versions.test.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import type { EmojiVersion } from "../../src/types";
2+
import {
3+
createExecutionContext,
4+
env,
5+
waitOnExecutionContext,
6+
} from "cloudflare:test";
7+
import { describe, expect, it } from "vitest";
8+
import worker from "../../src";
9+
10+
describe("v1_versions", () => {
11+
it("should return all versions", async () => {
12+
const request = new Request("https://mojis.dev/api/v1/versions");
13+
const ctx = createExecutionContext();
14+
const response = await worker.fetch(request, env, ctx);
15+
await waitOnExecutionContext(ctx);
16+
17+
expect(response.status).toBe(200);
18+
const data = await response.json() as EmojiVersion[];
19+
expect(Array.isArray(data)).toBe(true);
20+
expect(data[0]).toMatchObject({
21+
emoji_version: expect.any(String),
22+
unicode_version: expect.any(String),
23+
draft: expect.any(Boolean),
24+
});
25+
});
26+
27+
it("should return latest version", async () => {
28+
const request = new Request("https://mojis.dev/api/v1/versions/latest");
29+
const ctx = createExecutionContext();
30+
const response = await worker.fetch(request, env, ctx);
31+
await waitOnExecutionContext(ctx);
32+
33+
expect(response.status).toBe(200);
34+
const data = await response.json() as EmojiVersion;
35+
expect(data).toMatchObject({
36+
emoji_version: expect.any(String),
37+
unicode_version: expect.any(String),
38+
draft: expect.any(Boolean),
39+
});
40+
});
41+
42+
it("should return latest draft version", async () => {
43+
const request = new Request("https://mojis.dev/api/v1/versions/draft");
44+
const ctx = createExecutionContext();
45+
const response = await worker.fetch(request, env, ctx);
46+
await waitOnExecutionContext(ctx);
47+
48+
expect(response.status).toBe(200);
49+
const data = await response.json() as EmojiVersion;
50+
expect(data).toMatchObject({
51+
emoji_version: expect.any(String),
52+
unicode_version: expect.any(String),
53+
draft: true,
54+
});
55+
});
56+
57+
it("should exclude draft versions when draft=true query param is set", async () => {
58+
const request = new Request("https://mojis.dev/api/v1/versions?draft=true");
59+
const ctx = createExecutionContext();
60+
const response = await worker.fetch(request, env, ctx);
61+
await waitOnExecutionContext(ctx);
62+
63+
expect(response.status).toBe(200);
64+
const data = await response.json() as EmojiVersion[];
65+
expect(Array.isArray(data)).toBe(true);
66+
expect(data.every((version) => !version.draft)).toBe(true);
67+
});
68+
});

0 commit comments

Comments
 (0)