traPtitech / traPtitech/Checkin

invoiceDaysUntilDue を決める分岐にテストがない

Open
#56 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
0
Forks
0
Avg merge
3d 5h
Merged PRs (30d)
7

Description

現状

請求書の支払期限までの日数は、apps/web/server/utils/billing-config.tsresolveBillingConfignum という補助関数を通して決めている。numNumber(value) が有限かつ正のときだけその値を採り、そうでなければ第 2 引数の既定値 7 を返す。runtimeConfiginvoiceDaysUntilDueapps/web/nuxt.config.tsprocess.env['INVOICE_DAYS_UNTIL_DUE'] ?? '7' と宣言されているので、環境変数を設定しない場合も文字列の '7' が渡る。

この 2 つの経路(環境変数の値を採る経路と、既定値 7 へ落ちる経路)を区別するテストがない。2026-09-18 に git grep -n 'invoiceDaysUntilDue' で参照箇所を数えたところ、テストが触れているのは次の 3 つだけだった。

  • packages/api/src/billing/billing.test.tspackages/api/src/membership/router.test.ts は、BillingConfig を組み立てるときに invoiceDaysUntilDue: 7 を直接書いている。num を通らない。
  • apps/web/server/utils/auth.test.tsresolveBillingConfig を実物のまま使うが、渡す runtimeConfiginvoiceDaysUntilDue を含めておらず、invoiceDaysUntilDue の値を一切検査しない。

packages/api/src/stripe/invoices.tscreateDraftInvoice は受け取った daysUntilDuedays_until_due にそのまま渡すだけなので、値を決める分岐はこの関数の側には無い。

誰が何を誤るか

num の条件(有限かつ正)を変える人が、テストを頼りに変更の影響を確かめられない。2026-09-18 に feat/merge-auth-collectiond8feaca で、num の条件から && n > 0 を落として Number.isFinite(n) ? n : fallback にしたうえで npx vitest run を実行したところ、30 ファイル 265 件がすべて通った。負の値や 0 を通すようになっても、どのテストも失敗しない。

難しい点

resolveBillingConfig は結果をモジュールの変数に保存して再利用する(let cached)。この変数を戻す手段が公開されていないので、1 つのテストファイルの中で複数の runtimeConfig を与えて結果を比べることが今の形ではできない。テストを足すときは、キャッシュを戻す手段を用意するか、num 相当の導出を単体で呼べる形へ切り出す必要がある。

直さずに残した理由

キャッシュの戻し方か導出の切り出しかを選ぶ判断が要り、どちらも resolveBillingConfig の形を変える。

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with apps/web/server/utils/billing-config.ts and apps/web/server/utils/auth.test.ts, then run the existing npx vitest run suite. Choose and document a way to test resolveBillingConfig across runtimeConfig values, covering both the environment-provided invoiceDaysUntilDue path and the fallback-to-7 path; done means the tests fail if non-finite, zero, or negative values are accepted.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend, testing
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.