@mx-space/api-client 1.0.0 → 1.0.2
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/.eslintcache +1 -1
- package/LICENSE +661 -0
- package/controllers/recently.ts +24 -3
- package/dist/index.cjs +18 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/dist/index.min.cjs +1 -1
- package/dist/index.min.cjs.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.umd.js +18 -0
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- 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 +110 -0
- package/esm/controllers/recently.js +49 -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 +110 -0
- package/lib/controllers/recently.js +53 -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 +26 -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 +110 -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,284 +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 { CategoryController } from '~/controllers'
|
|
6
|
-
|
|
7
|
-
describe('test Category client', () => {
|
|
8
|
-
const client = mockRequestInstance(CategoryController)
|
|
9
|
-
|
|
10
|
-
test('GET /categories', async () => {
|
|
11
|
-
const mocked = mockResponse('/categories', {
|
|
12
|
-
data: [
|
|
13
|
-
{
|
|
14
|
-
id: '5eb2c62a613a5ab0642f1f7a',
|
|
15
|
-
type: 0,
|
|
16
|
-
count: 34,
|
|
17
|
-
name: '编程',
|
|
18
|
-
slug: 'programming',
|
|
19
|
-
created: '2020-05-06T14:14:02.339Z',
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const data = await client.category.getAllCategories()
|
|
25
|
-
expect(data.$raw.data).toEqual(mocked)
|
|
26
|
-
expect(data.data).toEqual(mocked.data)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
describe('GET /categories/:id', () => {
|
|
30
|
-
test('get by slug', async () => {
|
|
31
|
-
const mocked = mockResponse('/categories/programming', {
|
|
32
|
-
data: {
|
|
33
|
-
id: '5eb2c62a613a5ab0642f1f7a',
|
|
34
|
-
type: 0,
|
|
35
|
-
count: 2,
|
|
36
|
-
name: '编程',
|
|
37
|
-
slug: 'programming',
|
|
38
|
-
created: '2020-05-06T14:14:02.339Z',
|
|
39
|
-
children: [
|
|
40
|
-
{
|
|
41
|
-
id: '611748895c2f6f4d3ba0d9b3',
|
|
42
|
-
title: 'pageproxy,为 spa 提供初始数据注入',
|
|
43
|
-
slug: 'pageproxy-spa-inject',
|
|
44
|
-
created: '2021-08-14T04:37:29.880Z',
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
id: '60cffff50ec52e0349cbb29f',
|
|
48
|
-
title: '曲折的 Vue 3 重构后台之路',
|
|
49
|
-
slug: 'mx-space-vue-3',
|
|
50
|
-
created: '2021-06-21T02:56:53.126Z',
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
},
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
const data = await client.category.getCategoryByIdOrSlug('programming')
|
|
57
|
-
expect(data).toEqual(mocked.data)
|
|
58
|
-
expect(data.count).toEqual(mocked.data.count)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
test('get by id', async () => {
|
|
62
|
-
const mocked = mockResponse('/categories/5eb2c62a613a5ab0642f1f7a', {
|
|
63
|
-
data: {
|
|
64
|
-
id: '5eb2c62a613a5ab0642f1f7a',
|
|
65
|
-
type: 0,
|
|
66
|
-
count: 2,
|
|
67
|
-
name: '编程',
|
|
68
|
-
slug: 'programming',
|
|
69
|
-
created: '2020-05-06T14:14:02.339Z',
|
|
70
|
-
children: [
|
|
71
|
-
{
|
|
72
|
-
id: '611748895c2f6f4d3ba0d9b3',
|
|
73
|
-
title: 'pageproxy,为 spa 提供初始数据注入',
|
|
74
|
-
slug: 'pageproxy-spa-inject',
|
|
75
|
-
created: '2021-08-14T04:37:29.880Z',
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
id: '60cffff50ec52e0349cbb29f',
|
|
79
|
-
title: '曲折的 Vue 3 重构后台之路',
|
|
80
|
-
slug: 'mx-space-vue-3',
|
|
81
|
-
created: '2021-06-21T02:56:53.126Z',
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
},
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
const data = await client.category.getCategoryByIdOrSlug(
|
|
88
|
-
'5eb2c62a613a5ab0642f1f7a',
|
|
89
|
-
)
|
|
90
|
-
expect(data).toEqual(mocked.data)
|
|
91
|
-
expect(data.count).toEqual(mocked.data.count)
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
test('GET /categories/:tagName', async () => {
|
|
96
|
-
const mocked = mockResponse('/categories/react?tag=1', {
|
|
97
|
-
tag: 'react',
|
|
98
|
-
data: [
|
|
99
|
-
{
|
|
100
|
-
id: '607bfcedc98328a0d941a409',
|
|
101
|
-
title: '虚拟列表与 Scroll Restoration',
|
|
102
|
-
slug: 'visualize-list-scroll-restoration',
|
|
103
|
-
category: {
|
|
104
|
-
id: '5eb2c62a613a5ab0642f1f7a',
|
|
105
|
-
type: 0,
|
|
106
|
-
name: '编程',
|
|
107
|
-
slug: 'programming',
|
|
108
|
-
},
|
|
109
|
-
created: '2021-04-18T09:33:33.271Z',
|
|
110
|
-
},
|
|
111
|
-
],
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
const data = await client.category.getTagByName('react')
|
|
115
|
-
expect(data.tag).toEqual('react')
|
|
116
|
-
expect(data.data).toEqual(mocked.data)
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
test('GET /categories?type=0', async () => {
|
|
120
|
-
const mocked = mockResponse('/categories?type=0', {
|
|
121
|
-
data: [
|
|
122
|
-
{
|
|
123
|
-
id: '5eb2c62a613a5ab0642f1f7a',
|
|
124
|
-
type: 0,
|
|
125
|
-
count: 34,
|
|
126
|
-
name: '编程',
|
|
127
|
-
slug: 'programming',
|
|
128
|
-
created: '2020-05-06T14:14:02.339Z',
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
const data = await client.category.getAllCategories()
|
|
134
|
-
expect(data.data).toEqual(mocked.data)
|
|
135
|
-
expect(data.$raw.data).toEqual(mocked)
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
test('GET /categories?type=1', async () => {
|
|
139
|
-
const mocked = mockResponse('/categories?type=1', {
|
|
140
|
-
data: [
|
|
141
|
-
{
|
|
142
|
-
count: 2,
|
|
143
|
-
name: 'docker',
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
count: 1,
|
|
147
|
-
name: 'react',
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
})
|
|
151
|
-
const data = await client.category.getAllTags()
|
|
152
|
-
expect(data.data).toEqual(mocked.data)
|
|
153
|
-
expect(data.$raw.data).toEqual(mocked)
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
describe('GET /categories?ids=', () => {
|
|
157
|
-
it('should get with ids array', async () => {
|
|
158
|
-
const mocked = mockResponse(
|
|
159
|
-
'/categories?ids=5ed5be418f3d6b6cb9ab7700,5eb2c62a613a5ab0642f1f7b',
|
|
160
|
-
{
|
|
161
|
-
entries: {
|
|
162
|
-
'5ed5be418f3d6b6cb9ab7700': {
|
|
163
|
-
id: '5ed5be418f3d6b6cb9ab7700',
|
|
164
|
-
type: 0,
|
|
165
|
-
count: 2,
|
|
166
|
-
slug: 'reprint',
|
|
167
|
-
name: '转载',
|
|
168
|
-
created: '2020-06-02T02:49:37.424Z',
|
|
169
|
-
children: [
|
|
170
|
-
{
|
|
171
|
-
id: '6005562e6b14b33be8afc1c3',
|
|
172
|
-
allow_comment: true,
|
|
173
|
-
copyright: false,
|
|
174
|
-
tags: [],
|
|
175
|
-
count: {
|
|
176
|
-
read: 221,
|
|
177
|
-
like: 3,
|
|
178
|
-
},
|
|
179
|
-
title: '[reprint] Your Own Time Zone',
|
|
180
|
-
slug: 'your-own-time-zone',
|
|
181
|
-
category_id: '5ed5be418f3d6b6cb9ab7700',
|
|
182
|
-
modified: '2021-01-18T09:41:37.380Z',
|
|
183
|
-
created: '2021-01-18T09:34:38.550Z',
|
|
184
|
-
},
|
|
185
|
-
],
|
|
186
|
-
},
|
|
187
|
-
'5eb2c62a613a5ab0642f1f7b': {
|
|
188
|
-
id: '5eb2c62a613a5ab0642f1f7b',
|
|
189
|
-
type: 0,
|
|
190
|
-
count: 19,
|
|
191
|
-
name: '折腾',
|
|
192
|
-
slug: 'Z-Turn',
|
|
193
|
-
created: '2020-05-06T14:14:02.356Z',
|
|
194
|
-
children: [
|
|
195
|
-
{
|
|
196
|
-
id: '5eb2c62a613a5ab0642f1f95',
|
|
197
|
-
title: '从零开始的 Redux',
|
|
198
|
-
slug: 'learn-redux',
|
|
199
|
-
created: '2020-01-08T08:24:00.000Z',
|
|
200
|
-
modified: '2020-11-14T06:50:19.164Z',
|
|
201
|
-
category_id: '5eb2c62a613a5ab0642f1f7b',
|
|
202
|
-
copyright: true,
|
|
203
|
-
count: {
|
|
204
|
-
read: 309,
|
|
205
|
-
like: 2,
|
|
206
|
-
},
|
|
207
|
-
allow_comment: true,
|
|
208
|
-
tags: [],
|
|
209
|
-
},
|
|
210
|
-
],
|
|
211
|
-
},
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
|
-
)
|
|
215
|
-
|
|
216
|
-
const data = await client.category.getCategoryDetail([
|
|
217
|
-
'5ed5be418f3d6b6cb9ab7700',
|
|
218
|
-
'5eb2c62a613a5ab0642f1f7b',
|
|
219
|
-
])
|
|
220
|
-
|
|
221
|
-
expect(data).toEqual(
|
|
222
|
-
new Map([
|
|
223
|
-
[
|
|
224
|
-
'5ed5be418f3d6b6cb9ab7700',
|
|
225
|
-
camelcaseKeys(mocked.entries['5ed5be418f3d6b6cb9ab7700'], {
|
|
226
|
-
deep: true,
|
|
227
|
-
}),
|
|
228
|
-
],
|
|
229
|
-
[
|
|
230
|
-
'5eb2c62a613a5ab0642f1f7b',
|
|
231
|
-
camelcaseKeys(mocked.entries['5eb2c62a613a5ab0642f1f7b'], {
|
|
232
|
-
deep: true,
|
|
233
|
-
}),
|
|
234
|
-
],
|
|
235
|
-
]),
|
|
236
|
-
)
|
|
237
|
-
|
|
238
|
-
expect(data.$raw.data).toEqual(mocked)
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
it('should get with single id', async () => {
|
|
242
|
-
const mocked = mockResponse('/categories?ids=5ed5be418f3d6b6cb9ab7700', {
|
|
243
|
-
entries: {
|
|
244
|
-
'5ed5be418f3d6b6cb9ab7700': {
|
|
245
|
-
id: '5ed5be418f3d6b6cb9ab7700',
|
|
246
|
-
type: 0,
|
|
247
|
-
count: 2,
|
|
248
|
-
slug: 'reprint',
|
|
249
|
-
name: '转载',
|
|
250
|
-
created: '2020-06-02T02:49:37.424Z',
|
|
251
|
-
children: [
|
|
252
|
-
{
|
|
253
|
-
id: '6005562e6b14b33be8afc1c3',
|
|
254
|
-
allow_comment: true,
|
|
255
|
-
copyright: false,
|
|
256
|
-
tags: [],
|
|
257
|
-
count: {
|
|
258
|
-
read: 221,
|
|
259
|
-
like: 3,
|
|
260
|
-
},
|
|
261
|
-
title: '[reprint] Your Own Time Zone',
|
|
262
|
-
slug: 'your-own-time-zone',
|
|
263
|
-
category_id: '5ed5be418f3d6b6cb9ab7700',
|
|
264
|
-
modified: '2021-01-18T09:41:37.380Z',
|
|
265
|
-
created: '2021-01-18T09:34:38.550Z',
|
|
266
|
-
},
|
|
267
|
-
],
|
|
268
|
-
},
|
|
269
|
-
},
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
const data = await client.category.getCategoryDetail(
|
|
273
|
-
'5ed5be418f3d6b6cb9ab7700',
|
|
274
|
-
)
|
|
275
|
-
expect(data).toEqual(
|
|
276
|
-
camelcaseKeys(mocked.entries['5ed5be418f3d6b6cb9ab7700'], {
|
|
277
|
-
deep: true,
|
|
278
|
-
}),
|
|
279
|
-
)
|
|
280
|
-
|
|
281
|
-
expect(data.$raw.data).toEqual(mocked)
|
|
282
|
-
})
|
|
283
|
-
})
|
|
284
|
-
})
|
|
@@ -1,113 +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 { CommentController } from '~/controllers/comment'
|
|
6
|
-
|
|
7
|
-
describe('test note client', () => {
|
|
8
|
-
const client = mockRequestInstance(CommentController)
|
|
9
|
-
|
|
10
|
-
test('get comment by id', async () => {
|
|
11
|
-
mockResponse('/comments/11111', {
|
|
12
|
-
ref_type: 'Page',
|
|
13
|
-
state: 1,
|
|
14
|
-
children: [],
|
|
15
|
-
comments_index: 1,
|
|
16
|
-
id: '6188b80b6290547080c9e1f3',
|
|
17
|
-
author: 'yss',
|
|
18
|
-
text: '做的框架模板不错. (•౪• ) ',
|
|
19
|
-
url: 'https://gitee.com/kmyss/',
|
|
20
|
-
key: '#26',
|
|
21
|
-
ref: '5e0318319332d06503619337',
|
|
22
|
-
created: '2021-11-08T05:39:23.010Z',
|
|
23
|
-
avatar:
|
|
24
|
-
'https://sdn.geekzu.org/avatar/8675fa376c044b0d93a23374549c4248?d=retro',
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
const data = await client.comment.getById('11111')
|
|
28
|
-
expect(data.children).toEqual([])
|
|
29
|
-
expect(data.text).toBeDefined()
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
test('get comment by ref id', async () => {
|
|
33
|
-
const comments = [
|
|
34
|
-
{
|
|
35
|
-
ref_type: 'Page',
|
|
36
|
-
state: 1,
|
|
37
|
-
children: [],
|
|
38
|
-
comments_index: 1,
|
|
39
|
-
id: '6188b80b6290547080c9e1f3',
|
|
40
|
-
author: 'yss',
|
|
41
|
-
text: '做的框架模板不错. (•౪• ) ',
|
|
42
|
-
url: 'https://gitee.com/kmyss/',
|
|
43
|
-
key: '#26',
|
|
44
|
-
ref: '5e0318319332d06503619337',
|
|
45
|
-
created: '2021-11-08T05:39:23.010Z',
|
|
46
|
-
avatar:
|
|
47
|
-
'https://sdn.geekzu.org/avatar/8675fa376c044b0d93a23374549c4248?d=retro',
|
|
48
|
-
},
|
|
49
|
-
]
|
|
50
|
-
mockResponse(
|
|
51
|
-
'/comments/ref/5e0318319332d06503619337',
|
|
52
|
-
{
|
|
53
|
-
data: comments,
|
|
54
|
-
pagination: {
|
|
55
|
-
total: 23,
|
|
56
|
-
current_page: 1,
|
|
57
|
-
total_page: 3,
|
|
58
|
-
size: 10,
|
|
59
|
-
has_next_page: true,
|
|
60
|
-
has_prev_page: false,
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
'get',
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
const data = await client.comment.getByRefId('5e0318319332d06503619337')
|
|
67
|
-
|
|
68
|
-
expect(data.data).toEqual(camelcaseKeys(comments, { deep: true }))
|
|
69
|
-
expect(data.pagination.total).toEqual(23)
|
|
70
|
-
expect(data.pagination.hasNextPage).toEqual(true)
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it('should comment successfully', async () => {
|
|
74
|
-
mockResponse(
|
|
75
|
-
'/comments/1',
|
|
76
|
-
{
|
|
77
|
-
id: '1',
|
|
78
|
-
text: 'bar',
|
|
79
|
-
},
|
|
80
|
-
'post',
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
const data = await client.comment.comment('1', {
|
|
84
|
-
author: 'foo',
|
|
85
|
-
text: 'bar',
|
|
86
|
-
mail: 'xx@aa.com',
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
expect(data).toEqual({
|
|
90
|
-
id: '1',
|
|
91
|
-
text: 'bar',
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
it('should reply comment successfully', async () => {
|
|
96
|
-
mockResponse(
|
|
97
|
-
'/comments/reply/1',
|
|
98
|
-
{
|
|
99
|
-
id: '1',
|
|
100
|
-
text: 'bar',
|
|
101
|
-
},
|
|
102
|
-
'post',
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
const data = await client.comment.reply('1', {
|
|
106
|
-
author: 'f',
|
|
107
|
-
text: 'bar',
|
|
108
|
-
mail: 'a@q.com',
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
expect(data).toEqual({ id: '1', text: 'bar' })
|
|
112
|
-
})
|
|
113
|
-
})
|
|
@@ -1,95 +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 { LinkController } from '~/controllers'
|
|
6
|
-
|
|
7
|
-
describe('test link client, /links', () => {
|
|
8
|
-
const client = mockRequestInstance(LinkController)
|
|
9
|
-
|
|
10
|
-
test('GET /', async () => {
|
|
11
|
-
const mocked = mockResponse('/links?size=10&page=1', {
|
|
12
|
-
data: [
|
|
13
|
-
{
|
|
14
|
-
type: 0,
|
|
15
|
-
state: 0,
|
|
16
|
-
id: '615c191ed5db15a1000e3ca6',
|
|
17
|
-
url: 'https://barry-flynn.github.io/',
|
|
18
|
-
avatar: 'https://i.loli.net/2021/09/09/5belKgmrkjN8ZQ7.jpg',
|
|
19
|
-
description: '星河滚烫,无问西东。',
|
|
20
|
-
name: '百里飞洋の博客',
|
|
21
|
-
created: '2021-10-05T09:21:34.257Z',
|
|
22
|
-
hide: false,
|
|
23
|
-
},
|
|
24
|
-
// ...
|
|
25
|
-
],
|
|
26
|
-
pagination: {
|
|
27
|
-
total: 43,
|
|
28
|
-
current_page: 1,
|
|
29
|
-
total_page: 5,
|
|
30
|
-
size: 10,
|
|
31
|
-
has_next_page: true,
|
|
32
|
-
has_prev_page: false,
|
|
33
|
-
},
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
const data = await client.link.getAllPaginated(1, 10)
|
|
37
|
-
expect(data.$raw.data).toEqual(mocked)
|
|
38
|
-
expect(data).toEqual(camelcaseKeys(mocked, { deep: true }))
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('should `friend` == `link`', () => {
|
|
42
|
-
expect(client.link).toEqual(client.friend)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
test('GET /all', async () => {
|
|
46
|
-
const mocked = mockResponse('/links/all', {
|
|
47
|
-
data: [],
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
const data = await client.link.getAll()
|
|
51
|
-
expect(data.$raw.data).toEqual(mocked)
|
|
52
|
-
expect(data).toEqual(camelcaseKeys(mocked, { deep: true }))
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
test('GET /:id', async () => {
|
|
56
|
-
const mocked = mockResponse('/links/5eaabe10cd5bca719652179d', {
|
|
57
|
-
id: '5eaabe10cd5bca719652179d',
|
|
58
|
-
name: '静かな森',
|
|
59
|
-
url: 'https://innei.ren',
|
|
60
|
-
avatar: 'https://cdn.innei.ren/avatar.png',
|
|
61
|
-
created: '2020-04-30T12:01:20.738Z',
|
|
62
|
-
type: 0,
|
|
63
|
-
description: '致虚极,守静笃。',
|
|
64
|
-
state: 0,
|
|
65
|
-
})
|
|
66
|
-
const data = await client.link.getById('5eaabe10cd5bca719652179d')
|
|
67
|
-
expect(data.$raw.data).toEqual(mocked)
|
|
68
|
-
expect(data).toEqual(camelcaseKeys(mocked, { deep: true }))
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
test('GET /audit', async () => {
|
|
72
|
-
const mocked = mockResponse('/links/audit', {
|
|
73
|
-
can: true,
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
const allowed = await client.link.canApplyLink()
|
|
77
|
-
|
|
78
|
-
expect(allowed).toEqual(mocked.can)
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
test('POST /audit', async () => {
|
|
82
|
-
const payload = {
|
|
83
|
-
author: '',
|
|
84
|
-
avatar: '',
|
|
85
|
-
name: '',
|
|
86
|
-
url: '',
|
|
87
|
-
description: '',
|
|
88
|
-
email: '',
|
|
89
|
-
}
|
|
90
|
-
mockResponse('/links/audit', 'OK', 'post', payload)
|
|
91
|
-
const res = await client.link.applyLink(payload)
|
|
92
|
-
|
|
93
|
-
expect(res).toEqual('OK')
|
|
94
|
-
})
|
|
95
|
-
})
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { vi } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { mockRequestInstance } from '~/__tests__/helpers/instance'
|
|
4
|
-
import { mockResponse } from '~/__tests__/helpers/response'
|
|
5
|
-
import { axiosAdaptor } from '~/adaptors/axios'
|
|
6
|
-
import { NoteController } from '~/controllers'
|
|
7
|
-
import { RequestError } from '~/core'
|
|
8
|
-
|
|
9
|
-
const { spyOn } = vi
|
|
10
|
-
|
|
11
|
-
describe('test note client', () => {
|
|
12
|
-
const client = mockRequestInstance(NoteController)
|
|
13
|
-
|
|
14
|
-
it('should get note list', async () => {
|
|
15
|
-
mockResponse('/notes', {
|
|
16
|
-
data: [],
|
|
17
|
-
pagination: {},
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const data = await client.note.getList()
|
|
21
|
-
expect(data).toEqual({ data: [], pagination: {} })
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('should get post list filter filed', async () => {
|
|
25
|
-
const mocked = mockResponse('/notes?page=1&size=1&select=created+title', {
|
|
26
|
-
data: [{}],
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
const data = await client.note.getList(1, 1, {
|
|
30
|
-
select: ['created', 'title'],
|
|
31
|
-
})
|
|
32
|
-
expect(data).toEqual(mocked)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('should get latest note', async () => {
|
|
36
|
-
mockResponse('/notes/latest', { data: { title: '1' } })
|
|
37
|
-
const data = await client.note.getLatest()
|
|
38
|
-
expect(data.data.title).toBe('1')
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('should get middle list of note', async () => {
|
|
42
|
-
mockResponse('/notes/list/1', {
|
|
43
|
-
data: [
|
|
44
|
-
{
|
|
45
|
-
id: '1',
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
id: '2',
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
size: 2,
|
|
52
|
-
})
|
|
53
|
-
const data = await client.note.getMiddleList('1')
|
|
54
|
-
expect(data).toEqual({
|
|
55
|
-
data: [
|
|
56
|
-
{
|
|
57
|
-
id: '1',
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
id: '2',
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
size: 2,
|
|
64
|
-
})
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('should get single note', async () => {
|
|
68
|
-
mockResponse('/notes/1', { title: '1' })
|
|
69
|
-
|
|
70
|
-
const data = await client.note.getNoteById('1')
|
|
71
|
-
|
|
72
|
-
expect(data).toStrictEqual({ title: '1' })
|
|
73
|
-
expect(data.$raw).toBeDefined()
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
it('should get note by nid', async () => {
|
|
77
|
-
mockResponse('/notes/nid/1', { data: { title: '1' } })
|
|
78
|
-
|
|
79
|
-
const data = await client.note.getNoteById(1)
|
|
80
|
-
expect(data.data.title).toBe('1')
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('should get note by nid query single result', async () => {
|
|
84
|
-
mockResponse('/notes/nid/1', { title: '1' })
|
|
85
|
-
|
|
86
|
-
const data = await client.note.getNoteById(1, undefined, true)
|
|
87
|
-
expect(data.title).toBe('1')
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it('should like note', async () => {
|
|
91
|
-
mockResponse('/notes/like/1', null)
|
|
92
|
-
|
|
93
|
-
const data = await client.note.likeIt('1')
|
|
94
|
-
|
|
95
|
-
expect(data).toBeNull()
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it('should forbidden if no password provide', async () => {
|
|
99
|
-
spyOn(axiosAdaptor, 'get').mockRejectedValue({
|
|
100
|
-
response: {
|
|
101
|
-
data: {
|
|
102
|
-
message: 'password required',
|
|
103
|
-
},
|
|
104
|
-
status: 403,
|
|
105
|
-
},
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
await expect(client.note.getNoteById('1')).rejects.toThrowError(
|
|
109
|
-
RequestError,
|
|
110
|
-
)
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
test('GET /notes/topics/:id', async () => {
|
|
114
|
-
mockResponse('/notes/topics/11111111', { data: [], pagination: {} })
|
|
115
|
-
|
|
116
|
-
const data = await client.note.getNoteByTopicId('11111111')
|
|
117
|
-
|
|
118
|
-
expect(data).toEqual({ data: [], pagination: {} })
|
|
119
|
-
})
|
|
120
|
-
})
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { mockRequestInstance } from '~/__tests__/helpers/instance'
|
|
2
|
-
import { mockResponse } from '~/__tests__/helpers/response'
|
|
3
|
-
import { PageController } from '~/controllers/page'
|
|
4
|
-
|
|
5
|
-
describe('test page client', () => {
|
|
6
|
-
const client = mockRequestInstance(PageController)
|
|
7
|
-
|
|
8
|
-
it('should get page list', async () => {
|
|
9
|
-
mockResponse('/pages?size=10&page=1', {
|
|
10
|
-
data: [],
|
|
11
|
-
pagination: {},
|
|
12
|
-
})
|
|
13
|
-
const data = await client.page.getList()
|
|
14
|
-
expect(data).toEqual({ data: [], pagination: {} })
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it('should get post list filter filed', async () => {
|
|
18
|
-
const mocked = mockResponse('/pages?page=1&size=1&select=created+title', {
|
|
19
|
-
data: [{}],
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
const data = await client.page.getList(1, 1, {
|
|
23
|
-
select: ['created', 'title'],
|
|
24
|
-
})
|
|
25
|
-
expect(data).toEqual(mocked)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('should get single page', async () => {
|
|
29
|
-
mockResponse('/pages/1', {
|
|
30
|
-
title: '1',
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const data = await client.page.getById('1')
|
|
34
|
-
|
|
35
|
-
expect(data).toStrictEqual({ title: '1' })
|
|
36
|
-
expect(data.$raw).toBeDefined()
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('should get by slug', async () => {
|
|
40
|
-
mockResponse('/pages/slug/about', {
|
|
41
|
-
title: 'about',
|
|
42
|
-
text: 'about!',
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const data = await client.page.getBySlug('about')
|
|
46
|
-
expect(data.title).toBe('about')
|
|
47
|
-
expect(data.text).toBe('about!')
|
|
48
|
-
})
|
|
49
|
-
})
|