-
Notifications
You must be signed in to change notification settings - Fork 2
test: add coverage for mqtt/status date parsing #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -356,4 +356,63 @@ final class MockVehicleDataTests: XCTestCase { | |||||||||||||||||||||||||||
| _ = try? decoder.decode(VehicleState.self, from: jsonData) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // MARK: - Date Parsing Coverage for Recent MQTT/Status Changes | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| func testTimeIntervalDateFormatterDecodesMillisecondsTimestampString() throws { | ||||||||||||||||||||||||||||
| struct TimestampPayload: Codable { | ||||||||||||||||||||||||||||
| @DateValue<TimeIntervalDateFormatter> var ts: Date | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| let json = #"{"ts":"1753344063251"}"# | ||||||||||||||||||||||||||||
| let payload = try JSONDecoder().decode(TimestampPayload.self, from: Data(json.utf8)) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| XCTAssertEqual(payload.ts.timeIntervalSince1970, 1_753_344_063.251, accuracy: 0.0001) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| func testMergedDateFormatterDecodesCompactTimestampString() throws { | ||||||||||||||||||||||||||||
| struct MergedPayload: Codable { | ||||||||||||||||||||||||||||
| @DateValue<MergedDateFormatter> var latestUpdateTime: Date | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| let json = #"{"latestUpdateTime":"20250901202513"}"# | ||||||||||||||||||||||||||||
| let payload = try JSONDecoder().decode(MergedPayload.self, from: Data(json.utf8)) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| var components = DateComponents() | ||||||||||||||||||||||||||||
| components.year = 2025 | ||||||||||||||||||||||||||||
| components.month = 9 | ||||||||||||||||||||||||||||
| components.day = 1 | ||||||||||||||||||||||||||||
| components.hour = 20 | ||||||||||||||||||||||||||||
| components.minute = 25 | ||||||||||||||||||||||||||||
| components.second = 13 | ||||||||||||||||||||||||||||
| components.timeZone = TimeZone(secondsFromGMT: 0) | ||||||||||||||||||||||||||||
| let expected = Calendar(identifier: .gregorian).date(from: components) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| let expected = Calendar(identifier: .gregorian).date(from: components) | |
| let expected = try XCTUnwrap(Calendar(identifier: .gregorian).date(from: components)) |
Copilot
AI
Mar 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testVehicleMQTTStatusResponseDecodesLatestUpdateTimeAndState doesn’t currently assert anything about latestUpdateTime/lastUpdateTime, so it won’t catch regressions in the CodingKeys mapping or MergedDateFormatter parsing. Add an assertion that response.lastUpdateTime matches the expected UTC date represented by "20250901202513" (or rename the test if time decoding is intentionally out of scope).
| var components = DateComponents() | |
| components.year = 2025 | |
| components.month = 9 | |
| components.day = 1 | |
| components.hour = 20 | |
| components.minute = 25 | |
| components.second = 13 | |
| components.timeZone = TimeZone(secondsFromGMT: 0) | |
| let expected = Calendar(identifier: .gregorian).date(from: components) | |
| XCTAssertEqual(response.lastUpdateTime, expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calendar(identifier: .gregorian).date(from:)returns an optionalDate; consider unwrapping the result so the test fails loudly if the components can’t be converted and the subsequent equality check is against a non-optional value.Severity: medium
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.