Repository navigation
fix(O6): 司機收入 API 漏回 total_cleaning_fee_cents(live E2E 抓到) - #36
Merged
Merged
Conversation
GET /api/driver/earnings 手動逐欄組 gin.H,O6 加在 repository.DriverEarnings 上的 清潔費分項沒被列進去 → 司機收入頁會看到「營業額 21500 − 手續費 3200 = 18300」, 但實得 22600,憑空多出 4300(正是清潔費)。 為什麼測試沒抓到:O6 的整合測試只覆蓋到 repository 層(SQL 與 struct 都對), handler 的 JSON 組裝沒有任何測試。admin 月報表直接回 struct(有 json tag)故不受影響, 只有這支手動組 map 的漏了。 修正:補上欄位,並把組裝抽成純函式 driverEarningsJSON 讓它可被單元測試釘住。 新增 TestDriverEarningsJSON:清潔費分項不可缺、等式「營業額 − 手續費 + 清潔費 = 實得」 成立、應付總公司不受清潔費影響、營業額不含清潔費。 反向驗證:拿掉該欄位 → 測試 FAIL。 live E2E 驗證(docker compose 全服務 + 真 OSRM):修復後回應含 total_cleaning_fee_cents =4300,等式 21500−3200+4300=22600 成立。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
live E2E 抓到的真 bug(docker compose 全服務 + 真 OSRM,六個 PR 合併後的第一次實跑)。
症狀
GET /api/driver/earnings的回應沒有total_cleaning_fee_cents:{"total_revenue_cents": 21500, "total_commission_cents": 3200, "driver_net_cents": 22600, ...}司機收入頁會看到「營業額 21500 − 手續費 3200 = 18300」,但實得 22600——憑空多出 4300,那正是清潔費,而 API 根本沒回。
根因
這支 handler 手動逐欄組
gin.H。O6 在repository.DriverEarnings上加了TotalCleaningFeeCents、SQL 也 SELECT 了,但 handler 的 map 沒列這一欄——repo struct 新增欄位不會自動出現在回應裡。為什麼測試沒抓到:O6 的整合測試只覆蓋 repository 層(
TestCleaningFeeReports驗的是 struct,且等式成立),handler 的 JSON 組裝沒有任何測試。admin 月報表不受影響:那支直接回 struct(有 json tag),欄位自動帶出。只有這支手動組 map 的漏了。
諷刺的是,我在 O6 的 PR 裡特別強調「報表分項必須跟計費同批做,否則司機收入頁的等式會對不上」——結果就漏在最後一哩。
修正
total_cleaning_fee_centsdriverEarningsJSON,讓「回應含哪些欄位」可被單元測試釘住TestDriverEarningsJSON:清潔費分項不可缺、等式「營業額 − 手續費 + 清潔費 = 實得」成立、應付總公司不受清潔費影響、營業額不含清潔費反向驗證:拿掉該欄位 → 測試 FAIL(
回應必須含 total_cleaning_fee_cents)。驗收
go build/vet/gofmt綠;TestDriverEarningsJSON綠。total_cleaning_fee_cents: 4300,等式21500 − 3200 + 4300 = 22600成立、營業額不含清潔費、應付總公司=手續費。🤖 Generated with Claude Code