@@ -82,4 +82,52 @@ describe("buildPaginationMeta", () => {
82
82
83
83
expect ( prevQuery ) . toBe ( null ) ;
84
84
} ) ;
85
+
86
+ test ( "API 修正前ロジック: 次のページが存在しない場合に next が null になる" , ( ) => {
87
+ const currentQuery = {
88
+ post_includes_text : "地震" ,
89
+ limit : 10 ,
90
+ offset : 10 ,
91
+ } satisfies z . infer < typeof noteSearchParamSchema > ;
92
+
93
+ // API が limit, offset 以外のクエリパラメータを削除してしまう挙動を再現
94
+ const currentBrokenMeta = {
95
+ next : null ,
96
+ prev : "https://example.com/api/v1/data/search?offset=0&limit=10" ,
97
+ } satisfies PaginationMeta ;
98
+
99
+ const fixedMeta = buildPaginationMeta ( currentBrokenMeta , currentQuery ) ;
100
+ const nextQuery = fixedMeta . next ? getQuery ( fixedMeta . next ) : null ;
101
+
102
+ expect ( nextQuery ) . toBe ( null ) ;
103
+ } ) ;
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
+ } ) ;
85
133
} ) ;
0 commit comments