Skip to content

Commit ca1695f

Browse files
committed
update test for expired-now
1 parent 92fde87 commit ca1695f

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Modules/Tests/YosemiteTests/PointOfSale/POSCouponTests.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,34 @@ struct POSCouponTests {
3131

3232
@Test func test_isExpired_when_current_date_then_returns_true() {
3333
// Given
34-
let now = Date()
34+
let now = fixedDate(daysFromReference: 0)
3535
let coupon = POSCoupon(id: UUID(), code: "expired-now", dateExpires: now)
3636

3737
// Then
3838
#expect(coupon.isExpired == true, "A coupon expiring at the current time should be considered expired")
3939
}
4040
}
41+
42+
private extension POSCouponTests {
43+
/// Returns a fixed date with optional day offset
44+
/// - Parameter daysFromReference: Number of days to add/subtract from the reference date (0 = reference date)
45+
/// - Returns: A fixed date
46+
func fixedDate(daysFromReference: Int = 0) -> Date {
47+
var components = DateComponents()
48+
components.year = 2024
49+
components.month = 6
50+
components.day = 15
51+
components.hour = 12
52+
components.minute = 0
53+
components.second = 0
54+
components.timeZone = TimeZone(identifier: "UTC")
55+
56+
guard let baseDate = Calendar(identifier: .gregorian).date(from: components) else {
57+
// Fallback to the same date (2024-06-15 12:00:00 UTC) if calendar creation fails
58+
return Date(timeIntervalSince1970: 1718452800)
59+
}
60+
guard daysFromReference != 0 else { return baseDate }
61+
62+
return Calendar.current.date(byAdding: .day, value: daysFromReference, to: baseDate) ?? baseDate
63+
}
64+
}

0 commit comments

Comments
 (0)