Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAllContents関数のリファクタ #71

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tecsoc
Copy link

@tecsoc tecsoc commented Oct 25, 2023

Issueにしようかと思いましたが、説明するよりコードを書いた方が早かったのでPRを作ってしまいました。
感覚的にはIssueのつもりで出しているので、レスポンスが遅かったりしたら
勝手に修正してマージしてしまっても大丈夫です

修正内容

  • エイリアスパスでインポートできるようにする
  • Promise.allとlimitを併用し、getAllContents関数を高速化する
  • limitを引数にして利用者が自由に変更できるようにする
    コンテンツ容量によっては、100件取得すると最大レスポンスサイズ:約5MBに抵触してエラーになるため
  • インターバルを引数にして利用者が自由に変更できるようにする
    1秒間に60リクエストという、microCMSの制限ギリギリであるため。

補足

テストケースを追加する必要がありそうですが、まだ対応できていないです

help

テストが通らないです。
ざっくりこんなエラーです

  console.warn
    [MSW] Warning: captured a request without a matching request handler:
    
      • GET https://servicedomain.microcms.io/api/v1/getAllContents-list-type
    
    If you still wish to intercept this unhandled request, please create a request handler for it.
    Read more: https://mswjs.io/docs/getting-started/mocks

      at Object.warn (node_modules/msw/src/utils/internal/devUtils.ts:17:11)
      at applyStrategy (node_modules/msw/src/utils/request/onUnhandledRequest.ts:208:18)
      at onUnhandledRequest (node_modules/msw/src/utils/request/onUnhandledRequest.ts:233:3)
      at handleRequest (node_modules/msw/src/utils/handleRequest.ts:80:5)
      at node_modules/msw/src/node/SetupServerApi.ts:69:24

  console.warn
    [MSW] Warning: captured a request without a matching request handler:
    
      • GET https://servicedomain.microcms.io/api/v1/getAllContents-list-type
    
    If you still wish to intercept this unhandled request, please create a request handler for it.
    Read more: https://mswjs.io/docs/getting-started/mocks

      at Object.warn (node_modules/msw/src/utils/internal/devUtils.ts:17:11)
      at applyStrategy (node_modules/msw/src/utils/request/onUnhandledRequest.ts:208:18)
      at onUnhandledRequest (node_modules/msw/src/utils/request/onUnhandledRequest.ts:233:3)
      at handleRequest (node_modules/msw/src/utils/handleRequest.ts:80:5)
      at node_modules/msw/src/node/SetupServerApi.ts:69:24

  console.warn
    [MSW] Warning: captured a request without a matching request handler:
    
      • GET https://servicedomain.microcms.io/api/v1/getAllContents-list-type
    
    If you still wish to intercept this unhandled request, please create a request handler for it.
    Read more: https://mswjs.io/docs/getting-started/mocks

      at Object.warn (node_modules/msw/src/utils/internal/devUtils.ts:17:11)
      at applyStrategy (node_modules/msw/src/utils/request/onUnhandledRequest.ts:208:18)
      at onUnhandledRequest (node_modules/msw/src/utils/request/onUnhandledRequest.ts:233:3)
      at handleRequest (node_modules/msw/src/utils/handleRequest.ts:80:5)
      at node_modules/msw/src/node/SetupServerApi.ts:69:24

 FAIL  tests/getAllContents.test.ts (12.566 s)
  getAllContents
    ✕ should fetch all contents (1749 ms)
    ✕ should handle pagination and fetch more than limit (1283 ms)

  ● getAllContents › should fetch all contents

    fetch API response status: 404

       98 |
       99 |             return bail(
    > 100 |               new Error(
          |               ^
      101 |                 `fetch API response status: ${response.status}${
      102 |                   message ? `\n  message is \`${message}\`` : ''
      103 |                 }`,

      at src/createClient.ts:100:15
      at step (src/createClient.ts:44:23)
      at Object.next (src/createClient.ts:25:53)
      at fulfilled (src/createClient.ts:16:58)

  ● getAllContents › should handle pagination and fetch more than limit

    fetch API response status: 404

       98 |
       99 |             return bail(
    > 100 |               new Error(
          |               ^
      101 |                 `fetch API response status: ${response.status}${
      102 |                   message ? `\n  message is \`${message}\`` : ''
      103 |                 }`,

      at src/createClient.ts:100:15
      at step (src/createClient.ts:44:23)
      at Object.next (src/createClient.ts:25:53)
      at fulfilled (src/createClient.ts:16:58)

Test Suites: 1 failed, 1 total
Tests:       2 failed, 2 total

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant