CI / Build and test (push) Canceled after 0s
Documentation / Build documentation (push) Canceled after 0s
Documentation / Deploy to GitHub Pages (push) Canceled after 0s
This PR contains the work done to fix the live test suite, which started failing once the Amiibo API began returning Switch 2 games, and tidies the test suite around it.
### Changes
- **Live tests:** replaced the assertion that the first amiibo has no Switch 2 games with a usage check, matching the other platforms. The live data now includes Switch 2 entries for most amiibos.
- **Live tests:** refreshed the minimum item counts and the earliest accepted last-updated date to the values observed in October 2026, and documented in the README how to refresh them.
- **All tests:** moved test descriptions from `@Test("...")` strings into backticked function names, and aligned every case on the same GIVEN/WHEN/THEN structure.
- **Live client:** replaced the TODO about DocC inherited docs with a note. The compiler does not inherit documentation for protocol witnesses, so the repeated doc comments stay on purpose.
Reviewed-on: #32
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
85 lines
2.4 KiB
Swift
85 lines
2.4 KiB
Swift
// ===----------------------------------------------------------------------===
|
|
//
|
|
// This source file is part of the Amiibo Service open source project
|
|
//
|
|
// Copyright (c) 2026 Röck+Cöde VoF. and the Amiibo Service project authors
|
|
// Licensed under Apache license v2.0
|
|
//
|
|
// See LICENSE for license information
|
|
// See CONTRIBUTORS for the list of Amiibo Service project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
// ===----------------------------------------------------------------------===
|
|
|
|
import AmiiboService
|
|
import Foundation
|
|
import Testing
|
|
|
|
@Suite("Model conformances")
|
|
struct ModelConformanceTests {
|
|
|
|
// MARK: Identifiable tests
|
|
|
|
@Test
|
|
func `identifies an amiibo by its identifier`() {
|
|
// GIVEN
|
|
let amiibos = Fixtures.amiibos
|
|
|
|
// WHEN
|
|
// THEN
|
|
#expect(amiibos.map(\.id) == amiibos.map(\.identifier))
|
|
}
|
|
|
|
@Test
|
|
func `identifies key-name models by their keys`() {
|
|
// GIVEN
|
|
// WHEN
|
|
// THEN
|
|
#expect(Fixtures.amiiboSeries.map(\.id) == Fixtures.amiiboSeries.map(\.key))
|
|
#expect(Fixtures.amiiboTypes.map(\.id) == Fixtures.amiiboTypes.map(\.key))
|
|
#expect(Fixtures.gameCharacters.map(\.id) == Fixtures.gameCharacters.map(\.key))
|
|
#expect(Fixtures.gameSeries.map(\.id) == Fixtures.gameSeries.map(\.key))
|
|
}
|
|
|
|
// MARK: Codable tests
|
|
|
|
@Test
|
|
func `round-trips amiibos through JSON`() throws {
|
|
// GIVEN
|
|
let amiibos = Fixtures.amiibos
|
|
|
|
// WHEN
|
|
let decoded = try roundTrip(amiibos)
|
|
|
|
// THEN
|
|
#expect(decoded == amiibos)
|
|
#expect(decoded.first?.platform?.switch.first?.usages?.isEmpty == false)
|
|
}
|
|
|
|
@Test
|
|
func `round-trips key-name models through JSON`() throws {
|
|
// GIVEN
|
|
// WHEN
|
|
// THEN
|
|
#expect(try roundTrip(Fixtures.amiiboSeries) == Fixtures.amiiboSeries)
|
|
#expect(try roundTrip(Fixtures.amiiboTypes) == Fixtures.amiiboTypes)
|
|
#expect(try roundTrip(Fixtures.gameCharacters) == Fixtures.gameCharacters)
|
|
#expect(try roundTrip(Fixtures.gameSeries) == Fixtures.gameSeries)
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: - Helpers
|
|
|
|
private extension ModelConformanceTests {
|
|
|
|
// MARK: Functions
|
|
|
|
/// Encodes a value to JSON and decodes it back.
|
|
func roundTrip<Value: Codable>(_ value: Value) throws -> Value {
|
|
try JSONDecoder().decode(Value.self, from: JSONEncoder().encode(value))
|
|
}
|
|
|
|
}
|