Siri: favourite price + favourite directions (top favourite per fuel); trim to 10 AppShortcuts (Apple cap)

This commit is contained in:
FuelBoard Contributor
2026-08-14 14:24:20 +01:00
parent aed99e3f32
commit b458d92972
4 changed files with 280 additions and 39 deletions
@@ -485,6 +485,55 @@ final class SiriCheapestLookupTests: XCTestCase {
XCTAssertTrue(url.absoluteString.hasPrefix("https://maps.apple.com/"))
}
// MARK: Favourite selection
private func favourite(_ id: String, _ fuel: FuelType, _ prices: [FuelType: Double]) -> FavouriteEntry {
FavouriteEntry(station: station(id, lat: 53.7, lng: -1.8, prices), fuel: fuel)
}
// The top favourite for a fuel is the FIRST entry in the manual favourites
// order for that fuel (the drag-and-drop order from the Favourites tab;
// per-fuel blocks keep their position, so array order = per-fuel order).
func testTopFavouriteIsFirstInManualOrderPerFuel() {
let favs = [
favourite("a", .e10, [.e10: 130]),
favourite("b", .diesel, [.diesel: 145]),
favourite("c", .e10, [.e10: 120]),
]
XCTAssertEqual(SiriCheapestLookup.topFavourite(in: favs, from: [], fuel: .e10)?.station.id, "a")
XCTAssertEqual(SiriCheapestLookup.topFavourite(in: favs, from: [], fuel: .diesel)?.station.id, "b")
XCTAssertNil(SiriCheapestLookup.topFavourite(in: favs, from: [], fuel: .e5))
}
// The favourite's cached price snapshot is refreshed from the current
// station dump when the station is present.
func testTopFavouriteRefreshesPriceFromDump() {
let favs = [favourite("a", .e10, [.e10: 130])]
let dump = [station("a", lat: 53.7, lng: -1.8, [.e10: 122.9])]
let top = SiriCheapestLookup.topFavourite(in: favs, from: dump, fuel: .e10)
XCTAssertEqual(top?.station.prices[.e10], 122.9)
}
// Stations missing from the dump keep their cached snapshot, so the
// favourite still answers offline or when the station isn't in the
// GOV.UK set.
func testTopFavouriteKeepsCachedSnapshotWhenMissingFromDump() {
let favs = [favourite("a", .e10, [.e10: 130])]
let top = SiriCheapestLookup.topFavourite(in: favs, from: [], fuel: .e10)
XCTAssertEqual(top?.station.prices[.e10], 130)
}
// Manual reorder (the Favourites tab's drag-and-drop) changes which
// favourite is "top" the Siri answer follows the widget order.
func testTopFavouriteFollowsManualReorder() {
let favs = [
favourite("a", .e10, [.e10: 130]),
favourite("c", .e10, [.e10: 120]),
]
let reordered = FuelStore.reorderedFavourites(favs, fuel: .e10, fromOffsets: IndexSet(integer: 0), toOffset: 2)
XCTAssertEqual(SiriCheapestLookup.topFavourite(in: reordered, from: [], fuel: .e10)?.station.id, "c")
}
func testFreshnessLabelUsesDataUpdatedStamp() {
let label = SiriCheapestLookup.freshnessLabel(
updated: "2026-08-14T10:31:36.000Z",