Conversation
|
There is a problem with the Gemini CLI PR review. Please check the action logs for details. |
🤖 Augment PR SummarySummary: Adds test coverage for MQTT location responses and merged timestamp decoding. Changes:
🤖 Was this summary useful? React with 👍 or 👎 |
| """.utf8 | ||
| ) | ||
|
|
||
| XCTAssertThrowsError(try JSONDecoder().decode(VehicleMQTTLocationResponse.self, from: data)) |
There was a problem hiding this comment.
This XCTAssertThrowsError will pass for any decoding failure, not specifically an invalid merged timestamp. Consider also asserting the thrown error is DateValue<MergedDateFormatter>.ParsingError.invalidString (or that its codingPath points at latestUpdateTime) to ensure the test is actually covering timestamp parsing.
Severity: low
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
|
|
||
| let date = formatter.date(from: source) | ||
| XCTAssertNotNil(date) | ||
| XCTAssertEqual(formatter.string(from: date!), source) |
There was a problem hiding this comment.
XCTAssertNotNil(date) doesn’t stop execution, so the subsequent date! can crash the test and hide the real assertion failure. Consider using XCTUnwrap(date) (or guard let) to keep failures reported as test failures instead of a runtime crash.
Severity: low
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
There was a problem hiding this comment.
Pull request overview
Adds a new XCTest suite to validate decoding of MQTT “merged” timestamp strings for VehicleMQTTLocationResponse, including behavior when the nested Location payload is null.
Changes:
- Add coverage for decoding a valid
latestUpdateTimemerged timestamp and asserting UTC date components. - Add a negative test ensuring invalid merged timestamp strings fail decoding.
- Add a
MergedDateFormatterround-trip test (string → date → string).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| XCTAssertNil(response.state.vehicle.location) | ||
|
|
||
| var utc = Calendar(identifier: .gregorian) | ||
| utc.timeZone = TimeZone(secondsFromGMT: 0)! |
There was a problem hiding this comment.
Avoid forcing unwrap on TimeZone(secondsFromGMT: 0) in tests; if it ever returns nil this will crash the test process instead of producing a clean failure. Prefer using TimeZone.gmt (if available) or guard let tz = TimeZone(secondsFromGMT: 0) else { XCTFail(...); return }.
| utc.timeZone = TimeZone(secondsFromGMT: 0)! | |
| utc.timeZone = .gmt |
| let date = formatter.date(from: source) | ||
| XCTAssertNotNil(date) | ||
| XCTAssertEqual(formatter.string(from: date!), source) |
There was a problem hiding this comment.
This test force-unwraps date after XCTAssertNotNil(date), which can still produce a crash with a less-informative failure if the assertion is skipped/continues. Prefer guard let date else { XCTFail("..."); return } and then use the non-optional date for the round-trip assertion.
| let date = formatter.date(from: source) | |
| XCTAssertNotNil(date) | |
| XCTAssertEqual(formatter.string(from: date!), source) | |
| guard let date = formatter.date(from: source) else { | |
| XCTFail("Expected MergedDateFormatter to produce a date from valid source string") | |
| return | |
| } | |
| XCTAssertEqual(formatter.string(from: date), source) |
| """.utf8 | ||
| ) | ||
|
|
||
| XCTAssertThrowsError(try JSONDecoder().decode(VehicleMQTTLocationResponse.self, from: data)) |
There was a problem hiding this comment.
XCTAssertThrowsError here only verifies that decoding fails, but not that it fails for the expected reason (invalid merged timestamp). Consider asserting the thrown error is DateValue<MergedDateFormatter>.ParsingError.invalidString (or at least that it contains the offending string/codingPath) so the test won’t pass if decoding starts failing for an unrelated reason.
| XCTAssertThrowsError(try JSONDecoder().decode(VehicleMQTTLocationResponse.self, from: data)) | |
| XCTAssertThrowsError(try JSONDecoder().decode(VehicleMQTTLocationResponse.self, from: data)) { error in | |
| // Ensure the error comes from the merged date parsing and relates to the invalid timestamp | |
| if let parsingError = error as? DateValue<MergedDateFormatter>.ParsingError { | |
| let description = String(describing: parsingError) | |
| XCTAssertTrue( | |
| description.contains("2025-09-01T14:27:33Z"), | |
| "Expected parsing error to reference invalid timestamp, got: \(description)" | |
| ) | |
| } else { | |
| XCTFail("Expected DateValue<MergedDateFormatter>.ParsingError, got \(type(of: error)): \(error)") | |
| } | |
| } |
Summary
VehicleMQTTLocationResponseTeststo cover merged timestamp decodingMergedDateFormatterTesting