Просмотр исходного кода

Remove redundant null check for pagePath

arvid-e 2 месяцев назад
Родитель
Сommit
8eb58b1d14

+ 5 - 6
packages/remark-lsx/src/server/routes/list-pages/index.spec.ts

@@ -43,20 +43,19 @@ describe('listPages', () => {
   it("returns 400 HTTP response when the query 'pagePath' is undefined", async () => {
     // setup
     const reqMock = mock<IListPagesRequest>();
-    // Ensure req.query exists even if pagePath doesn't
-    reqMock.query = {} as any;
+    reqMock.query = { pagePath: '' };
 
     const resMock = mock<Response>();
     const resStatusMock = mock<Response>();
     resMock.status.mockReturnValue(resStatusMock);
-    // Mock generateBaseQuery to return a dummy builder so it doesn't crash on .query
-    mocks.generateBaseQueryMock.mockResolvedValue({ query: {} });
 
-    // when
+    mocks.generateBaseQueryMock.mockRejectedValue(
+      createError(400, 'pagePath is required'),
+    );
+
     const handler = listPages({ excludedPaths: [] });
     await handler(reqMock, resMock);
 
-    // then
     expect(resMock.status).toHaveBeenCalledWith(400);
   });
 

+ 0 - 4
packages/remark-lsx/src/server/routes/list-pages/index.ts

@@ -77,10 +77,6 @@ export const listPages = ({ excludedPaths }: { excludedPaths: string[] }) => {
 
     const { pagePath, offset, limit, options } = params;
 
-    if (pagePath == null || pagePath === '') {
-      return res.status(400).send("the 'pagepath' query must not be null.");
-    }
-
     // count viewers of `/`
     let toppageViewersCount: number;
     try {