test(gift): 받은 선물 상세를 검증한다

This commit is contained in:
Yu Sung
2026-10-08 12:33:00 +09:00
parent 6c9d4e8d2a
commit fedebf825f
2 changed files with 319 additions and 0 deletions
+73
View File
@@ -0,0 +1,73 @@
import Foundation
private struct Check {
var assertions = 0
mutating func expect(_ condition: @autoclosure () -> Bool, _ message: String) {
assertions += 1
guard condition() else { fatalError("Assertion \(assertions) failed: \(message)") }
}
}
private func detail(
direction: String = "RECEIVED",
status: String = GiftStatus.delivered.rawValue,
recipientAddress: GiftRecipientAddressResponse? = GiftRecipientAddressResponse(name: "수령인", phoneNumber: "전화", address: "주소"),
undeliverableReason: String? = nil,
nestedApplicationNo: String? = "nested-only"
) -> GiftDetailResponse {
GiftDetailResponse(
applicationNo: "synthetic",
direction: direction,
status: status,
statusName: "상태",
giftInfo: GiftInfoResponse(
recipientCreatorNickname: nil,
senderNickname: "보낸이",
sizeName: "중형",
categoryName: "도서",
applicationNo: nestedApplicationNo,
paidCan: nil,
tracking: nil,
shippingRequestedAt: nil
),
senderInfo: nil,
recipientAddress: recipientAddress,
mailbox: nil,
trackingRequired: false,
recipientAddressRequired: true,
recipientAddressDeadlineAt: nil,
delivery: GiftDeliveryResponse(canceledAt: nil, undeliverableAt: nil, undeliverableReason: undeliverableReason),
statusTimeline: GiftProgressStep.allCases.map { GiftStatusTimelineResponse(status: $0.rawValue, statusName: "상태", occurredAt: nil) }
)
}
@main
enum ReceivedGiftDetailCheck {
static func main() {
var check = Check()
for status in GiftStatus.allCases {
check.expect(GiftDisplayPolicy.receivedDetail(from: detail(status: status.rawValue))?.status == status, "accepts \(status.rawValue)")
}
check.expect(GiftDisplayPolicy.receivedDetail(from: detail(direction: "SENT")) == nil, "rejects SENT")
check.expect(GiftDisplayPolicy.receivedDetail(from: detail(direction: "OTHER")) == nil, "rejects unknown direction")
check.expect(GiftDisplayPolicy.receivedDetail(from: detail(status: "UNKNOWN")) == nil, "rejects unknown status")
check.expect(GiftDisplayPolicy.sentDetail(from: detail(direction: "SENT"))?.applicationNo == "synthetic", "sent detail uses top-level applicationNo")
check.expect(GiftDisplayPolicy.sentDetail(from: detail(direction: "SENT", nestedApplicationNo: nil))?.applicationNo == "synthetic", "sent detail uses top-level applicationNo when nested is nil")
let model = GiftDisplayPolicy.receivedDetail(from: detail())!
check.expect(model.statusName == "상태", "maps statusName")
check.expect(model.senderNickname == "보낸이", "maps senderNickname")
check.expect(model.sizeName == "중형" && model.categoryName == "도서", "maps size and category")
check.expect(Set(Mirror(reflecting: model).children.compactMap { $0.label }) == ["status", "statusName", "undeliverableReason", "senderNickname", "sizeName", "categoryName", "shippingRequestedDateText", "recipientAddressRequired", "recipientAddress", "progress"], "stored-property allowlist")
check.expect(GiftDisplayPolicy.receivedDetail(from: detail(undeliverableReason: "수령인 부재"))?.undeliverableReason == "수령인 부재", "maps undeliverable reason")
check.expect(model.recipientAddress?.address == "주소", "maps present recipient address")
check.expect(GiftDisplayPolicy.receivedDetail(from: detail(recipientAddress: nil))?.recipientAddress == nil, "keeps nil recipient address nil")
let undeliverable = GiftDisplayPolicy.receivedDetail(from: detail(status: GiftStatus.undeliverable.rawValue, undeliverableReason: "주소 오류"))!
check.expect(!undeliverable.recipientAddressRequired && undeliverable.recipientAddress == nil, "suppresses undeliverable address")
check.expect(model.progress.map(\.step) == GiftProgressStep.allCases, "progress has five steps")
print("PASS ReceivedGiftDetailCheck assertions=\(check.assertions)")
}
}