Yuki Takei 2 лет назад
Родитель
Сommit
98d68056ba
1 измененных файлов с 30 добавлено и 0 удалено
  1. 30 0
      packages/remark-lsx/src/server/routes/list-pages/add-depth-condition.spec.ts

+ 30 - 0
packages/remark-lsx/src/server/routes/list-pages/add-depth-condition.spec.ts

@@ -1,8 +1,20 @@
+import type { ParseRangeResult } from '@growi/core';
 import { mock } from 'vitest-mock-extended';
 import { mock } from 'vitest-mock-extended';
 
 
 import { addDepthCondition } from './add-depth-condition';
 import { addDepthCondition } from './add-depth-condition';
 import type { PageQuery } from './generate-base-query';
 import type { PageQuery } from './generate-base-query';
 
 
+
+// mocking modules
+const mocks = vi.hoisted(() => {
+  return {
+    getDepthOfPathMock: vi.fn(),
+  };
+});
+
+vi.mock('../../../utils/depth-utils', () => ({ getDepthOfPath: mocks.getDepthOfPathMock }));
+
+
 describe('addDepthCondition()', () => {
 describe('addDepthCondition()', () => {
 
 
   it('returns query as-is', () => {
   it('returns query as-is', () => {
@@ -16,4 +28,22 @@ describe('addDepthCondition()', () => {
     expect(result).toEqual(query);
     expect(result).toEqual(query);
   });
   });
 
 
+  describe('throws http-errors instance', () => {
+
+    it('when the start is smaller than 1', () => {
+      // setup
+      const query = mock<PageQuery>();
+      const depthRange = mock<ParseRangeResult>();
+      depthRange.start = -1;
+      depthRange.end = 10;
+
+      // when
+      const caller = () => addDepthCondition(query, '/', depthRange);
+
+      // then
+      expect(caller).toThrowError(new Error("The specified option 'depth' is { start: -1, end: 10 } : the start must be larger or equal than 1"));
+      expect(mocks.getDepthOfPathMock).not.toHaveBeenCalled();
+    });
+
+  });
 });
 });