Skip to content

Commit 94652d8

Browse files
committed
test: 同じクエリパラメータを 2 回以上指定した場合のテスト追加
1 parent 402829c commit 94652d8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

app/feature/search/pagination.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,33 @@ describe("buildPaginationMeta", () => {
101101

102102
expect(nextQuery).toBe(null);
103103
});
104+
105+
test("API修正前ロジック: 同じクエリパラメータが 2 回以上指定されていてもそのまま処理できる", () => {
106+
const currentQuery = {
107+
note_status: ["CURRENTLY_RATED_HELPFUL", "NEEDS_MORE_RATINGS"],
108+
limit: 10,
109+
offset: 10,
110+
} satisfies z.infer<typeof noteSearchParamSchema>;
111+
112+
const currentBrokenMeta = {
113+
// API が note_status を複数回指定した際、最後のもの以外を削除してしまう挙動を再現
114+
next: "https://example.com/api/v1/data/search?note_status=NEEDS_MORE_RATINGS&limit=10&offset=20",
115+
prev: "https://example.com/api/v1/data/search?note_status=NEEDS_MORE_RATINGS&limit=10&offset=0",
116+
} satisfies PaginationMeta;
117+
118+
const fixedMeta = buildPaginationMeta(currentBrokenMeta, currentQuery);
119+
const prevQuery = fixedMeta.prev ? getQuery(fixedMeta.prev) : null;
120+
const nextQuery = fixedMeta.next ? getQuery(fixedMeta.next) : null;
121+
122+
expect(prevQuery).toStrictEqual({
123+
note_status: ["CURRENTLY_RATED_HELPFUL", "NEEDS_MORE_RATINGS"],
124+
limit: "10",
125+
offset: "0",
126+
});
127+
expect(nextQuery).toStrictEqual({
128+
note_status: ["CURRENTLY_RATED_HELPFUL", "NEEDS_MORE_RATINGS"],
129+
limit: "10",
130+
offset: "20",
131+
});
132+
});
104133
});

0 commit comments

Comments
 (0)