Skip to content

Add MQTT location response tests#8

Open
augard wants to merge 1 commit intomainfrom
codex/test-gap-mqtt-location-response
Open

Add MQTT location response tests#8
augard wants to merge 1 commit intomainfrom
codex/test-gap-mqtt-location-response

Conversation

@augard
Copy link
Owner

@augard augard commented Mar 3, 2026

Summary

  • add VehicleMQTTLocationResponseTests to cover merged timestamp decoding
  • verify valid timestamp parsing yields expected UTC components even when location is null
  • ensure invalid timestamp formats throw and round-trip formatter via MergedDateFormatter

Testing

  • Not run (not requested)

Copilot AI review requested due to automatic review settings March 3, 2026 07:28
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

There is a problem with the Gemini CLI PR review. Please check the action logs for details.

@augmentcode
Copy link

augmentcode bot commented Mar 3, 2026

🤖 Augment PR Summary

Summary: Adds test coverage for MQTT location responses and merged timestamp decoding.

Changes:

  • Add VehicleMQTTLocationResponseTests to exercise latestUpdateTime parsing (yyyyMMddHHmmss) and Location: null decoding.
  • Assert the parsed Date matches expected UTC components.
  • Ensure invalid timestamp formats throw and validate MergedDateFormatter round-trip behavior.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

""".utf8
)

XCTAssertThrowsError(try JSONDecoder().decode(VehicleMQTTLocationResponse.self, from: data))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Fix This in Augment

🤖 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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 latestUpdateTime merged timestamp and asserting UTC date components.
  • Add a negative test ensuring invalid merged timestamp strings fail decoding.
  • Add a MergedDateFormatter round-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)!
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }.

Suggested change
utc.timeZone = TimeZone(secondsFromGMT: 0)!
utc.timeZone = .gmt

Copilot uses AI. Check for mistakes.
Comment on lines +66 to +68
let date = formatter.date(from: source)
XCTAssertNotNil(date)
XCTAssertEqual(formatter.string(from: date!), source)
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
""".utf8
)

XCTAssertThrowsError(try JSONDecoder().decode(VehicleMQTTLocationResponse.self, from: data))
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)")
}
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants