All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 50s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import {
|
|
createUser,
|
|
db,
|
|
get,
|
|
insertDump,
|
|
insertPlaylist,
|
|
test,
|
|
} from "../helpers.ts";
|
|
import type { SearchResults } from "../../../shared/search.ts";
|
|
import { assertEquals, assertFalse } from "@std/assert";
|
|
|
|
test("GET /api/search: dumps, users and playlists, privacy-filtered", async () => {
|
|
const owner = await createUser({ username: "searcher_a" });
|
|
const other = await createUser();
|
|
db.prepare(
|
|
`UPDATE users SET description = 'loves banana bread' WHERE id = ?;`,
|
|
).run(other.id);
|
|
insertDump({ userId: owner.id, title: "Banana split" });
|
|
insertDump({
|
|
userId: owner.id,
|
|
title: "x",
|
|
comment: "a banana in the comment",
|
|
});
|
|
insertDump({
|
|
userId: owner.id,
|
|
title: "y",
|
|
richContent: { type: "generic", url: "u", description: "banana page" },
|
|
});
|
|
insertDump({ userId: owner.id, title: "Secret banana", isPrivate: true });
|
|
insertDump({ userId: owner.id, title: "Apple" });
|
|
insertPlaylist({ userId: owner.id, title: "Banana hits" });
|
|
insertPlaylist({
|
|
userId: owner.id,
|
|
title: "Private bananas",
|
|
isPublic: false,
|
|
});
|
|
|
|
const anon = (await get<SearchResults>("/api/search?q=banana")).data;
|
|
assertEquals(anon.dumps.total, 3);
|
|
assertEquals(anon.users.map((u) => u.id), [other.id]);
|
|
// Profiles only: a search must never hand out hashes or emails.
|
|
assertFalse("passwordHash" in anon.users[0]);
|
|
assertFalse("email" in anon.users[0]);
|
|
assertEquals(anon.playlists.map((p) => p.title), [
|
|
"Banana hits",
|
|
]);
|
|
|
|
const mine =
|
|
(await get<SearchResults>("/api/search?q=banana", { auth: owner.auth }))
|
|
.data;
|
|
assertEquals(mine.dumps.total, 4);
|
|
assertEquals(mine.playlists.length, 2);
|
|
|
|
const paged =
|
|
(await get<SearchResults>("/api/search?q=banana&limit=2")).data.dumps;
|
|
assertEquals(paged.items.length, 2);
|
|
assertEquals(paged.hasMore, true);
|
|
|
|
assertEquals((await get<SearchResults>("/api/search?q=%20%20")).data, {
|
|
dumps: { items: [], total: 0, hasMore: false },
|
|
users: [],
|
|
playlists: [],
|
|
});
|
|
});
|