You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.4 KiB
40 lines
1.4 KiB
import { describe, expect, test } from "bun:test";
|
|
import { parseMeMediaAssetsQuery } from "./me-media-assets-query";
|
|
|
|
describe("parseMeMediaAssetsQuery", () => {
|
|
test("defaults: {} -> { page: 1, pageSize: 20, search: null }", () => {
|
|
expect(parseMeMediaAssetsQuery({})).toEqual({ page: 1, pageSize: 20, search: null });
|
|
});
|
|
|
|
test("pageSize 10 and 50 are accepted", () => {
|
|
expect(parseMeMediaAssetsQuery({ pageSize: "10" })).toEqual({ page: 1, pageSize: 10, search: null });
|
|
expect(parseMeMediaAssetsQuery({ pageSize: "50" })).toEqual({ page: 1, pageSize: 50, search: null });
|
|
});
|
|
|
|
test("search trims and empty becomes null", () => {
|
|
expect(parseMeMediaAssetsQuery({ search: " hello " })).toEqual({
|
|
page: 1,
|
|
pageSize: 20,
|
|
search: "hello",
|
|
});
|
|
expect(parseMeMediaAssetsQuery({ search: " " })).toEqual({ page: 1, pageSize: 20, search: null });
|
|
});
|
|
|
|
test("search over 200 chars throws 400", () => {
|
|
try {
|
|
parseMeMediaAssetsQuery({ search: "x".repeat(201) });
|
|
expect.unreachable();
|
|
} catch (e: unknown) {
|
|
expect(e).toMatchObject({ statusCode: 400 });
|
|
}
|
|
});
|
|
|
|
test("pageSize 15 throws with statusCode 400", () => {
|
|
try {
|
|
parseMeMediaAssetsQuery({ pageSize: "15" });
|
|
expect.unreachable();
|
|
} catch (e: unknown) {
|
|
expect(e).toMatchObject({ statusCode: 400 });
|
|
}
|
|
});
|
|
});
|
|
|