reiji-h 1 год назад
Родитель
Сommit
7584dbbb47
1 измененных файлов с 8 добавлено и 5 удалено
  1. 8 5
      packages/remark-lsx/src/server/routes/list-pages/index.spec.ts

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

@@ -3,12 +3,15 @@ import type { Request, Response } from 'express';
 import createError from 'http-errors';
 import createError from 'http-errors';
 import { mock } from 'vitest-mock-extended';
 import { mock } from 'vitest-mock-extended';
 
 
-import type { LsxApiResponseData } from '../../../interfaces/api';
+import type { LsxApiResponseData, LsxApiParams } from '../../../interfaces/api';
 
 
 import type { PageQuery, PageQueryBuilder } from './generate-base-query';
 import type { PageQuery, PageQueryBuilder } from './generate-base-query';
 
 
 import { listPages } from '.';
 import { listPages } from '.';
 
 
+interface listPagesRequest extends Request<undefined, undefined, undefined, LsxApiParams> {
+  user: IUser,
+}
 
 
 // mocking modules
 // mocking modules
 const mocks = vi.hoisted(() => {
 const mocks = vi.hoisted(() => {
@@ -30,7 +33,7 @@ describe('listPages', () => {
 
 
   it("returns 400 HTTP response when the query 'pagePath' is undefined", async() => {
   it("returns 400 HTTP response when the query 'pagePath' is undefined", async() => {
     // setup
     // setup
-    const reqMock = mock<Request & { user: IUser }>();
+    const reqMock = mock<listPagesRequest>();
     const resMock = mock<Response>();
     const resMock = mock<Response>();
     const resStatusMock = mock<Response>();
     const resStatusMock = mock<Response>();
     resMock.status.calledWith(400).mockReturnValue(resStatusMock);
     resMock.status.calledWith(400).mockReturnValue(resStatusMock);
@@ -46,7 +49,7 @@ describe('listPages', () => {
 
 
   describe('with num option', () => {
   describe('with num option', () => {
 
 
-    const reqMock = mock<Request & { user: IUser }>();
+    const reqMock = mock<listPagesRequest>();
     reqMock.query = { pagePath: '/Sandbox' };
     reqMock.query = { pagePath: '/Sandbox' };
 
 
     const builderMock = mock<PageQueryBuilder>();
     const builderMock = mock<PageQueryBuilder>();
@@ -97,7 +100,7 @@ describe('listPages', () => {
 
 
     it('returns 500 HTTP response when an unexpected error occured', async() => {
     it('returns 500 HTTP response when an unexpected error occured', async() => {
       // setup
       // setup
-      const reqMock = mock<Request & { user: IUser }>();
+      const reqMock = mock<listPagesRequest>();
       reqMock.query = { pagePath: '/Sandbox' };
       reqMock.query = { pagePath: '/Sandbox' };
 
 
       // an Error instance will be thrown by addNumConditionMock
       // an Error instance will be thrown by addNumConditionMock
@@ -124,7 +127,7 @@ describe('listPages', () => {
 
 
     it('returns 400 HTTP response when the value is invalid', async() => {
     it('returns 400 HTTP response when the value is invalid', async() => {
       // setup
       // setup
-      const reqMock = mock<Request & { user: IUser }>();
+      const reqMock = mock<listPagesRequest>();
       reqMock.query = { pagePath: '/Sandbox' };
       reqMock.query = { pagePath: '/Sandbox' };
 
 
       // an http-errors instance will be thrown by addNumConditionMock
       // an http-errors instance will be thrown by addNumConditionMock