55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
|
|
import { handleGetDupes } from "../../app/api/assets/[id]/dupes/handlers";
|
|
|
|
describe("handleGetDupes", () => {
|
|
test("returns empty list when hash is missing", async () => {
|
|
let call = 0;
|
|
const db = async () => {
|
|
call += 1;
|
|
return [] as unknown[];
|
|
};
|
|
|
|
const result = await handleGetDupes({
|
|
params: { id: "00000000-0000-0000-0000-000000000000" },
|
|
db,
|
|
});
|
|
expect(result.status).toBe(200);
|
|
expect(result.body).toEqual({ items: [] });
|
|
expect(call).toBe(1);
|
|
});
|
|
|
|
test("returns dupes excluding the asset id", async () => {
|
|
const calls: unknown[] = [];
|
|
const db = async () => {
|
|
calls.push(true);
|
|
if (calls.length === 1) {
|
|
return [{ bucket: "photos", sha256: "hash" }];
|
|
}
|
|
return [
|
|
{
|
|
id: "11111111-1111-1111-1111-111111111111",
|
|
media_type: "image",
|
|
status: "ready",
|
|
},
|
|
];
|
|
};
|
|
|
|
const result = await handleGetDupes({
|
|
params: { id: "00000000-0000-0000-0000-000000000000" },
|
|
db,
|
|
});
|
|
expect(result.status).toBe(200);
|
|
expect(result.body).toEqual({
|
|
items: [
|
|
{
|
|
id: "11111111-1111-1111-1111-111111111111",
|
|
media_type: "image",
|
|
status: "ready",
|
|
},
|
|
],
|
|
});
|
|
expect(calls.length).toBe(2);
|
|
});
|
|
});
|