feat: create route to handle updating watch status in AniList
This commit is contained in:
99
src/controllers/watch-status/index.spec.ts
Normal file
99
src/controllers/watch-status/index.spec.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
import { beforeEach, describe, expect, it } from "bun:test";
|
||||
|
||||
import app from "~/index";
|
||||
import { server } from "~/mocks";
|
||||
import { getDb, resetDb } from "~/models/db";
|
||||
import { tokenTable } from "~/models/schema";
|
||||
|
||||
server.listen();
|
||||
console.error = () => {};
|
||||
|
||||
describe("requests the /watch-status route", () => {
|
||||
const db = getDb({
|
||||
TURSO_URL: "http://127.0.0.1:3000",
|
||||
TURSO_AUTH_TOKEN: "asd",
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await resetDb();
|
||||
});
|
||||
|
||||
it("saving title, deviceId in db, should succeed", async () => {
|
||||
await db.insert(tokenTable).values({ deviceId: "123", token: "asd" });
|
||||
|
||||
const res = await app.request(
|
||||
"/watch-status",
|
||||
{
|
||||
method: "POST",
|
||||
headers: new Headers({
|
||||
"x-anilist-token": "asd",
|
||||
"Content-Type": "application/json",
|
||||
}),
|
||||
body: JSON.stringify({
|
||||
deviceId: "123",
|
||||
watchStatus: "CURRENT",
|
||||
titleId: 10,
|
||||
}),
|
||||
},
|
||||
{
|
||||
TURSO_URL: process.env.TURSO_URL,
|
||||
TURSO_AUTH_TOKEN: process.env.TURSO_AUTH_TOKEN,
|
||||
},
|
||||
);
|
||||
|
||||
expect(res.json()).resolves.toEqual({ success: true });
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
|
||||
it("saving title, deviceId not in db, should fail", async () => {
|
||||
const res = await app.request(
|
||||
"/watch-status",
|
||||
{
|
||||
method: "POST",
|
||||
headers: new Headers({
|
||||
"x-anilist-token": "asd",
|
||||
"Content-Type": "application/json",
|
||||
}),
|
||||
body: JSON.stringify({
|
||||
deviceId: "123",
|
||||
watchStatus: "CURRENT",
|
||||
titleId: 10,
|
||||
}),
|
||||
},
|
||||
{
|
||||
TURSO_URL: process.env.TURSO_URL,
|
||||
TURSO_AUTH_TOKEN: process.env.TURSO_AUTH_TOKEN,
|
||||
},
|
||||
);
|
||||
|
||||
expect(res.json()).resolves.toEqual({ success: false });
|
||||
expect(res.status).toBe(500);
|
||||
});
|
||||
|
||||
it("saving title, Anilist request fails, should succeed", async () => {
|
||||
await db.insert(tokenTable).values({ deviceId: "123", token: "asd" });
|
||||
|
||||
const res = await app.request(
|
||||
"/watch-status",
|
||||
{
|
||||
method: "POST",
|
||||
headers: new Headers({
|
||||
"x-anilist-token": "asd",
|
||||
"Content-Type": "application/json",
|
||||
}),
|
||||
body: JSON.stringify({
|
||||
deviceId: "123",
|
||||
watchStatus: "CURRENT",
|
||||
titleId: -1,
|
||||
}),
|
||||
},
|
||||
{
|
||||
TURSO_URL: process.env.TURSO_URL,
|
||||
TURSO_AUTH_TOKEN: process.env.TURSO_AUTH_TOKEN,
|
||||
},
|
||||
);
|
||||
|
||||
expect(res.json()).resolves.toEqual({ success: true });
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user