Files
outline/server/routes/api/stars.test.ts
Tom Moor 1fbc000e03 chore: Reduce test boilerplate (#4300)
* chore: Reduce test boilerplate

* mo
2022-10-15 19:40:21 -07:00

82 lines
2.0 KiB
TypeScript

import { buildUser, buildStar, buildDocument } from "@server/test/factories";
import { getTestServer } from "@server/test/support";
const server = getTestServer();
describe("#stars.create", () => {
it("should create a star", async () => {
const user = await buildUser();
const document = await buildDocument({
userId: user.id,
teamId: user.teamId,
});
const res = await server.post("/api/stars.create", {
body: {
token: user.getJwtToken(),
documentId: document.id,
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.documentId).toEqual(document.id);
});
it("should require authentication", async () => {
const res = await server.post("/api/stars.create");
expect(res.status).toEqual(401);
});
});
describe("#stars.list", () => {
it("should list users stars", async () => {
const user = await buildUser();
await buildStar();
const star = await buildStar({
userId: user.id,
});
const res = await server.post("/api/stars.list", {
body: {
token: user.getJwtToken(),
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.stars.length).toEqual(1);
expect(body.data.stars[0].id).toEqual(star.id);
});
it("should require authentication", async () => {
const res = await server.post("/api/stars.list");
expect(res.status).toEqual(401);
});
});
describe("#stars.delete", () => {
it("should delete users star", async () => {
const user = await buildUser();
const star = await buildStar({
userId: user.id,
});
const res = await server.post("/api/stars.delete", {
body: {
id: star.id,
token: user.getJwtToken(),
},
});
expect(res.status).toEqual(200);
});
it("should require authentication", async () => {
const res = await server.post("/api/stars.delete");
expect(res.status).toEqual(401);
});
});