70bf21e064
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
34 lines
864 B
TypeScript
34 lines
864 B
TypeScript
import { env } from "cloudflare:workers";
|
|
import { it } from "vitest";
|
|
import { listPosts, readPost, upsertPost } from "../src/utils";
|
|
|
|
it("should create and read post", async ({ expect }) => {
|
|
await upsertPost(env, "/hello", "👋");
|
|
|
|
const post = await readPost(env, "/hello");
|
|
expect(post).toMatchInlineSnapshot(`
|
|
{
|
|
"author": {
|
|
"email": "admin@example.com",
|
|
"name": "Ada Min",
|
|
"username": "admin",
|
|
},
|
|
"body": "👋",
|
|
"slug": "/hello",
|
|
}
|
|
`);
|
|
});
|
|
|
|
it("should list posts", async ({ expect }) => {
|
|
await upsertPost(env, "/one", "1");
|
|
await upsertPost(env, "/two", "2");
|
|
await upsertPost(env, "/three", "3");
|
|
|
|
const posts = await listPosts(env);
|
|
expect(posts.length).toBe(4);
|
|
expect(posts[0].body).toBe("👋");
|
|
expect(posts[1].body).toBe("1");
|
|
expect(posts[2].body).toBe("2");
|
|
expect(posts[3].body).toBe("3");
|
|
});
|