traPtitech / traPtitech/Checkin
invoiceDaysUntilDue を決める分岐にテストがない
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 0
- Forks
- 0
- Avg merge
- 3d 5h
- Merged PRs (30d)
- 7
Description
現状
請求書の支払期限までの日数は、apps/web/server/utils/billing-config.ts の resolveBillingConfig が num という補助関数を通して決めている。num は Number(value) が有限かつ正のときだけその値を採り、そうでなければ第 2 引数の既定値 7 を返す。runtimeConfig の invoiceDaysUntilDue は apps/web/nuxt.config.ts で process.env['INVOICE_DAYS_UNTIL_DUE'] ?? '7' と宣言されているので、環境変数を設定しない場合も文字列の '7' が渡る。
この 2 つの経路(環境変数の値を採る経路と、既定値 7 へ落ちる経路)を区別するテストがない。2026-09-18 に git grep -n 'invoiceDaysUntilDue' で参照箇所を数えたところ、テストが触れているのは次の 3 つだけだった。
packages/api/src/billing/billing.test.tsとpackages/api/src/membership/router.test.tsは、BillingConfigを組み立てるときにinvoiceDaysUntilDue: 7を直接書いている。numを通らない。apps/web/server/utils/auth.test.tsはresolveBillingConfigを実物のまま使うが、渡すruntimeConfigにinvoiceDaysUntilDueを含めておらず、invoiceDaysUntilDueの値を一切検査しない。
packages/api/src/stripe/invoices.ts の createDraftInvoice は受け取った daysUntilDue を days_until_due にそのまま渡すだけなので、値を決める分岐はこの関数の側には無い。
誰が何を誤るか
num の条件(有限かつ正)を変える人が、テストを頼りに変更の影響を確かめられない。2026-09-18 に feat/merge-auth-collection の d8feaca で、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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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