@mx-space/api-client 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/esm/adaptors/axios.d.ts +4 -0
- package/esm/adaptors/axios.js +37 -0
- package/esm/adaptors/axios.js.map +1 -0
- package/esm/adaptors/ky.d.ts +23 -0
- package/esm/adaptors/ky.js +62 -0
- package/esm/adaptors/ky.js.map +1 -0
- package/esm/adaptors/umi-request.d.ts +4 -0
- package/esm/adaptors/umi-request.js +31 -0
- package/esm/adaptors/umi-request.js.map +1 -0
- package/esm/controllers/aggregate.d.ts +64 -0
- package/esm/controllers/aggregate.js +42 -0
- package/esm/controllers/aggregate.js.map +1 -0
- package/esm/controllers/base.d.ts +43 -0
- package/esm/controllers/base.js +27 -0
- package/esm/controllers/base.js.map +1 -0
- package/esm/controllers/category.d.ts +114 -0
- package/esm/controllers/category.js +68 -0
- package/esm/controllers/category.js.map +1 -0
- package/esm/controllers/comment.d.ts +81 -0
- package/esm/controllers/comment.js +47 -0
- package/esm/controllers/comment.js.map +1 -0
- package/esm/controllers/index.d.ts +18 -0
- package/esm/controllers/index.js +55 -0
- package/esm/controllers/index.js.map +1 -0
- package/esm/controllers/link.d.ts +20 -0
- package/esm/controllers/link.js +21 -0
- package/esm/controllers/link.js.map +1 -0
- package/esm/controllers/note.d.ts +123 -0
- package/esm/controllers/note.js +68 -0
- package/esm/controllers/note.js.map +1 -0
- package/esm/controllers/page.d.ts +59 -0
- package/esm/controllers/page.js +42 -0
- package/esm/controllers/page.js.map +1 -0
- package/esm/controllers/post.d.ts +72 -0
- package/esm/controllers/post.js +52 -0
- package/esm/controllers/post.js.map +1 -0
- package/esm/controllers/project.d.ts +15 -0
- package/esm/controllers/project.js +12 -0
- package/esm/controllers/project.js.map +1 -0
- package/esm/controllers/recently.d.ts +61 -0
- package/esm/controllers/recently.js +31 -0
- package/esm/controllers/recently.js.map +1 -0
- package/esm/controllers/say.d.ts +37 -0
- package/esm/controllers/say.js +21 -0
- package/esm/controllers/say.js.map +1 -0
- package/esm/controllers/search.d.ts +247 -0
- package/esm/controllers/search.js +28 -0
- package/esm/controllers/search.js.map +1 -0
- package/esm/controllers/severless.d.ts +24 -0
- package/esm/controllers/severless.js +16 -0
- package/esm/controllers/severless.js.map +1 -0
- package/esm/controllers/snippet.d.ts +24 -0
- package/esm/controllers/snippet.js +19 -0
- package/esm/controllers/snippet.js.map +1 -0
- package/esm/controllers/topic.d.ts +26 -0
- package/esm/controllers/topic.js +18 -0
- package/esm/controllers/topic.js.map +1 -0
- package/esm/controllers/user.d.ts +70 -0
- package/esm/controllers/user.js +40 -0
- package/esm/controllers/user.js.map +1 -0
- package/esm/core/attach-request.d.ts +2 -0
- package/esm/core/attach-request.js +36 -0
- package/esm/core/attach-request.js.map +1 -0
- package/esm/core/client.d.ts +29 -0
- package/esm/core/client.js +186 -0
- package/esm/core/client.js.map +1 -0
- package/esm/core/error.d.ts +6 -0
- package/esm/core/error.js +9 -0
- package/esm/core/error.js.map +1 -0
- package/esm/core/index.d.ts +2 -0
- package/esm/core/index.js +3 -0
- package/esm/core/index.js.map +1 -0
- package/esm/dtos/comment.d.ts +6 -0
- package/esm/dtos/comment.js +3 -0
- package/esm/dtos/comment.js.map +1 -0
- package/esm/index.d.ts +7 -0
- package/esm/index.js +8 -0
- package/esm/index.js.map +1 -0
- package/esm/interfaces/adapter.d.ts +14 -0
- package/esm/interfaces/adapter.js +2 -0
- package/esm/interfaces/adapter.js.map +1 -0
- package/esm/interfaces/client.d.ts +13 -0
- package/esm/interfaces/client.js +2 -0
- package/esm/interfaces/client.js.map +1 -0
- package/esm/interfaces/controller.d.ts +4 -0
- package/esm/interfaces/controller.js +2 -0
- package/esm/interfaces/controller.js.map +1 -0
- package/esm/interfaces/instance.d.ts +7 -0
- package/esm/interfaces/instance.js +2 -0
- package/esm/interfaces/instance.js.map +1 -0
- package/esm/interfaces/options.d.ts +1 -0
- package/esm/interfaces/options.js +2 -0
- package/esm/interfaces/options.js.map +1 -0
- package/esm/interfaces/params.d.ts +4 -0
- package/esm/interfaces/params.js +2 -0
- package/esm/interfaces/params.js.map +1 -0
- package/esm/interfaces/request.d.ts +43 -0
- package/esm/interfaces/request.js +2 -0
- package/esm/interfaces/request.js.map +1 -0
- package/esm/interfaces/types.d.ts +2 -0
- package/esm/interfaces/types.js +2 -0
- package/esm/interfaces/types.js.map +1 -0
- package/esm/models/aggregate.d.ts +53 -0
- package/esm/models/aggregate.js +6 -0
- package/esm/models/aggregate.js.map +1 -0
- package/esm/models/base.d.ts +41 -0
- package/esm/models/base.js +2 -0
- package/esm/models/base.js.map +1 -0
- package/esm/models/category.d.ts +22 -0
- package/esm/models/category.js +6 -0
- package/esm/models/category.js.map +1 -0
- package/esm/models/comment.d.ts +37 -0
- package/esm/models/comment.js +13 -0
- package/esm/models/comment.js.map +1 -0
- package/esm/models/index.d.ts +14 -0
- package/esm/models/index.js +15 -0
- package/esm/models/index.js.map +1 -0
- package/esm/models/link.d.ts +22 -0
- package/esm/models/link.js +14 -0
- package/esm/models/link.js.map +1 -0
- package/esm/models/note.d.ts +38 -0
- package/esm/models/note.js +2 -0
- package/esm/models/note.js.map +1 -0
- package/esm/models/page.d.ts +14 -0
- package/esm/models/page.js +7 -0
- package/esm/models/page.js.map +1 -0
- package/esm/models/post.d.ts +17 -0
- package/esm/models/post.js +2 -0
- package/esm/models/post.js.map +1 -0
- package/esm/models/project.d.ts +11 -0
- package/esm/models/project.js +2 -0
- package/esm/models/project.js.map +1 -0
- package/esm/models/recently.d.ts +20 -0
- package/esm/models/recently.js +7 -0
- package/esm/models/recently.js.map +1 -0
- package/esm/models/say.d.ts +6 -0
- package/esm/models/say.js +2 -0
- package/esm/models/say.js.map +1 -0
- package/esm/models/setting.d.ts +66 -0
- package/esm/models/setting.js +2 -0
- package/esm/models/setting.js.map +1 -0
- package/esm/models/snippet.d.ts +18 -0
- package/esm/models/snippet.js +8 -0
- package/esm/models/snippet.js.map +1 -0
- package/esm/models/topic.d.ts +8 -0
- package/esm/models/topic.js +2 -0
- package/esm/models/topic.js.map +1 -0
- package/esm/models/user.d.ts +21 -0
- package/esm/models/user.js +2 -0
- package/esm/models/user.js.map +1 -0
- package/esm/utils/auto-bind.d.ts +4 -0
- package/esm/utils/auto-bind.js +36 -0
- package/esm/utils/auto-bind.js.map +1 -0
- package/esm/utils/camelcase-keys.d.ts +6 -0
- package/esm/utils/camelcase-keys.js +23 -0
- package/esm/utils/camelcase-keys.js.map +1 -0
- package/esm/utils/index.d.ts +5 -0
- package/esm/utils/index.js +43 -0
- package/esm/utils/index.js.map +1 -0
- package/esm/utils/path.d.ts +1 -0
- package/esm/utils/path.js +7 -0
- package/esm/utils/path.js.map +1 -0
- package/esm/vitest.config.d.ts +2 -0
- package/esm/vitest.config.js +12 -0
- package/esm/vitest.config.js.map +1 -0
- package/lib/adaptors/axios.d.ts +4 -0
- package/lib/adaptors/axios.js +43 -0
- package/lib/adaptors/axios.js.map +1 -0
- package/lib/adaptors/ky.d.ts +23 -0
- package/lib/adaptors/ky.js +69 -0
- package/lib/adaptors/ky.js.map +1 -0
- package/lib/adaptors/umi-request.d.ts +4 -0
- package/lib/adaptors/umi-request.js +34 -0
- package/lib/adaptors/umi-request.js.map +1 -0
- package/lib/controllers/aggregate.d.ts +64 -0
- package/lib/controllers/aggregate.js +46 -0
- package/lib/controllers/aggregate.js.map +1 -0
- package/lib/controllers/base.d.ts +43 -0
- package/lib/controllers/base.js +31 -0
- package/lib/controllers/base.js.map +1 -0
- package/lib/controllers/category.d.ts +114 -0
- package/lib/controllers/category.js +72 -0
- package/lib/controllers/category.js.map +1 -0
- package/lib/controllers/comment.d.ts +81 -0
- package/lib/controllers/comment.js +51 -0
- package/lib/controllers/comment.js.map +1 -0
- package/lib/controllers/index.d.ts +18 -0
- package/lib/controllers/index.js +72 -0
- package/lib/controllers/index.js.map +1 -0
- package/lib/controllers/link.d.ts +20 -0
- package/lib/controllers/link.js +25 -0
- package/lib/controllers/link.js.map +1 -0
- package/lib/controllers/note.d.ts +123 -0
- package/lib/controllers/note.js +72 -0
- package/lib/controllers/note.js.map +1 -0
- package/lib/controllers/page.d.ts +59 -0
- package/lib/controllers/page.js +46 -0
- package/lib/controllers/page.js.map +1 -0
- package/lib/controllers/post.d.ts +72 -0
- package/lib/controllers/post.js +56 -0
- package/lib/controllers/post.js.map +1 -0
- package/lib/controllers/project.d.ts +15 -0
- package/lib/controllers/project.js +16 -0
- package/lib/controllers/project.js.map +1 -0
- package/lib/controllers/recently.d.ts +61 -0
- package/lib/controllers/recently.js +35 -0
- package/lib/controllers/recently.js.map +1 -0
- package/lib/controllers/say.d.ts +37 -0
- package/lib/controllers/say.js +25 -0
- package/lib/controllers/say.js.map +1 -0
- package/lib/controllers/search.d.ts +247 -0
- package/lib/controllers/search.js +32 -0
- package/lib/controllers/search.js.map +1 -0
- package/lib/controllers/severless.d.ts +24 -0
- package/lib/controllers/severless.js +20 -0
- package/lib/controllers/severless.js.map +1 -0
- package/lib/controllers/snippet.d.ts +24 -0
- package/lib/controllers/snippet.js +23 -0
- package/lib/controllers/snippet.js.map +1 -0
- package/lib/controllers/topic.d.ts +26 -0
- package/lib/controllers/topic.js +22 -0
- package/lib/controllers/topic.js.map +1 -0
- package/lib/controllers/user.d.ts +70 -0
- package/lib/controllers/user.js +44 -0
- package/lib/controllers/user.js.map +1 -0
- package/lib/core/attach-request.d.ts +2 -0
- package/lib/core/attach-request.js +40 -0
- package/lib/core/attach-request.js.map +1 -0
- package/lib/core/client.d.ts +29 -0
- package/lib/core/client.js +190 -0
- package/lib/core/client.js.map +1 -0
- package/lib/core/error.d.ts +6 -0
- package/lib/core/error.js +13 -0
- package/lib/core/error.js.map +1 -0
- package/lib/core/index.d.ts +2 -0
- package/lib/core/index.js +19 -0
- package/lib/core/index.js.map +1 -0
- package/lib/dtos/comment.d.ts +6 -0
- package/lib/dtos/comment.js +7 -0
- package/lib/dtos/comment.js.map +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +28 -0
- package/lib/index.js.map +1 -0
- package/lib/interfaces/adapter.d.ts +14 -0
- package/lib/interfaces/adapter.js +3 -0
- package/lib/interfaces/adapter.js.map +1 -0
- package/lib/interfaces/client.d.ts +13 -0
- package/lib/interfaces/client.js +3 -0
- package/lib/interfaces/client.js.map +1 -0
- package/lib/interfaces/controller.d.ts +4 -0
- package/lib/interfaces/controller.js +3 -0
- package/lib/interfaces/controller.js.map +1 -0
- package/lib/interfaces/instance.d.ts +7 -0
- package/lib/interfaces/instance.js +3 -0
- package/lib/interfaces/instance.js.map +1 -0
- package/lib/interfaces/options.d.ts +1 -0
- package/lib/interfaces/options.js +3 -0
- package/lib/interfaces/options.js.map +1 -0
- package/lib/interfaces/params.d.ts +4 -0
- package/lib/interfaces/params.js +3 -0
- package/lib/interfaces/params.js.map +1 -0
- package/lib/interfaces/request.d.ts +43 -0
- package/lib/interfaces/request.js +3 -0
- package/lib/interfaces/request.js.map +1 -0
- package/lib/interfaces/types.d.ts +2 -0
- package/lib/interfaces/types.js +3 -0
- package/lib/interfaces/types.js.map +1 -0
- package/lib/models/aggregate.d.ts +53 -0
- package/lib/models/aggregate.js +9 -0
- package/lib/models/aggregate.js.map +1 -0
- package/lib/models/base.d.ts +41 -0
- package/lib/models/base.js +3 -0
- package/lib/models/base.js.map +1 -0
- package/lib/models/category.d.ts +22 -0
- package/lib/models/category.js +9 -0
- package/lib/models/category.js.map +1 -0
- package/lib/models/comment.d.ts +37 -0
- package/lib/models/comment.js +16 -0
- package/lib/models/comment.js.map +1 -0
- package/lib/models/index.d.ts +14 -0
- package/lib/models/index.js +31 -0
- package/lib/models/index.js.map +1 -0
- package/lib/models/link.d.ts +22 -0
- package/lib/models/link.js +17 -0
- package/lib/models/link.js.map +1 -0
- package/lib/models/note.d.ts +38 -0
- package/lib/models/note.js +3 -0
- package/lib/models/note.js.map +1 -0
- package/lib/models/page.d.ts +14 -0
- package/lib/models/page.js +10 -0
- package/lib/models/page.js.map +1 -0
- package/lib/models/post.d.ts +17 -0
- package/lib/models/post.js +3 -0
- package/lib/models/post.js.map +1 -0
- package/lib/models/project.d.ts +11 -0
- package/lib/models/project.js +3 -0
- package/lib/models/project.js.map +1 -0
- package/lib/models/recently.d.ts +20 -0
- package/lib/models/recently.js +10 -0
- package/lib/models/recently.js.map +1 -0
- package/lib/models/say.d.ts +6 -0
- package/lib/models/say.js +3 -0
- package/lib/models/say.js.map +1 -0
- package/lib/models/setting.d.ts +66 -0
- package/lib/models/setting.js +3 -0
- package/lib/models/setting.js.map +1 -0
- package/lib/models/snippet.d.ts +18 -0
- package/lib/models/snippet.js +11 -0
- package/lib/models/snippet.js.map +1 -0
- package/lib/models/topic.d.ts +8 -0
- package/lib/models/topic.js +3 -0
- package/lib/models/topic.js.map +1 -0
- package/lib/models/user.d.ts +21 -0
- package/lib/models/user.js +3 -0
- package/lib/models/user.js.map +1 -0
- package/lib/utils/auto-bind.d.ts +4 -0
- package/lib/utils/auto-bind.js +40 -0
- package/lib/utils/auto-bind.js.map +1 -0
- package/lib/utils/camelcase-keys.d.ts +6 -0
- package/lib/utils/camelcase-keys.js +28 -0
- package/lib/utils/camelcase-keys.js.map +1 -0
- package/lib/utils/index.d.ts +5 -0
- package/lib/utils/index.js +50 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/path.d.ts +1 -0
- package/lib/utils/path.js +11 -0
- package/lib/utils/path.js.map +1 -0
- package/lib/vitest.config.d.ts +2 -0
- package/lib/vitest.config.js +17 -0
- package/lib/vitest.config.js.map +1 -0
- package/package.json +25 -12
- package/types/adaptors/axios.d.ts +4 -0
- package/types/adaptors/ky.d.ts +23 -0
- package/types/adaptors/umi-request.d.ts +4 -0
- package/types/controllers/aggregate.d.ts +64 -0
- package/types/controllers/base.d.ts +43 -0
- package/types/controllers/category.d.ts +114 -0
- package/types/controllers/comment.d.ts +81 -0
- package/types/controllers/index.d.ts +18 -0
- package/types/controllers/link.d.ts +20 -0
- package/types/controllers/note.d.ts +123 -0
- package/types/controllers/page.d.ts +59 -0
- package/types/controllers/post.d.ts +72 -0
- package/types/controllers/project.d.ts +15 -0
- package/types/controllers/recently.d.ts +61 -0
- package/types/controllers/say.d.ts +37 -0
- package/types/controllers/search.d.ts +247 -0
- package/types/controllers/severless.d.ts +24 -0
- package/types/controllers/snippet.d.ts +24 -0
- package/types/controllers/topic.d.ts +26 -0
- package/types/controllers/user.d.ts +70 -0
- package/types/core/attach-request.d.ts +2 -0
- package/types/core/client.d.ts +29 -0
- package/types/core/error.d.ts +6 -0
- package/types/core/index.d.ts +2 -0
- package/types/dtos/comment.d.ts +6 -0
- package/types/index.d.ts +7 -0
- package/types/interfaces/adapter.d.ts +14 -0
- package/types/interfaces/client.d.ts +13 -0
- package/types/interfaces/controller.d.ts +4 -0
- package/types/interfaces/instance.d.ts +7 -0
- package/types/interfaces/options.d.ts +1 -0
- package/types/interfaces/params.d.ts +4 -0
- package/types/interfaces/request.d.ts +43 -0
- package/types/interfaces/types.d.ts +2 -0
- package/types/models/aggregate.d.ts +53 -0
- package/types/models/base.d.ts +41 -0
- package/types/models/category.d.ts +22 -0
- package/types/models/comment.d.ts +37 -0
- package/types/models/index.d.ts +14 -0
- package/types/models/link.d.ts +22 -0
- package/types/models/note.d.ts +38 -0
- package/types/models/page.d.ts +14 -0
- package/types/models/post.d.ts +17 -0
- package/types/models/project.d.ts +11 -0
- package/types/models/recently.d.ts +20 -0
- package/types/models/say.d.ts +6 -0
- package/types/models/setting.d.ts +66 -0
- package/types/models/snippet.d.ts +18 -0
- package/types/models/topic.d.ts +8 -0
- package/types/models/user.d.ts +21 -0
- package/types/utils/auto-bind.d.ts +4 -0
- package/types/utils/camelcase-keys.d.ts +6 -0
- package/types/utils/index.d.ts +5 -0
- package/types/utils/path.d.ts +1 -0
- package/types/vitest.config.d.ts +2 -0
- package/__tests__/adaptors/axios.spec.ts +0 -7
- package/__tests__/adaptors/ky.spec.ts +0 -9
- package/__tests__/adaptors/umi-request.spec.ts +0 -7
- package/__tests__/contronllers/aggregate.test.ts +0 -389
- package/__tests__/contronllers/category.test.ts +0 -284
- package/__tests__/contronllers/comment.test.ts +0 -113
- package/__tests__/contronllers/link.test.ts +0 -95
- package/__tests__/contronllers/note.test.ts +0 -120
- package/__tests__/contronllers/page.test.ts +0 -49
- package/__tests__/contronllers/post.test.ts +0 -77
- package/__tests__/contronllers/recently.test.ts +0 -49
- package/__tests__/contronllers/say.test.ts +0 -106
- package/__tests__/contronllers/search.test.ts +0 -81
- package/__tests__/contronllers/serverless.test.ts +0 -19
- package/__tests__/contronllers/snippet.test.ts +0 -38
- package/__tests__/contronllers/topic.test.ts +0 -17
- package/__tests__/contronllers/user.test.ts +0 -59
- package/__tests__/core/client.test.ts +0 -293
- package/__tests__/helpers/adaptor-test.ts +0 -108
- package/__tests__/helpers/e2e-mock-server.ts +0 -22
- package/__tests__/helpers/global-fetch.ts +0 -39
- package/__tests__/helpers/instance.ts +0 -11
- package/__tests__/helpers/response.ts +0 -76
- package/__tests__/mock/algolia.json +0 -446
- package/__tests__/utils/auto-bind.spec.ts +0 -27
- package/__tests__/utils/camelcase-keys.spec.ts +0 -86
- package/__tests__/utils/index.test.ts +0 -33
- package/__tests__/utils/path.spec.ts +0 -8
- package/adaptors/axios.ts +0 -44
- package/adaptors/ky.ts +0 -76
- package/adaptors/umi-request.ts +0 -38
- package/core/attach-request.ts +0 -43
- package/core/client.ts +0 -252
- package/core/error.ts +0 -10
- package/core/index.ts +0 -2
- package/coverage/lcov-report/__tests__/helpers/adaptor-test.ts.html +0 -405
- package/coverage/lcov-report/__tests__/helpers/e2e-mock-server.ts.html +0 -150
- package/coverage/lcov-report/__tests__/helpers/index.html +0 -236
- package/coverage/lcov-report/__tests__/helpers/instance.ts.html +0 -120
- package/coverage/lcov-report/__tests__/helpers/response.ts.html +0 -231
- package/rollup.config.js +0 -150
- package/utils/auto-bind.ts +0 -48
- package/utils/camelcase-keys.ts +0 -26
- package/utils/index.ts +0 -53
- package/utils/path.ts +0 -6
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { mockRequestInstance } from '~/__tests__/helpers/instance'
|
|
2
|
-
import { mockResponse } from '~/__tests__/helpers/response'
|
|
3
|
-
import { ServerlessController } from '~/controllers'
|
|
4
|
-
|
|
5
|
-
describe('test Snippet client', () => {
|
|
6
|
-
const client = mockRequestInstance(ServerlessController)
|
|
7
|
-
|
|
8
|
-
test('GET /:reference/:name', async () => {
|
|
9
|
-
const mocked = mockResponse('/serverless/api/ping', { message: 'pong' })
|
|
10
|
-
|
|
11
|
-
const data = await client.serverless.getByReferenceAndName<{}>(
|
|
12
|
-
'api',
|
|
13
|
-
'ping',
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
expect(data).toEqual(mocked)
|
|
17
|
-
expect(data.$raw.data).toEqual(mocked)
|
|
18
|
-
})
|
|
19
|
-
})
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { mockRequestInstance } from '~/__tests__/helpers/instance'
|
|
2
|
-
import { mockResponse } from '~/__tests__/helpers/response'
|
|
3
|
-
import { SnippetController } from '~/controllers'
|
|
4
|
-
|
|
5
|
-
describe('test Snippet client', () => {
|
|
6
|
-
const client = mockRequestInstance(SnippetController)
|
|
7
|
-
|
|
8
|
-
// test('GET /:id', async () => {
|
|
9
|
-
// const mocked = mockResponse('/snippets/61a0cac4b4aefa000fcc1822', {
|
|
10
|
-
// id: '61a0cac4b4aefa000fcc1822',
|
|
11
|
-
// type: 'json',
|
|
12
|
-
// private: true,
|
|
13
|
-
// reference: 'theme',
|
|
14
|
-
// raw: '{}',
|
|
15
|
-
// name: 'config',
|
|
16
|
-
// created: '2021-11-26T11:53:40.863Z',
|
|
17
|
-
// updated: '2021-11-26T11:53:40.863Z',
|
|
18
|
-
// })
|
|
19
|
-
|
|
20
|
-
// const data = await client.snippet.getById('61a0cac4b4aefa000fcc1822')
|
|
21
|
-
|
|
22
|
-
// expect(data).toEqual(mocked)
|
|
23
|
-
// expect(data.$raw.data).toEqual(mocked)
|
|
24
|
-
// expect(data.raw).toEqual('{}')
|
|
25
|
-
// })
|
|
26
|
-
|
|
27
|
-
test('GET /:reference/:name', async () => {
|
|
28
|
-
const mocked = mockResponse('/snippets/theme/config', {})
|
|
29
|
-
|
|
30
|
-
const data = await client.snippet.getByReferenceAndName<{}>(
|
|
31
|
-
'theme',
|
|
32
|
-
'config',
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
expect(data).toEqual(mocked)
|
|
36
|
-
expect(data.$raw.data).toEqual(mocked)
|
|
37
|
-
})
|
|
38
|
-
})
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import camelcaseKeys from 'camelcase-keys'
|
|
2
|
-
|
|
3
|
-
import { mockRequestInstance } from '~/__tests__/helpers/instance'
|
|
4
|
-
import { mockResponse } from '~/__tests__/helpers/response'
|
|
5
|
-
import { TopicController } from '~/controllers/topic'
|
|
6
|
-
|
|
7
|
-
describe('test topic client', () => {
|
|
8
|
-
const client = mockRequestInstance(TopicController)
|
|
9
|
-
|
|
10
|
-
test('GET /topics/slug/:slug', async () => {
|
|
11
|
-
const mocked = mockResponse('/topics/slug/111', {
|
|
12
|
-
name: 'name-topic',
|
|
13
|
-
})
|
|
14
|
-
const data = await client.topic.getTopicBySlug('111')
|
|
15
|
-
expect(data).toEqual(camelcaseKeys(mocked))
|
|
16
|
-
})
|
|
17
|
-
})
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import camelcaseKeys from 'camelcase-keys'
|
|
2
|
-
|
|
3
|
-
import { mockRequestInstance } from '~/__tests__/helpers/instance'
|
|
4
|
-
import { mockResponse } from '~/__tests__/helpers/response'
|
|
5
|
-
import { UserController } from '~/controllers'
|
|
6
|
-
|
|
7
|
-
describe('test user client', () => {
|
|
8
|
-
const client = mockRequestInstance(UserController)
|
|
9
|
-
|
|
10
|
-
test('GET /master', async () => {
|
|
11
|
-
const mocked = mockResponse('/master', {
|
|
12
|
-
id: '5ea4fe632507ba128f4c938c',
|
|
13
|
-
introduce: '这是我的小世界呀',
|
|
14
|
-
mail: 'i@innei.ren',
|
|
15
|
-
url: 'https://innei.ren',
|
|
16
|
-
name: 'Innei',
|
|
17
|
-
social_ids: {
|
|
18
|
-
bili_id: 26578164,
|
|
19
|
-
netease_id: 84302804,
|
|
20
|
-
github: 'Innei',
|
|
21
|
-
},
|
|
22
|
-
username: 'Innei',
|
|
23
|
-
created: '2020-04-26T03:22:11.784Z',
|
|
24
|
-
modified: '2020-11-13T09:38:49.014Z',
|
|
25
|
-
last_login_time: '2021-11-17T13:42:48.209Z',
|
|
26
|
-
avatar: 'https://cdn.innei.ren/avatar.png',
|
|
27
|
-
})
|
|
28
|
-
const data = await client.user.getMasterInfo()
|
|
29
|
-
expect(data.id).toEqual(mocked.id)
|
|
30
|
-
expect(data).toEqual(camelcaseKeys(mocked, { deep: true }))
|
|
31
|
-
expect(data.$raw.data).toEqual(mocked)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test('POST /login', async () => {
|
|
35
|
-
const mocked = mockResponse(
|
|
36
|
-
'/master/login',
|
|
37
|
-
{
|
|
38
|
-
id: '5ea4fe632507ba128f4c938c',
|
|
39
|
-
},
|
|
40
|
-
'post',
|
|
41
|
-
)
|
|
42
|
-
const data = await client.user.login('test', 'test')
|
|
43
|
-
expect(data.id).toEqual(mocked.id)
|
|
44
|
-
expect(data.$raw.data).toEqual(mocked)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test('GET /check_logged', async () => {
|
|
48
|
-
const mocked = mockResponse('/check_logged?token=bearer token', {
|
|
49
|
-
isGuest: true,
|
|
50
|
-
})
|
|
51
|
-
const data = await client.user.checkTokenValid('token')
|
|
52
|
-
expect(data).toEqual(mocked)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('should call `master.xx` work', () => {
|
|
56
|
-
expect(client.master.getMasterInfo).toBeInstanceOf(Function)
|
|
57
|
-
expect(client.master).toEqual(client.user)
|
|
58
|
-
})
|
|
59
|
-
})
|
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
import { AxiosError, AxiosResponse } from 'axios'
|
|
2
|
-
import { vi } from 'vitest'
|
|
3
|
-
|
|
4
|
-
import { axiosAdaptor } from '~/adaptors/axios'
|
|
5
|
-
import { umiAdaptor } from '~/adaptors/umi-request'
|
|
6
|
-
import {
|
|
7
|
-
NoteController,
|
|
8
|
-
PostController,
|
|
9
|
-
allContollerNames,
|
|
10
|
-
allControllers,
|
|
11
|
-
} from '~/controllers'
|
|
12
|
-
import { RequestError, createClient } from '~/core'
|
|
13
|
-
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
14
|
-
import { ClientOptions } from '~/interfaces/client'
|
|
15
|
-
|
|
16
|
-
const { spyOn } = vi
|
|
17
|
-
|
|
18
|
-
// axios wrapper test
|
|
19
|
-
const generateClient = <
|
|
20
|
-
Response = AxiosResponse<unknown>,
|
|
21
|
-
AdaptorType extends IRequestAdapter = typeof axiosAdaptor,
|
|
22
|
-
>(
|
|
23
|
-
adapter?: AdaptorType,
|
|
24
|
-
options?: ClientOptions,
|
|
25
|
-
) =>
|
|
26
|
-
createClient(adapter ?? axiosAdaptor)<Response>(
|
|
27
|
-
'http://127.0.0.1:2323',
|
|
28
|
-
options,
|
|
29
|
-
)
|
|
30
|
-
describe('test client', () => {
|
|
31
|
-
it('should create new client with axios', () => {
|
|
32
|
-
const client = generateClient()
|
|
33
|
-
expect(client).toBeDefined()
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
describe('client `get` method', () => {
|
|
37
|
-
test('case 1', async () => {
|
|
38
|
-
spyOn(axiosAdaptor, 'get').mockImplementation((url) => {
|
|
39
|
-
if (url === 'http://127.0.0.1:2323/a/a?foo=bar') {
|
|
40
|
-
return Promise.resolve({ data: { ok: 1 } })
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return Promise.resolve({ data: null })
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
const client = generateClient()
|
|
47
|
-
const data = await client.proxy.a.a.get({ params: { foo: 'bar' } })
|
|
48
|
-
|
|
49
|
-
expect(data).toStrictEqual({ ok: 1 })
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
test('case 2', async () => {
|
|
53
|
-
spyOn(axiosAdaptor, 'get').mockImplementation((url) => {
|
|
54
|
-
if (url === 'http://127.0.0.1:2323/a/a') {
|
|
55
|
-
return Promise.resolve({ data: { ok: 1 } })
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return Promise.resolve({ data: null })
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
const client = generateClient()
|
|
62
|
-
const data = await client.proxy.a.a.get()
|
|
63
|
-
|
|
64
|
-
expect(data).toStrictEqual({ ok: 1 })
|
|
65
|
-
|
|
66
|
-
{
|
|
67
|
-
spyOn(axiosAdaptor, 'get').mockImplementation((url) => {
|
|
68
|
-
if (url === 'http://127.0.0.1:2323/a/b') {
|
|
69
|
-
return Promise.resolve({ data: { ok: 1 } })
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return Promise.resolve({ data: null })
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
const client = generateClient()
|
|
76
|
-
const data = await client.proxy.a.b.get()
|
|
77
|
-
|
|
78
|
-
expect(data).toStrictEqual({ ok: 1 })
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('should throw error if not inject other client', () => {
|
|
84
|
-
const client = generateClient()
|
|
85
|
-
allContollerNames.forEach((name) => {
|
|
86
|
-
expect(() => (client as any)[name].name).toThrow(
|
|
87
|
-
`${
|
|
88
|
-
name.charAt(0).toUpperCase() + name.slice(1)
|
|
89
|
-
} Client not inject yet, please inject with client.injectClients(...)`,
|
|
90
|
-
)
|
|
91
|
-
})
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('should work if inject client', () => {
|
|
95
|
-
const client = generateClient()
|
|
96
|
-
|
|
97
|
-
client.injectControllers(allControllers)
|
|
98
|
-
allContollerNames.forEach((name) => {
|
|
99
|
-
expect(() => (client as any)[name].name).toBeDefined()
|
|
100
|
-
})
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('should inject single client worked', () => {
|
|
104
|
-
const client = generateClient()
|
|
105
|
-
|
|
106
|
-
client.injectControllers(PostController)
|
|
107
|
-
expect(client.post.name).toBeDefined()
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
it('should inject multi client worked', () => {
|
|
111
|
-
const client = generateClient()
|
|
112
|
-
|
|
113
|
-
client.injectControllers(PostController, NoteController)
|
|
114
|
-
expect(client.post.name).toBeDefined()
|
|
115
|
-
expect(client.note.name).toBeDefined()
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('should inject controller when init', () => {
|
|
119
|
-
const client = createClient(axiosAdaptor)('http://127.0.0.1:2323', {
|
|
120
|
-
controllers: [PostController, NoteController],
|
|
121
|
-
})
|
|
122
|
-
expect(client.post.name).toBeDefined()
|
|
123
|
-
expect(client.note.name).toBeDefined()
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
it('should infer response wrapper type', async () => {
|
|
127
|
-
const client = generateClient<AxiosResponse>(axiosAdaptor)
|
|
128
|
-
client.injectControllers(PostController)
|
|
129
|
-
spyOn(axiosAdaptor, 'get').mockImplementation((url) => {
|
|
130
|
-
if (url === 'http://127.0.0.1:2323/posts/latest') {
|
|
131
|
-
return Promise.resolve({ data: { ok: 1 }, status: 200 })
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return Promise.resolve({ data: null })
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
const data = await client.post.getLatest()
|
|
138
|
-
|
|
139
|
-
expect(data.$raw.status).toBe(200)
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
it('should infer axios instance type', async () => {
|
|
143
|
-
const client = generateClient<AxiosResponse>(axiosAdaptor)
|
|
144
|
-
spyOn(axiosAdaptor, 'get').mockImplementation((url) => {
|
|
145
|
-
if (url === 'http://127.0.0.1:2323/a') {
|
|
146
|
-
return Promise.resolve({ data: { ok: 1 }, status: 200 })
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return Promise.resolve({ data: null })
|
|
150
|
-
})
|
|
151
|
-
expect(client.instance.default).toBe(axiosAdaptor.default)
|
|
152
|
-
const res = await client.proxy.a.get()
|
|
153
|
-
expect(res.$raw.status).toBe(200)
|
|
154
|
-
|
|
155
|
-
{
|
|
156
|
-
spyOn(umiAdaptor, 'get').mockImplementation((url) => {
|
|
157
|
-
if (url === 'http://127.0.0.1:2323/a') {
|
|
158
|
-
return Promise.resolve({
|
|
159
|
-
data: { ok: 1 },
|
|
160
|
-
response: { status: 200, body: {} },
|
|
161
|
-
})
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return Promise.resolve({ data: null })
|
|
165
|
-
})
|
|
166
|
-
const client2 = createClient(umiAdaptor)('http://127.0.0.1:2323')
|
|
167
|
-
expect(client2.instance.default).toBe(umiAdaptor.default)
|
|
168
|
-
const res = await client2.proxy.a.get()
|
|
169
|
-
expect(res.$raw.response.status).toBe(200)
|
|
170
|
-
expect(res.$raw.response.body).toStrictEqual({})
|
|
171
|
-
}
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
it('should resolve joint path call toString()', () => {
|
|
175
|
-
const client = generateClient()
|
|
176
|
-
{
|
|
177
|
-
const path = client.proxy.foo.bar.toString()
|
|
178
|
-
expect(path).toBe('/foo/bar')
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
{
|
|
182
|
-
const path = client.proxy.foo.bar.toString(true)
|
|
183
|
-
expect(path).toBe('http://127.0.0.1:2323/foo/bar')
|
|
184
|
-
}
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
it('should do not json convert case if payload is string or other primitive type', async () => {
|
|
188
|
-
const client = generateClient<AxiosResponse>(axiosAdaptor)
|
|
189
|
-
spyOn(axiosAdaptor, 'get').mockImplementation((url) => {
|
|
190
|
-
if (url === 'http://127.0.0.1:2323/a') {
|
|
191
|
-
return Promise.resolve({ data: 'foo', status: 200 })
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return Promise.resolve({ data: null })
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
const data = await client.proxy.a.get()
|
|
198
|
-
expect(data).toBe('foo')
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
it('should throw exception with custom message and code', async () => {
|
|
202
|
-
const client = generateClient<AxiosResponse>(axiosAdaptor, {
|
|
203
|
-
// @ts-ignore
|
|
204
|
-
getCodeMessageFromException: (e: AxiosError) => {
|
|
205
|
-
return {
|
|
206
|
-
code: e.response?.status,
|
|
207
|
-
message: e.message,
|
|
208
|
-
}
|
|
209
|
-
},
|
|
210
|
-
})
|
|
211
|
-
spyOn(axiosAdaptor, 'get').mockImplementation(() => {
|
|
212
|
-
return Promise.reject(
|
|
213
|
-
new AxiosError(
|
|
214
|
-
'not found',
|
|
215
|
-
'NOT_FOUND',
|
|
216
|
-
{},
|
|
217
|
-
{},
|
|
218
|
-
{
|
|
219
|
-
status: 404,
|
|
220
|
-
config: {},
|
|
221
|
-
data: {},
|
|
222
|
-
headers: {},
|
|
223
|
-
statusText: 'not found',
|
|
224
|
-
},
|
|
225
|
-
),
|
|
226
|
-
)
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
try {
|
|
230
|
-
await client.proxy.a.get()
|
|
231
|
-
} catch (er: any) {
|
|
232
|
-
expect(er).toBeInstanceOf(RequestError)
|
|
233
|
-
expect(er.status).toBe(404)
|
|
234
|
-
}
|
|
235
|
-
})
|
|
236
|
-
|
|
237
|
-
it('should throw custom exception', async () => {
|
|
238
|
-
class MyRequestError extends Error {
|
|
239
|
-
constructor(
|
|
240
|
-
message: string,
|
|
241
|
-
public status: number,
|
|
242
|
-
public path: string,
|
|
243
|
-
public raw: any,
|
|
244
|
-
) {
|
|
245
|
-
super(message)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
toResponse() {
|
|
249
|
-
return {
|
|
250
|
-
status: this.status,
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const client = generateClient<AxiosResponse>(axiosAdaptor, {
|
|
256
|
-
// @ts-ignore
|
|
257
|
-
customThrowResponseError(err) {
|
|
258
|
-
return new MyRequestError(
|
|
259
|
-
err.message,
|
|
260
|
-
err.response?.status,
|
|
261
|
-
err.path,
|
|
262
|
-
err.raw,
|
|
263
|
-
)
|
|
264
|
-
},
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
spyOn(axiosAdaptor, 'get').mockImplementation(() => {
|
|
268
|
-
return Promise.reject(
|
|
269
|
-
new AxiosError(
|
|
270
|
-
'not found',
|
|
271
|
-
'NOT_FOUND',
|
|
272
|
-
{},
|
|
273
|
-
{},
|
|
274
|
-
{
|
|
275
|
-
status: 404,
|
|
276
|
-
config: {},
|
|
277
|
-
data: {},
|
|
278
|
-
headers: {},
|
|
279
|
-
statusText: 'not found',
|
|
280
|
-
},
|
|
281
|
-
),
|
|
282
|
-
)
|
|
283
|
-
})
|
|
284
|
-
|
|
285
|
-
try {
|
|
286
|
-
await client.proxy.a.get()
|
|
287
|
-
} catch (er: any) {
|
|
288
|
-
expect(er).toBeInstanceOf(MyRequestError)
|
|
289
|
-
expect(er.toResponse).toBeDefined()
|
|
290
|
-
expect(er.status).toBe(404)
|
|
291
|
-
}
|
|
292
|
-
})
|
|
293
|
-
})
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { allControllers } from '~/controllers'
|
|
2
|
-
import { HTTPClient, RequestError, createClient } from '~/core'
|
|
3
|
-
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
4
|
-
|
|
5
|
-
import { createMockServer } from './e2e-mock-server'
|
|
6
|
-
|
|
7
|
-
export const testAdaptor = (adaptor: IRequestAdapter) => {
|
|
8
|
-
let client: HTTPClient
|
|
9
|
-
const { app, close, port } = createMockServer()
|
|
10
|
-
|
|
11
|
-
afterAll(() => {
|
|
12
|
-
close()
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
beforeAll(() => {
|
|
16
|
-
client = createClient(adaptor)(`http://localhost:${port}`)
|
|
17
|
-
client.injectControllers(allControllers)
|
|
18
|
-
})
|
|
19
|
-
test('get', async () => {
|
|
20
|
-
app.get('/posts/1', (req, res) => {
|
|
21
|
-
res.send({
|
|
22
|
-
id: '1',
|
|
23
|
-
category_id: '11',
|
|
24
|
-
})
|
|
25
|
-
})
|
|
26
|
-
const res = await client.post.getPost('1')
|
|
27
|
-
|
|
28
|
-
expect(res).toStrictEqual({
|
|
29
|
-
id: '1',
|
|
30
|
-
categoryId: '11',
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
expect(res.$raw.data.category_id).toEqual('11')
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
test('post', async () => {
|
|
37
|
-
app.post('/comments/1', (req, res) => {
|
|
38
|
-
const { body } = req
|
|
39
|
-
|
|
40
|
-
res.send({
|
|
41
|
-
...body,
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
const dto = {
|
|
45
|
-
text: 'hello',
|
|
46
|
-
author: 'test',
|
|
47
|
-
mail: '1@ee.com',
|
|
48
|
-
}
|
|
49
|
-
const res = await client.comment.comment('1', dto)
|
|
50
|
-
|
|
51
|
-
expect(res).toStrictEqual(dto)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
test('get with search query', async () => {
|
|
55
|
-
app.get('/search/post', (req, res) => {
|
|
56
|
-
if (req.query.keyword) {
|
|
57
|
-
return res.send({ result: 1 })
|
|
58
|
-
}
|
|
59
|
-
res.send(null)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
const res = await client.search.search('post', 'keyword')
|
|
63
|
-
expect(res).toStrictEqual({ result: 1 })
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
test('rawResponse rawRequest should defined', async () => {
|
|
67
|
-
app.get('/search/post', (req, res) => {
|
|
68
|
-
if (req.query.keyword) {
|
|
69
|
-
return res.send({ result: 1 })
|
|
70
|
-
}
|
|
71
|
-
res.send(null)
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
const res = await client.search.search('post', 'keyword')
|
|
75
|
-
expect(res.$raw).toBeDefined()
|
|
76
|
-
expect(res.$raw.data).toBeDefined()
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('should error catch', async () => {
|
|
80
|
-
app.get('/error', (req, res) => {
|
|
81
|
-
res.status(500).send({
|
|
82
|
-
message: 'error message',
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
await expect(client.proxy.error.get()).rejects.toThrowError(RequestError)
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
it('should use number as path', async () => {
|
|
89
|
-
app.get('/1/1', (req, res) => {
|
|
90
|
-
res.send({ data: 1, foo_bar: 'foo' })
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
const res = await client.proxy(1)(1).get<{ data: number; fooBar: string }>()
|
|
94
|
-
|
|
95
|
-
expect(res).toStrictEqual({ data: 1, fooBar: 'foo' })
|
|
96
|
-
expect(res.$raw.data).toStrictEqual({ data: 1, foo_bar: 'foo' })
|
|
97
|
-
expect(res.$request).toBeDefined()
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
it('should get string payload', async () => {
|
|
101
|
-
app.get('/string', (req, res) => {
|
|
102
|
-
res.send('x')
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
const res = await client.proxy('string').get<string>()
|
|
106
|
-
expect(res).toStrictEqual('x')
|
|
107
|
-
})
|
|
108
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import cors from 'cors'
|
|
2
|
-
import express from 'express'
|
|
3
|
-
import { AddressInfo } from 'net'
|
|
4
|
-
|
|
5
|
-
type Express = ReturnType<typeof express>
|
|
6
|
-
export const createMockServer = (options: { port?: number } = {}) => {
|
|
7
|
-
const { port = 0 } = options
|
|
8
|
-
|
|
9
|
-
const app: Express = express()
|
|
10
|
-
app.use(express.json())
|
|
11
|
-
app.use(cors())
|
|
12
|
-
const server = app.listen(port)
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
app,
|
|
16
|
-
port: (server.address() as AddressInfo).port,
|
|
17
|
-
server,
|
|
18
|
-
close() {
|
|
19
|
-
server.close()
|
|
20
|
-
},
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
|
-
/* eslint-disable */
|
|
4
|
-
import AbortController from 'abort-controller'
|
|
5
|
-
import fetch, { Headers, Request, Response } from 'node-fetch'
|
|
6
|
-
|
|
7
|
-
const TEN_MEGABYTES = 1000 * 1000 * 10
|
|
8
|
-
|
|
9
|
-
if (!globalThis.fetch) {
|
|
10
|
-
globalThis.fetch = (url, options) =>
|
|
11
|
-
fetch(url, { highWaterMark: TEN_MEGABYTES, ...options })
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (!globalThis.Headers) {
|
|
15
|
-
globalThis.Headers = Headers
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (!globalThis.Request) {
|
|
19
|
-
globalThis.Request = Request
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!globalThis.Response) {
|
|
23
|
-
globalThis.Response = Response
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!globalThis.AbortController) {
|
|
27
|
-
globalThis.AbortController = AbortController
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!globalThis.ReadableStream) {
|
|
31
|
-
try {
|
|
32
|
-
// eslint-disable-next-line node/file-extension-in-import, node/no-unsupported-features/es-syntax
|
|
33
|
-
globalThis.ReadableStream = await import(
|
|
34
|
-
'web-streams-polyfill/ponyfill/es2018'
|
|
35
|
-
)
|
|
36
|
-
} catch {}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export {}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { axiosAdaptor } from '~/adaptors/axios'
|
|
2
|
-
import { HTTPClient, createClient } from '~/core'
|
|
3
|
-
import { IController } from '~/interfaces/controller'
|
|
4
|
-
|
|
5
|
-
export const mockRequestInstance = (
|
|
6
|
-
injectController: new (client: HTTPClient) => IController,
|
|
7
|
-
) => {
|
|
8
|
-
const client = createClient(axiosAdaptor)('https://api.innei.ren/v2')
|
|
9
|
-
client.injectControllers(injectController)
|
|
10
|
-
return client
|
|
11
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { isEqual } from 'lodash'
|
|
2
|
-
import { URLSearchParams } from 'url'
|
|
3
|
-
import { vi } from 'vitest'
|
|
4
|
-
|
|
5
|
-
import { axiosAdaptor } from '~/adaptors/axios'
|
|
6
|
-
|
|
7
|
-
const { spyOn } = vi
|
|
8
|
-
|
|
9
|
-
export const buildResponseDataWrapper = (data: any) => ({ data })
|
|
10
|
-
|
|
11
|
-
export const mockResponse = <T>(
|
|
12
|
-
path: string,
|
|
13
|
-
data: T,
|
|
14
|
-
method = 'get',
|
|
15
|
-
requestBody?: any,
|
|
16
|
-
) => {
|
|
17
|
-
const exceptUrlObject = new URL(
|
|
18
|
-
path.startsWith('http')
|
|
19
|
-
? path
|
|
20
|
-
: `https://example.com/${path.replace(/^\//, '')}`,
|
|
21
|
-
)
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
spyOn(axiosAdaptor, method).mockImplementation(
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
async (requestUrl: string, options: any) => {
|
|
26
|
-
const requestUrlObject = new URL(requestUrl)
|
|
27
|
-
|
|
28
|
-
if (requestBody) {
|
|
29
|
-
const { data } = options || {}
|
|
30
|
-
if (!isEqual(requestBody, data)) {
|
|
31
|
-
throw new Error(
|
|
32
|
-
`body not equal, got: ${JSON.stringify(
|
|
33
|
-
data,
|
|
34
|
-
)} except: ${JSON.stringify(requestBody)}`,
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
requestUrlObject.pathname.endsWith(exceptUrlObject.pathname) &&
|
|
41
|
-
(exceptUrlObject.search
|
|
42
|
-
? isSearchEqual(
|
|
43
|
-
exceptUrlObject.searchParams,
|
|
44
|
-
requestUrlObject.searchParams,
|
|
45
|
-
)
|
|
46
|
-
: true)
|
|
47
|
-
) {
|
|
48
|
-
return buildResponseDataWrapper(data)
|
|
49
|
-
} else {
|
|
50
|
-
return buildResponseDataWrapper({
|
|
51
|
-
error: 1,
|
|
52
|
-
requestPath: requestUrlObject.pathname + requestUrlObject.search,
|
|
53
|
-
expectPath: path,
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
return data
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const isSearchEqual = (a: URLSearchParams, b: URLSearchParams) => {
|
|
63
|
-
const keys = Array.from(a.keys()).sort()
|
|
64
|
-
if (keys.toString() !== Array.from(b.keys()).sort().toString()) {
|
|
65
|
-
return false
|
|
66
|
-
}
|
|
67
|
-
return keys.every((key) => {
|
|
68
|
-
const res = a.get(key) === b.get(key)
|
|
69
|
-
if (!res) {
|
|
70
|
-
console.log(
|
|
71
|
-
`key ${key} not equal, receive ${a.get(key)} want ${b.get(key)}`,
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
return res
|
|
75
|
-
})
|
|
76
|
-
}
|