Repository navigation
test(constants): 救回電話驗證的邊界測試(來自未合併的 PR #42) - #49
Merged
Merged
Conversation
PR #42 的產品程式碼後來由別的 PR 進了 main,但它帶的兩個測試檔從未落地。 比對後只救這一個:internal/constants/phone_test.go。 main 目前對 NormalizePhone/IsValidPhone 的覆蓋只在 handler 層的 driver_profile_test.go,且只驗「4 碼失敗、正常手機通過」兩點。 本檔補上真正的邊界: - 有效:8 碼市話(下界)、市話含區碼、手機、+886 國際格式 - 無效:7 碼(短於下界)、16 碼(超過 E.164 上界)、全形數字、 夾雜英文字母、`+` 出現在開頭以外的位置、空字串 **刻意沒救 PR #42 的 internal/service/driver_phone_test.go**:它編碼的是當時的 行為假設,與 main 後來的決策衝突,跑起來會 FAIL—— - 它斷言 SetPhone("") 可清除電話,但 main 後來拍板「電話必填」而刻意擋空字串; - 它斷言 "0912-345-678a" 會被擋,但 main 是「先正規化再驗證」,字母會被 NormalizePhone 濾掉——這是 TODO 記載的刻意寬鬆(只驗位數不驗樣式, 硬綁格式會誤擋市話與境外號碼)。 把它救回來等於用過時的測試去推翻現行決策,所以丟棄。 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.
關閉舊 PR 前逐一比對的產出。#42 的產品程式碼後來由別的 PR 進了 main,
但它帶的兩個測試檔從未落地。比對後只救一個。
救回:
internal/constants/phone_test.gomain 目前對
NormalizePhone/IsValidPhone的覆蓋只在 handler 層的driver_profile_test.go,且只驗「4 碼失敗、正常手機通過」兩點。本檔補上真正的邊界:
+886國際格式+出現在開頭以外的位置、空字串刻意沒救:
internal/service/driver_phone_test.go它編碼的是當時的行為假設,與 main 後來的決策衝突,跑起來實測 FAIL:
SetPhone("")可清除電話"0912-345-678a"應被擋0912345678)把它救回來等於用過時的測試去推翻現行決策,所以丟棄。
驗收
gofmt乾淨、go build/go vet通過、go test ./internal/constants/綠(
TestNormalizePhone與 handler 層同名但屬不同 package,不衝突)。🤖 Generated with Claude Code