Restructured every test case to follow the same GIVEN?WHEN/THEN structure with backticked, descriptive test names.

This commit is contained in:
javier committed 2026-10-25 22:25:59 +01:00
1 parent 3784c04df2
commit 647f63ee1e
5 files changed
+114 -120

No files matched your search

@@ -25,8 +25,8 @@ struct ISODateTimeTranscoderTests {
// MARK: Decode tests
@Test("decodes a timestamp as UTC")
func decodesTimestamp() throws {
@Test
func `decodes a timestamp as UTC`() throws {
// GIVEN
let string = "2026-07-24T12:34:56.123000"
@@ -37,8 +37,8 @@ struct ISODateTimeTranscoderTests {
#expect(abs(date.timeIntervalSince(.utc(2026, 7, 24, 12, 34, 56)) - 0.123) < 0.001)
}
@Test("decodes a date-only string as midnight UTC")
func decodesDate() throws {
@Test
func `decodes a date-only string as midnight UTC`() throws {
// GIVEN
let string = "2014-11-21"
@@ -49,10 +49,10 @@ struct ISODateTimeTranscoderTests {
#expect(date == .utc(2014, 11, 21))
}
@Test("throws a decoding error for an unsupported string", arguments: [
@Test(arguments: [
"", "2014-11", "2014-11-21T12:34:56", "2014-11-21T12:34:56Z", "21/11/2014", "yesterday"
])
func throwsForUnsupportedString(string: String) {
func `throws a decoding error for an unsupported string`(string: String) {
// GIVEN
// WHEN
// THEN
@@ -63,8 +63,8 @@ struct ISODateTimeTranscoderTests {
// MARK: Encode tests
@Test("encodes a date as a timestamp")
func encodesTimestamp() throws {
@Test
func `encodes a date as a timestamp`() throws {
// GIVEN
let date: Date = .utc(2026, 7, 24, 12, 34, 56)
@@ -22,8 +22,8 @@ struct AmiiboLiveClientTests {
// MARK: Server URL tests
@Test("resolves the server URL defined in the OpenAPI specification")
func serverURLResolves() throws {
@Test
func `resolves the server URL defined in the OpenAPI specification`() throws {
// GIVEN
// WHEN
let url = try Servers.Server1.url()
@@ -32,8 +32,8 @@ struct AmiiboLiveClientTests {
#expect(url.absoluteString == "https://www.amiiboapi.org/api")
}
@Test("uses the server URL from the OpenAPI specification")
func serverURLMatchesSpecification() throws {
@Test
func `uses the server URL from the OpenAPI specification`() throws {
// GIVEN
let expected = try Servers.Server1.url()
@@ -46,14 +46,11 @@ struct AmiiboLiveClientTests {
// MARK: Error mapping tests
@Test(
"maps an error thrown by the transport to the matching service error",
arguments: zip(
TransportErrors.thrown,
TransportErrors.expected
)
)
func mapsTransportError(
@Test(arguments: zip(
TransportErrors.thrown,
TransportErrors.expected
))
func `maps an error thrown by the transport to the matching service error`(
thrown: any Error,
expected: AmiiboServiceError
) async {
@@ -67,14 +64,11 @@ struct AmiiboLiveClientTests {
}
}
@Test(
"maps a response status to the matching service error",
arguments: zip(
Responses.failing,
Responses.expected
)
)
func mapsResponseStatus(
@Test(arguments: zip(
Responses.failing,
Responses.expected
))
func `maps a response status to the matching service error`(
response: (status: Int, json: String?),
expected: AmiiboServiceError
) async {
@@ -93,8 +87,8 @@ struct AmiiboLiveClientTests {
// MARK: Get Amiibos tests
@Test("returns amiibos sorted by identifier")
func getAmiibosSorted() async throws {
@Test
func `returns amiibos sorted by identifier`() async throws {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport(status: .ok, json: JSON.amiibos))
@@ -106,8 +100,8 @@ struct AmiiboLiveClientTests {
#expect(amiibos.map(\.name) == ["Mario", "Zelda"])
}
@Test("returns a single amiibo when the response holds an object")
func getAmiibosSingle() async throws {
@Test
func `returns a single amiibo when the response holds an object`() async throws {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport(status: .ok, json: JSON.amiibo))
@@ -128,8 +122,8 @@ struct AmiiboLiveClientTests {
#expect(amiibo.platform == nil)
}
@Test("returns no amiibos when the response holds null")
func getAmiibosNull() async throws {
@Test
func `returns no amiibos when the response holds null`() async throws {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport(status: .ok, json: JSON.amiibosNull))
@@ -140,8 +134,8 @@ struct AmiiboLiveClientTests {
#expect(amiibos.isEmpty)
}
@Test("returns no amiibos when the response holds an empty list")
func getAmiibosEmpty() async throws {
@Test
func `returns no amiibos when the response holds an empty list`() async throws {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport(status: .ok, json: JSON.amiibosEmpty))
@@ -152,8 +146,8 @@ struct AmiiboLiveClientTests {
#expect(amiibos.isEmpty)
}
@Test("decodes release dates as midnight UTC, and missing or null ones as nil")
func getAmiibosRelease() async throws {
@Test
func `decodes release dates as midnight UTC, and missing or null ones as nil`() async throws {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport(status: .ok, json: JSON.amiibos))
@@ -171,8 +165,8 @@ struct AmiiboLiveClientTests {
#expect(zelda.release.japan == nil)
}
@Test("maps related games and usages into the platform")
func getAmiibosPlatform() async throws {
@Test
func `maps related games and usages into the platform`() async throws {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport(status: .ok, json: JSON.amiiboWithGames))
@@ -192,8 +186,8 @@ struct AmiiboLiveClientTests {
#expect(platform.wiiU.first?.usages == nil)
}
@Test("encodes the amiibo filter as query parameters")
func getAmiibosQuery() async throws {
@Test
func `encodes the amiibo filter as query parameters`() async throws {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport { request in
let path = request.path ?? ""
@@ -229,8 +223,8 @@ struct AmiiboLiveClientTests {
))
}
@Test("omits nil filter values from the query")
func getAmiibosEmptyQuery() async throws {
@Test
func `omits nil filter values from the query`() async throws {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport { request in
#expect(request.path == "/amiibo")
@@ -245,8 +239,8 @@ struct AmiiboLiveClientTests {
// MARK: Key-name endpoints tests
@Test("returns amiibo series sorted by key")
func getAmiiboSeriesSorted() async throws {
@Test
func `returns amiibo series sorted by key`() async throws {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport(status: .ok, json: JSON.keyNameList))
@@ -257,8 +251,8 @@ struct AmiiboLiveClientTests {
#expect(series == [.init(key: "0x00", name: "Second"), .init(key: "0x01", name: "First")])
}
@Test("returns a single amiibo series when the response holds an object")
func getAmiiboSeriesSingle() async throws {
@Test
func `returns a single amiibo series when the response holds an object`() async throws {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport { request in
#expect(request.path == "/amiiboseries?key=0x01")
@@ -273,8 +267,8 @@ struct AmiiboLiveClientTests {
#expect(series == [.init(key: "0x01", name: "First")])
}
@Test("returns amiibo types sorted by key")
func getAmiiboTypesSorted() async throws {
@Test
func `returns amiibo types sorted by key`() async throws {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport { request in
#expect(request.path == "/type")
@@ -289,8 +283,8 @@ struct AmiiboLiveClientTests {
#expect(types == [.init(key: "0x00", name: "Second"), .init(key: "0x01", name: "First")])
}
@Test("returns game characters sorted by key")
func getGameCharactersSorted() async throws {
@Test
func `returns game characters sorted by key`() async throws {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport { request in
#expect(request.path == "/character?name=First")
@@ -305,8 +299,8 @@ struct AmiiboLiveClientTests {
#expect(characters == [.init(key: "0x00", name: "Second"), .init(key: "0x01", name: "First")])
}
@Test("returns game series sorted by key")
func getGameSeriesSorted() async throws {
@Test
func `returns game series sorted by key`() async throws {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport { request in
#expect(request.path == "/gameseries")
@@ -321,8 +315,8 @@ struct AmiiboLiveClientTests {
#expect(series == [.init(key: "0x00", name: "Second"), .init(key: "0x01", name: "First")])
}
@Test("throws notFound when a key-name endpoint matches nothing")
func getKeyNameNotFound() async {
@Test
func `throws notFound when a key-name endpoint matches nothing`() async {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport(status: .notFound, json: JSON.notFound))
@@ -335,8 +329,8 @@ struct AmiiboLiveClientTests {
// MARK: Get Last Updated tests
@Test("returns the last updated timestamp as UTC")
func getLastUpdated() async throws {
@Test
func `returns the last updated timestamp as UTC`() async throws {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport { request in
#expect(request.path == "/lastupdated")
@@ -351,8 +345,8 @@ struct AmiiboLiveClientTests {
#expect(lastUpdated == .utc(2026, 7, 24, 12, 34, 56))
}
@Test("throws notAvailable when the last updated endpoint fails")
func getLastUpdatedNotAvailable() async {
@Test
func `throws notAvailable when the last updated endpoint fails`() async {
// GIVEN
let client = AmiiboLiveClient(transport: StubTransport(status: .internalServerError))
@@ -20,8 +20,8 @@ struct FilterConformanceTests {
// MARK: Equatable tests
@Test("compares amiibo filters by value")
func amiiboFilterEquality() {
@Test
func `compares amiibo filters by value`() {
// GIVEN
// WHEN
// THEN
@@ -31,8 +31,8 @@ struct FilterConformanceTests {
#expect(AmiiboFilter() != AmiiboFilter(showGames: true))
}
@Test("compares key-name filters by value")
func keyNameFilterEquality() {
@Test
func `compares key-name filters by value`() {
// GIVEN
// WHEN
// THEN
@@ -46,8 +46,8 @@ struct FilterConformanceTests {
// MARK: Hashable tests
@Test("hashes equal filters alike")
func filterHashing() {
@Test
func `hashes equal filters alike`() {
// GIVEN
let amiiboFilters: Set = [AmiiboFilter(name: "zelda"), AmiiboFilter(name: "zelda"), AmiiboFilter(name: "mario")]
let seriesFilters: Set = [AmiiboSeriesFilter(key: "0x01"), AmiiboSeriesFilter(key: "0x01"), AmiiboSeriesFilter()]
@@ -21,8 +21,8 @@ struct ModelConformanceTests {
// MARK: Identifiable tests
@Test("identifies an amiibo by its identifier")
func amiiboID() {
@Test
func `identifies an amiibo by its identifier`() {
// GIVEN
let amiibos = Fixtures.amiibos
@@ -31,8 +31,8 @@ struct ModelConformanceTests {
#expect(amiibos.map(\.id) == amiibos.map(\.identifier))
}
@Test("identifies key-name models by their keys")
func keyNameIDs() {
@Test
func `identifies key-name models by their keys`() {
// GIVEN
// WHEN
// THEN
@@ -44,8 +44,8 @@ struct ModelConformanceTests {
// MARK: Codable tests
@Test("round-trips amiibos through JSON")
func amiibosRoundTrip() throws {
@Test
func `round-trips amiibos through JSON`() throws {
// GIVEN
let amiibos = Fixtures.amiibos
@@ -57,8 +57,8 @@ struct ModelConformanceTests {
#expect(decoded.first?.platform?.switch.first?.usages?.isEmpty == false)
}
@Test("round-trips key-name models through JSON")
func keyNameRoundTrip() throws {
@Test
func `round-trips key-name models through JSON`() throws {
// GIVEN
// WHEN
// THEN
@@ -21,8 +21,8 @@ struct AmiiboServiceMockTests {
// MARK: Get Amiibos tests
@Test("returns empty amiibos when mock provides an empty list")
func getAmiibosEmpty() async throws {
@Test
func `returns empty amiibos when mock provides an empty list`() async throws {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(amiibos: []))
@@ -33,8 +33,8 @@ struct AmiiboServiceMockTests {
#expect(amiibos.isEmpty)
}
@Test("returns amiibos when mock provides a list")
func getAmiibosList() async throws {
@Test
func `returns amiibos when mock provides a list`() async throws {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(amiibos: Fixtures.amiibos))
@@ -47,8 +47,8 @@ struct AmiiboServiceMockTests {
#expect(amiibos.first?.imageURL != nil)
}
@Test("throws notFound when mock provides no amiibos")
func getAmiibosNotFound() async {
@Test
func `throws notFound when mock provides no amiibos`() async {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient())
@@ -59,8 +59,8 @@ struct AmiiboServiceMockTests {
}
}
@Test("throws error for amiibos when mock is configured with error", arguments: Errors.all)
func getAmiibosThrows(error: AmiiboServiceError) async {
@Test(arguments: Errors.all)
func `throws error for amiibos when mock is configured with error`(error: AmiiboServiceError) async {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(error: error))
@@ -73,8 +73,8 @@ struct AmiiboServiceMockTests {
// MARK: Get Amiibo Series tests
@Test("returns empty amiibo series when mock provides an empty list")
func getAmiiboSeriesEmpty() async throws {
@Test
func `returns empty amiibo series when mock provides an empty list`() async throws {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(amiiboSeries: []))
@@ -85,8 +85,8 @@ struct AmiiboServiceMockTests {
#expect(amiiboSeries.isEmpty)
}
@Test("returns amiibo series when mock provides a list")
func getAmiiboSeriesList() async throws {
@Test
func `returns amiibo series when mock provides a list`() async throws {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(amiiboSeries: Fixtures.amiiboSeries))
@@ -97,8 +97,8 @@ struct AmiiboServiceMockTests {
#expect(amiiboSeries == Fixtures.amiiboSeries)
}
@Test("throws notFound when mock provides no amiibo series")
func getAmiiboSeriesNotFound() async {
@Test
func `throws notFound when mock provides no amiibo series`() async {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient())
@@ -109,8 +109,8 @@ struct AmiiboServiceMockTests {
}
}
@Test("throws error for amiibo series when mock is configured with error", arguments: Errors.all)
func getAmiiboSeriesThrows(error: AmiiboServiceError) async {
@Test(arguments: Errors.all)
func `throws error for amiibo series when mock is configured with error`(error: AmiiboServiceError) async {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(error: error))
@@ -123,8 +123,8 @@ struct AmiiboServiceMockTests {
// MARK: Get Amiibo Types tests
@Test("returns empty amiibo types when mock provides an empty list")
func getAmiiboTypesEmpty() async throws {
@Test
func `returns empty amiibo types when mock provides an empty list`() async throws {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(amiiboTypes: []))
@@ -135,8 +135,8 @@ struct AmiiboServiceMockTests {
#expect(amiiboTypes.isEmpty)
}
@Test("returns amiibo types when mock provides a list")
func getAmiiboTypesList() async throws {
@Test
func `returns amiibo types when mock provides a list`() async throws {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(amiiboTypes: Fixtures.amiiboTypes))
@@ -147,8 +147,8 @@ struct AmiiboServiceMockTests {
#expect(amiiboTypes == Fixtures.amiiboTypes)
}
@Test("throws notFound when mock provides no amiibo types")
func getAmiiboTypesNotFound() async {
@Test
func `throws notFound when mock provides no amiibo types`() async {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient())
@@ -159,8 +159,8 @@ struct AmiiboServiceMockTests {
}
}
@Test("throws error for amiibo types when mock is configured with error", arguments: Errors.all)
func getAmiiboTypesThrows(error: AmiiboServiceError) async {
@Test(arguments: Errors.all)
func `throws error for amiibo types when mock is configured with error`(error: AmiiboServiceError) async {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(error: error))
@@ -173,8 +173,8 @@ struct AmiiboServiceMockTests {
// MARK: Get Game Characters tests
@Test("returns empty game characters when mock provides an empty list")
func getGameCharactersEmpty() async throws {
@Test
func `returns empty game characters when mock provides an empty list`() async throws {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(gameCharacters: []))
@@ -185,8 +185,8 @@ struct AmiiboServiceMockTests {
#expect(gameCharacters.isEmpty)
}
@Test("returns game characters when mock provides a list")
func getGameCharactersList() async throws {
@Test
func `returns game characters when mock provides a list`() async throws {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(gameCharacters: Fixtures.gameCharacters))
@@ -197,8 +197,8 @@ struct AmiiboServiceMockTests {
#expect(gameCharacters == Fixtures.gameCharacters)
}
@Test("throws notFound when mock provides no game characters")
func getGameCharactersNotFound() async {
@Test
func `throws notFound when mock provides no game characters`() async {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient())
@@ -209,8 +209,8 @@ struct AmiiboServiceMockTests {
}
}
@Test("throws error for game characters when mock is configured with error", arguments: Errors.all)
func getGameCharactersThrows(error: AmiiboServiceError) async {
@Test(arguments: Errors.all)
func `throws error for game characters when mock is configured with error`(error: AmiiboServiceError) async {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(error: error))
@@ -223,8 +223,8 @@ struct AmiiboServiceMockTests {
// MARK: Get Game Series tests
@Test("returns empty game series when mock provides an empty list")
func getGameSeriesEmpty() async throws {
@Test
func `returns empty game series when mock provides an empty list`() async throws {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(gameSeries: []))
@@ -235,8 +235,8 @@ struct AmiiboServiceMockTests {
#expect(gameSeries.isEmpty)
}
@Test("returns game series when mock provides a list")
func getGameSeriesList() async throws {
@Test
func `returns game series when mock provides a list`() async throws {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(gameSeries: Fixtures.gameSeries))
@@ -247,8 +247,8 @@ struct AmiiboServiceMockTests {
#expect(gameSeries == Fixtures.gameSeries)
}
@Test("throws notFound when mock provides no game series")
func getGameSeriesNotFound() async {
@Test
func `throws notFound when mock provides no game series`() async {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient())
@@ -259,8 +259,8 @@ struct AmiiboServiceMockTests {
}
}
@Test("throws error for game series when mock is configured with error", arguments: Errors.all)
func getGameSeriesThrows(error: AmiiboServiceError) async {
@Test(arguments: Errors.all)
func `throws error for game series when mock is configured with error`(error: AmiiboServiceError) async {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(error: error))
@@ -273,8 +273,8 @@ struct AmiiboServiceMockTests {
// MARK: Get Last Updated tests
@Test("returns date when mock provides a last updated date")
func getLastUpdated() async throws {
@Test
func `returns date when mock provides a last updated date`() async throws {
// GIVEN
let expectedDate = Date(timeIntervalSince1970: 1_700_000_000)
let service = AmiiboService(client: AmiiboMockClient(lastUpdated: expectedDate))
@@ -286,8 +286,8 @@ struct AmiiboServiceMockTests {
#expect(lastUpdated == expectedDate)
}
@Test("throws notFound when mock provides no last updated date")
func getLastUpdatedNotFound() async {
@Test
func `throws notFound when mock provides no last updated date`() async {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient())
@@ -298,8 +298,8 @@ struct AmiiboServiceMockTests {
}
}
@Test("throws error for last updated when mock is configured with error", arguments: Errors.all)
func getLastUpdatedThrows(error: AmiiboServiceError) async {
@Test(arguments: Errors.all)
func `throws error for last updated when mock is configured with error`(error: AmiiboServiceError) async {
// GIVEN
let service = AmiiboService(client: AmiiboMockClient(error: error))