diff --git a/Tests/AmiiboService/Tests/Public/Services/AmiiboServiceLiveTests.swift b/Tests/AmiiboService/Tests/Public/Services/AmiiboServiceLiveTests.swift index 777fb9d..565dc68 100644 --- a/Tests/AmiiboService/Tests/Public/Services/AmiiboServiceLiveTests.swift +++ b/Tests/AmiiboService/Tests/Public/Services/AmiiboServiceLiveTests.swift @@ -30,607 +30,32 @@ struct AmiiboServiceLiveTests { // MARK: Functions tests #if swift(>=6.2) - @Test - func `get Amiibo items`() async throws { - // GIVEN - // WHEN - let amiibos = try await service.getAmiibos() - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 885) - #expect(amiibos.first?.identifier == "0000000000000002") - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.identifier == "3f000000042e0002") - #expect(amiibos.last?.platform == nil) + @Test(arguments: zip( + Input.amiibos, + Output.amiibos + )) + func `get amiibos`( + filter: AmiiboFilter, + expects numberOfItems: Int + ) async throws { + try await assertAmiibos( + with: filter, + expects: numberOfItems + ) } - @Test - func `get Amiibo items by an existing identifier`() async throws { - // GIVEN - let identifier = "0000000000000002" - - // WHEN - let amiibos = try await service.getAmiibos(.init(identifier: identifier)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 1) - #expect(amiibos.first?.identifier == identifier) - #expect(amiibos.first?.platform == nil) - } - - @Test - func `get Amiibo items by a non-existing identifier`() async throws { - // GIVEN - let identifier = "0000000000000000" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.decoding) { - try await service.getAmiibos(.init(identifier: identifier)) - } - } - - @Test - func `get Amiibo items by an incomplete identifier`() async throws { - // GIVEN - let identifier = "0000000" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.decoding) { - try await service.getAmiibos(.init(identifier: identifier)) - } - } - - @Test - func `get Amiibo items by an empty identifier`() async throws { - // GIVEN - let identifier = "" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.badRequest) { - try await service.getAmiibos(.init(identifier: identifier)) - } - } - - @Test - func `get Amiibo items by an existing name`() async throws { - // GIVEN - let name = "zelda" - - // WHEN - let amiibos = try await service.getAmiibos(.init(name: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 5) - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.platform == nil) - - let nameFirst = try #require(amiibos.first?.name.lowercased()) - let nameLast = try #require(amiibos.last?.name.lowercased()) - - #expect(nameFirst.contains(name)) - #expect(nameLast.contains(name)) - } - - @Test - func `get Amiibo items by a non-existing name`() async throws { - // GIVEN - let name = "Something" - - // WHEN - let amiibos = try await service.getAmiibos(.init(name: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test - func `get Amiibo items by an incomplete name`() async throws { - // GIVEN - let name = "zel" - - // WHEN - let amiibos = try await service.getAmiibos(.init(name: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 7) - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.platform == nil) - - let nameFirst = try #require(amiibos.first?.name.lowercased()) - let nameLast = try #require(amiibos.last?.name.lowercased()) - - #expect(nameFirst.contains(name)) - #expect(nameLast.contains(name)) - } - - @Test - func `get Amiibo items by an empty name`() async throws { - // GIVEN - let name = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(name: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 885) - } - - @Test - func `get Amiibo items by an existing type key`() async throws { - // GIVEN - let key = "0x00" - - // WHEN - let amiibos = try await service.getAmiibos(.init(type: key)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 235) - #expect(amiibos.first?.type == "Figure") - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.type == "Figure") - #expect(amiibos.last?.platform == nil) - } - - @Test - func `get Amiibo items by an existing type name`() async throws { - // GIVEN - let name = "figure" - - // WHEN - let amiibos = try await service.getAmiibos(.init(type: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 235) - #expect(amiibos.first?.type == "Figure") - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.type == "Figure") - #expect(amiibos.last?.platform == nil) - } - - @Test - func `get Amiibo items by a non-existing type key`() async throws { - // GIVEN - let key = "0x0f" - - // WHEN - let amiibos = try await service.getAmiibos(.init(type: key)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test - func `get Amiibo items by a non-existing type name`() async throws { - // GIVEN - let name = "something" - - // WHEN - let amiibos = try await service.getAmiibos(.init(type: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test - func `get Amiibo items by an incomplete type key`() async throws { - // GIVEN - let key = "0x" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.badRequest) { - try await service.getAmiibos(.init(type: key)) - } - } - - @Test - func `get Amiibo items by an incomplete type name`() async throws { - // GIVEN - let name = "fig" - - // WHEN - let amiibos = try await service.getAmiibos(.init(type: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test - func `get Amiibo items by an empty type key`() async throws { - // GIVEN - let key = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(type: key)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test - func `get Amiibo items by an empty type name`() async throws { - // GIVEN - let name = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(type: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test - func `get Amiibo items by an existing series key`() async throws { - // GIVEN - let key = "0x00" - - // WHEN - let amiibos = try await service.getAmiibos(.init(series: key)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 96) - #expect(amiibos.first?.series == "Super Smash Bros.") - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.series == "Super Smash Bros.") - #expect(amiibos.last?.platform == nil) - } - - @Test - func `get Amiibo items by an existing series name`() async throws { - // GIVEN - let name = "Legend Of Zelda" - - // WHEN - let amiibos = try await service.getAmiibos(.init(series: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 26) - #expect(amiibos.first?.series == name) - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.series == name) - #expect(amiibos.last?.platform == nil) - } - - @Test - func `get Amiibo items by a non-existing series key`() async throws { - // GIVEN - let key = "0xf9" - - // WHEN - let amiibos = try await service.getAmiibos(.init(series: key)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test - func `get Amiibo items by a non-existing series name`() async throws { - // GIVEN - let name = "something" - - // WHEN - let amiibos = try await service.getAmiibos(.init(series: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test - func `get Amiibo items by an incomplete series key`() async throws { - // GIVEN - let key = "0x" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.badRequest) { - try await service.getAmiibos(.init(series: key)) - } - } - - @Test - func `get Amiibo items by an incomplete series name`() async throws { - // GIVEN - let name = "fig" - - // WHEN - let amiibos = try await service.getAmiibos(.init(series: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 25) - } - - @Test - func `get Amiibo items by an empty series key`() async throws { - // GIVEN - let key = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(series: key)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 885) - } - - @Test - func `get Amiibo items by an empty series name`() async throws { - // GIVEN - let name = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(series: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 885) - } - - @Test - func `get Amiibo items by an existing game character key`() async throws { - // GIVEN - let key = "0x00" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameCharacter: key)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 11) - #expect(amiibos.first?.gameCharacter == "Mario") - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.gameCharacter == "Mario") - #expect(amiibos.last?.platform == nil) - } - - @Test - func `get Amiibo items by an existing game character name`() async throws { - // GIVEN - let name = "Zelda" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameCharacter: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 6) - #expect(amiibos.first?.gameCharacter == name) - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.gameCharacter == name) - #expect(amiibos.last?.platform == nil) - } - - @Test - func `get Amiibo items by a non-existing game character key`() async throws { - // GIVEN - let key = "0xf9" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameCharacter: key)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test - func `get Amiibo items by a non-existing game character name`() async throws { - // GIVEN - let name = "something" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameCharacter: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test - func `get Amiibo items by an incomplete game character key`() async throws { - // GIVEN - let key = "0x" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.badRequest) { - try await service.getAmiibos(.init(gameCharacter: key)) - } - } - - @Test - func `get Amiibo items by an incomplete game character name`() async throws { - // GIVEN - let name = "fig" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameCharacter: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test - func `get Amiibo items by an empty game character key`() async throws { - // GIVEN - let key = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameCharacter: key)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 885) - } - - @Test - func `get Amiibo items by an empty game character name`() async throws { - // GIVEN - let name = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameCharacter: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 885) - } - - @Test - func `get Amiibo items by an existing game series key`() async throws { - // GIVEN - let key = "0x00" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameSeries: key)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 45) - #expect(amiibos.first?.gameSeries == "Super Mario") - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.gameSeries == "Super Mario") - #expect(amiibos.last?.platform == nil) - } - - @Test - func `get Amiibo items by an existing game series name`() async throws { - // GIVEN - let name = "The Legend of Zelda" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameSeries: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 32) - #expect(amiibos.first?.gameSeries == name) - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.gameSeries == name) - #expect(amiibos.last?.platform == nil) - } - - @Test - func `get Amiibo items by a non-existing game series key`() async throws { - // GIVEN - let key = "0xf9" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameSeries: key)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test - func `get Amiibo items by a non-existing game series name`() async throws { - // GIVEN - let name = "something" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameSeries: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test - func `get Amiibo items by an incomplete game series key`() async throws { - // GIVEN - let key = "0x" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.badRequest) { - try await service.getAmiibos(.init(gameSeries: key)) - } - } - - @Test - func `get Amiibo items by an incomplete game series name`() async throws { - // GIVEN - let name = "Super" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameSeries: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 143) - } - - @Test - func `get Amiibo items by an empty game series key`() async throws { - // GIVEN - let key = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameSeries: key)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 885) - } - - @Test - func `get Amiibo items by an empty game series name`() async throws { - // GIVEN - let name = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameSeries: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 885) - } - - @Test - func `get Amiibo items with games data`() async throws { - // GIVEN - // WHEN - let amiibos = try await service.getAmiibos(.init(showGames: true)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 885) - #expect(amiibos.first?.platform != nil) - #expect(amiibos.first?.platform?.switch.isEmpty == false) - #expect(amiibos.first?.platform?.switch.first?.usages == nil) - #expect(amiibos.first?.platform?.threeDS.isEmpty == false) - #expect(amiibos.first?.platform?.threeDS.first?.usages == nil) - #expect(amiibos.first?.platform?.wiiU.isEmpty == false) - #expect(amiibos.first?.platform?.wiiU.first?.usages == nil) - #expect(amiibos.last?.platform != nil) - } - - @Test - func `get Amiibo items with games and usages data`() async throws { - // GIVEN - // WHEN - let amiibos = try await service.getAmiibos(.init(showUsage: true)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 885) - #expect(amiibos.first?.platform != nil) - #expect(amiibos.first?.platform?.switch.isEmpty == false) - #expect(amiibos.first?.platform?.switch.first?.usages?.isEmpty == false) - #expect(amiibos.first?.platform?.threeDS.isEmpty == false) - #expect(amiibos.first?.platform?.threeDS.first?.usages?.isEmpty == false) - #expect(amiibos.first?.platform?.wiiU.isEmpty == false) - #expect(amiibos.first?.platform?.wiiU.first?.usages?.isEmpty == false) - #expect(amiibos.last?.platform != nil) + @Test(arguments: zip( + Input.amiibosThrows, + Output.amiibosThrows + )) + func `get amiibos throws`( + filter: AmiiboFilter, + expects error: AmiiboServiceError + ) async throws { + try await assertsAmiibosThrows( + error: error, + when: filter + ) } @Test(arguments: zip( @@ -754,609 +179,34 @@ struct AmiiboServiceLiveTests { ) } #else - @Test("Get Amiibo items") - func getAmiibos() async throws { - // GIVEN - // WHEN - let amiibos = try await service.getAmiibos() - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 889) - #expect(amiibos.first?.identifier == "0000000000000002") - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.identifier == "3f000000042e0002") - #expect(amiibos.last?.platform == nil) + @Test("get amiibos", arguments: zip( + Input.amiibos, + Output.amiibos + )) + func getAmiibos( + filter: AmiiboFilter, + expects numberOfItems: Int + ) async throws { + try await assertAmiibos( + with: filter, + expects: numberOfItems + ) } - @Test("Get Amiibo items by an existing identifier") - func getAmiibos_byExistingIdentifier() async throws { - // GIVEN - let identifier = "0000000000000002" - - // WHEN - let amiibos = try await service.getAmiibos(.init(identifier: identifier)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 1) - #expect(amiibos.first?.identifier == identifier) - #expect(amiibos.first?.platform == nil) + @Test("get amiibos throws", arguments: zip( + Input.amiibosThrows, + Output.amiibosThrows + )) + func getAmiibosThrows( + filter: AmiiboFilter, + expects error: AmiiboServiceError + ) async throws { + try await assertsAmiibosThrows( + error: error, + when: filter + ) } - @Test("Get Amiibo items by a non-existing identifier") - func getAmiibos_byNonExistingIdentifier() async throws { - // GIVEN - let identifier = "0000000000000000" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.decoding) { - try await service.getAmiibos(.init(identifier: identifier)) - } - } - - @Test("Get Amiibo items by an incomplete identifier") - func getAmiibos_byIncompleteIdentifier() async throws { - // GIVEN - let identifier = "0000000" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.decoding) { - try await service.getAmiibos(.init(identifier: identifier)) - } - } - - @Test("Get Amiibo items by an empty identifier") - func getAmiibos_byEmptyIdentifier() async throws { - // GIVEN - let identifier = "" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.badRequest) { - try await service.getAmiibos(.init(identifier: identifier)) - } - } - - @Test("Get Amiibo items by an existing name") - func getAmiibos_byExistingName() async throws { - // GIVEN - let name = "zelda" - - // WHEN - let amiibos = try await service.getAmiibos(.init(name: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 5) - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.platform == nil) - - let nameFirst = try #require(amiibos.first?.name.lowercased()) - let nameLast = try #require(amiibos.last?.name.lowercased()) - - #expect(nameFirst.contains(name)) - #expect(nameLast.contains(name)) - } - - @Test("Get Amiibo items by a non-existing name") - func getAmiibos_byNonExistingName() async throws { - // GIVEN - let name = "Something" - - // WHEN - let amiibos = try await service.getAmiibos(.init(name: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test("Get Amiibo items by an incomplete name") - func getAmiibos_byIncompleteName() async throws { - // GIVEN - let name = "zel" - - // WHEN - let amiibos = try await service.getAmiibos(.init(name: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 7) - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.platform == nil) - - let nameFirst = try #require(amiibos.first?.name.lowercased()) - let nameLast = try #require(amiibos.last?.name.lowercased()) - - #expect(nameFirst.contains(name)) - #expect(nameLast.contains(name)) - } - - @Test("Get Amiibo items by an empty name") - func getAmiibos_byEmptyName() async throws { - // GIVEN - let name = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(name: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 889) - } - - @Test("Get Amiibo items by an existing type key") - func getAmiibos_byExistingTypeKey() async throws { - // GIVEN - let key = "0x00" - - // WHEN - let amiibos = try await service.getAmiibos(.init(type: key)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 235) - #expect(amiibos.first?.type == "Figure") - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.type == "Figure") - #expect(amiibos.last?.platform == nil) - } - - @Test("Get Amiibo items by an existing type name") - func getAmiibos_byExistingTypeName() async throws { - // GIVEN - let name = "figure" - - // WHEN - let amiibos = try await service.getAmiibos(.init(type: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 235) - #expect(amiibos.first?.type == "Figure") - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.type == "Figure") - #expect(amiibos.last?.platform == nil) - } - - @Test("Get Amiibo items by a non-existing type key") - func getAmiibos_byNonExistingTypeKey() async throws { - // GIVEN - let key = "0x0f" - - // WHEN - let amiibos = try await service.getAmiibos(.init(type: key)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test("Get Amiibo items by a non-existing type name") - func getAmiibos_byNonExistingTypeName() async throws { - // GIVEN - let name = "something" - - // WHEN - let amiibos = try await service.getAmiibos(.init(type: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test("Get Amiibo items by an incomplete type key") - func getAmiibos_byIncompleteTypeKey() async throws { - // GIVEN - let key = "0x" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.badRequest) { - try await service.getAmiibos(.init(type: key)) - } - } - - @Test("Get Amiibo items by an incomplete type name") - func getAmiibos_byIncompleteTypeName() async throws { - // GIVEN - let name = "fig" - - // WHEN - let amiibos = try await service.getAmiibos(.init(type: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test("Get Amiibo items by an empty type key") - func getAmiibos_byEmptyTypeKey() async throws { - // GIVEN - let key = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(type: key)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test("Get Amiibo items by an empty type name") - func getAmiibos_byEmptyTypeName() async throws { - // GIVEN - let name = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(type: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test("Get Amiibo items by an existing series key") - func getAmiibos_byExistingSeriesKey() async throws { - // GIVEN - let key = "0x00" - - // WHEN - let amiibos = try await service.getAmiibos(.init(series: key)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 96) - #expect(amiibos.first?.series == "Super Smash Bros.") - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.series == "Super Smash Bros.") - #expect(amiibos.last?.platform == nil) - } - - @Test("Get Amiibo items by an existing series name") - func getAmiibos_byExistingSeriesName() async throws { - // GIVEN - let name = "Legend Of Zelda" - - // WHEN - let amiibos = try await service.getAmiibos(.init(series: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 26) - #expect(amiibos.first?.series == name) - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.series == name) - #expect(amiibos.last?.platform == nil) - } - - @Test("Get Amiibo items by a non-existing series key") - func getAmiibos_byNonExistingSeriesKey() async throws { - // GIVEN - let key = "0xf9" - - // WHEN - let amiibos = try await service.getAmiibos(.init(series: key)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test("Get Amiibo items by a non-existing series name") - func getAmiibos_byNonExistingSeriesName() async throws { - // GIVEN - let name = "something" - - // WHEN - let amiibos = try await service.getAmiibos(.init(series: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test("Get Amiibo items by an incomplete series key") - func getAmiibos_byIncompleteSeriesKey() async throws { - // GIVEN - let key = "0x" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.badRequest) { - try await service.getAmiibos(.init(series: key)) - } - } - - @Test("Get Amiibo items by an incomplete series name") - func getAmiibos_byIncompleteSeriesName() async throws { - // GIVEN - let name = "fig" - - // WHEN - let amiibos = try await service.getAmiibos(.init(series: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 25) - } - - @Test("Get Amiibo items by an empty series key") - func getAmiibos_byEmptySeriesKey() async throws { - // GIVEN - let key = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(series: key)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 889) - } - - @Test("Get Amiibo items by an empty series name") - func getAmiibos_byEmptySeriesName() async throws { - // GIVEN - let name = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(series: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 889) - } - - @Test("Get Amiibo items by an existing game character key") - func getAmiibos_byExistingGameCharacterKey() async throws { - // GIVEN - let key = "0x00" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameCharacter: key)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 12) - #expect(amiibos.first?.gameCharacter == "Mario") - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.gameCharacter == "Mario") - #expect(amiibos.last?.platform == nil) - } - - @Test("Get Amiibo items by an existing game character name") - func getAmiibos_byExistingGameCharacterName() async throws { - // GIVEN - let name = "Zelda" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameCharacter: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 6) - #expect(amiibos.first?.gameCharacter == name) - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.gameCharacter == name) - #expect(amiibos.last?.platform == nil) - } - - @Test("Get Amiibo items by a non-existing game character key") - func getAmiibos_byNonExistingGameCharacterKey() async throws { - // GIVEN - let key = "0xf9" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameCharacter: key)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test("Get Amiibo items by a non-existing game character name") - func getAmiibos_byNonExistingGameCharacterName() async throws { - // GIVEN - let name = "something" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameCharacter: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test("Get Amiibo items by an incomplete game character key") - func getAmiibos_byIncompleteGameCharacterKey() async throws { - // GIVEN - let key = "0x" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.badRequest) { - try await service.getAmiibos(.init(gameCharacter: key)) - } - } - - @Test("Get Amiibo items by an incomplete game character name") - func getAmiibos_byIncompleteGameCharacterName() async throws { - // GIVEN - let name = "fig" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameCharacter: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test("Get Amiibo items by an empty game character key") - func getAmiibos_byEmptyGameCharacterKey() async throws { - // GIVEN - let key = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameCharacter: key)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 889) - } - - @Test("Get Amiibo items by an empty game character name") - func getAmiibos_byEmptyGameCharacterName() async throws { - // GIVEN - let name = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameCharacter: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 889) - } - - @Test("Get Amiibo items by an existing game series key") - func getAmiibos_byExistingGameSeriesKey() async throws { - // GIVEN - let key = "0x00" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameSeries: key)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 49) - #expect(amiibos.first?.gameSeries == "Super Mario") - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.gameSeries == "Super Mario") - #expect(amiibos.last?.platform == nil) - } - - @Test("Get Amiibo items by an existing game series name") - func getAmiibos_byExistingGameSeriesName() async throws { - // GIVEN - let name = "The Legend of Zelda" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameSeries: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 32) - #expect(amiibos.first?.gameSeries == name) - #expect(amiibos.first?.platform == nil) - #expect(amiibos.last?.gameSeries == name) - #expect(amiibos.last?.platform == nil) - } - - @Test("Get Amiibo items by a non-existing game series key") - func getAmiibos_byNonExistingGameSeriesKey() async throws { - // GIVEN - let key = "0xf9" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameSeries: key)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test("Get Amiibo items by a non-existing game series name") - func getAmiibos_byNonExistingGameSeriesName() async throws { - // GIVEN - let name = "something" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameSeries: name)) - - // THEN - #expect(amiibos.isEmpty) - } - - @Test("Get Amiibo items by an incomplete game series key") - func getAmiibos_byIncompleteGameSeriesKey() async throws { - // GIVEN - let key = "0x" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.badRequest) { - try await service.getAmiibos(.init(gameSeries: key)) - } - } - - @Test("Get Amiibo items by an incomplete game series name") - func getAmiibos_byIncompleteGameSeriesName() async throws { - // GIVEN - let name = "Super" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameSeries: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 147) - } - - @Test("Get Amiibo items by an empty game series key") - func getAmiibos_byEmptyGameSeriesKey() async throws { - // GIVEN - let key = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameSeries: key)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 889) - } - - @Test("Get Amiibo items by an empty game series name") - func getAmiibos_byEmptyGameSeriesName() async throws { - // GIVEN - let name = "" - - // WHEN - let amiibos = try await service.getAmiibos(.init(gameSeries: name)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 889) - } - - @Test("Get Amiibo items with games data") - func getAmiibos_withGamesData() async throws { - // GIVEN - // WHEN - let amiibos = try await service.getAmiibos(.init(showGames: true)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 889) - #expect(amiibos.first?.platform != nil) - #expect(amiibos.first?.platform?.switch.isEmpty == false) - #expect(amiibos.first?.platform?.switch.first?.usages == nil) - #expect(amiibos.first?.platform?.threeDS.isEmpty == false) - #expect(amiibos.first?.platform?.threeDS.first?.usages == nil) - #expect(amiibos.first?.platform?.wiiU.isEmpty == false) - #expect(amiibos.first?.platform?.wiiU.first?.usages == nil) - #expect(amiibos.last?.platform != nil) - } - - @Test("Get Amiibo items with games and usages data") - func getAmiibos_withGamesAndUsagesData() async throws { - // GIVEN - // WHEN - let amiibos = try await service.getAmiibos(.init(showUsage: true)) - - // THEN - #expect(!amiibos.isEmpty) - #expect(amiibos.count == 889) - #expect(amiibos.first?.platform != nil) - #expect(amiibos.first?.platform?.switch.isEmpty == false) - #expect(amiibos.first?.platform?.switch.first?.usages?.isEmpty == false) - #expect(amiibos.first?.platform?.threeDS.isEmpty == false) - #expect(amiibos.first?.platform?.threeDS.first?.usages?.isEmpty == false) - #expect(amiibos.first?.platform?.wiiU.isEmpty == false) - #expect(amiibos.first?.platform?.wiiU.first?.usages?.isEmpty == false) - #expect(amiibos.last?.platform != nil) - } - @Test("get amiibo series", arguments: zip( Input.amiiboSeries, Output.amiiboSeries @@ -1487,6 +337,53 @@ private extension AmiiboServiceLiveTests { // MARK: Functions + /// Asserts the number of items returned by the `amiibos` endpoint that matched a given filter. + /// - Parameters: + /// - filter: An amiibo filter type. + /// - numberOfItems: An expected number of items returned. + func assertAmiibos( + with filter: AmiiboFilter, + expects numberOfItems: Int + ) async throws { + // GIVEN + // WHEN + let amiibos = try await service.getAmiibos(filter) + + // THEN + #expect(amiibos.count == numberOfItems) + + guard + !amiibos.isEmpty, + (filter.showGames == true || filter.showUsage == true) + else { return } + + let firstAmiiboPlatform = try #require(amiibos.first?.platform) + + #expect(amiibos.last?.platform != nil) + + if filter.showUsage == true { + #expect(firstAmiiboPlatform.switch.first?.usages?.isEmpty == false) + #expect(firstAmiiboPlatform.threeDS.first?.usages?.isEmpty == false) + #expect(firstAmiiboPlatform.wiiU.first?.usages?.isEmpty == false) + } + } + + /// Asserts the error thrown by the `amiibos` endpoint. + /// - Parameters: + /// - error: An expected error. + /// - filter: An amiibo filter type. + func assertsAmiibosThrows( + error: AmiiboServiceError, + when filter: AmiiboFilter + ) async throws { + // GIVEN + // WHEN + // THEN + await #expect(throws: error) { + try await service.getAmiibos(filter) + } + } + /// Asserts the number of items returned by the `amiiboSeries` endpoint that matched a given filter. /// - Parameters: /// - filter: An amiibo series filter type. @@ -1500,7 +397,6 @@ private extension AmiiboServiceLiveTests { let amiiboSeries = try await service.getAmiiboSeries(filter) // THEN - #expect(!amiiboSeries.isEmpty) #expect(amiiboSeries.count == numberOfItems) } @@ -1533,7 +429,6 @@ private extension AmiiboServiceLiveTests { let amiiboTypes = try await service.getAmiiboTypes(filter) // THEN - #expect(!amiiboTypes.isEmpty) #expect(amiiboTypes.count == numberOfItems) } @@ -1566,7 +461,6 @@ private extension AmiiboServiceLiveTests { let gameCharacters = try await service.getGameCharacters(filter) // THEN - #expect(!gameCharacters.isEmpty) #expect(gameCharacters.count == numberOfItems) } @@ -1599,7 +493,6 @@ private extension AmiiboServiceLiveTests { let gameSeries = try await service.getGameSeries(filter) // THEN - #expect(!gameSeries.isEmpty) #expect(gameSeries.count == numberOfItems) } @@ -1649,6 +542,51 @@ private extension AmiiboServiceLiveTests { // MARK: - Arguments enum Input { + /// A list of amiibo filters to input to the `assertAmiibos` assertion. + static let amiibos: [AmiiboFilter] = [ + .init(), + .init(identifier: "0000000000000002"), + .init(name: "zelda"), + .init(name: "Something"), + .init(name: "zel"), + .init(name: .empty), + .init(type: "0x00"), + .init(type: "Figure"), + .init(type: "0x0f"), + .init(type: "something"), + .init(type: "fig"), + .init(type: .empty), + .init(series: "0x00"), + .init(series: "Legend of Zelda"), + .init(series: "0xf9"), + .init(series: "something"), + .init(series: "fig"), + .init(series: .empty), + .init(gameCharacter: "0x00"), + .init(gameCharacter: "Zelda"), + .init(gameCharacter: "0xf9"), + .init(gameCharacter: "something"), + .init(gameCharacter: "fig"), + .init(gameCharacter: .empty), + .init(gameSeries: "0x00"), + .init(gameSeries: "Legend of Zelda"), + .init(gameSeries: "0xf9"), + .init(gameSeries: "something"), + .init(gameSeries: "Super"), + .init(gameSeries: .empty), + .init(showGames: true), + .init(showUsage: true) + ] + /// A list of amiibo series filters to input to the `assertAmiibosThrows` assertion. + static let amiibosThrows: [AmiiboFilter] = [ + .init(identifier: "0000000000000000"), + .init(identifier: "0000000"), + .init(identifier: .empty), + .init(type: "0x"), + .init(series: "0x"), + .init(gameCharacter: "0x"), + .init(gameSeries: "0x"), + ] /// A list of amiibo series filters to input to the `assertAmiiboSeries` assertion. static let amiiboSeries: [AmiiboSeriesFilter] = [ .init(), @@ -1712,6 +650,10 @@ enum Input { } enum Output { + /// A list of number of items that are expected from the `assertAmiibos` assertion. + static let amiibos: [Int] = [.totalAmiibos, 1, 5, .zero, 7, .totalAmiibos, 235, 235, .zero, .zero, .zero, .zero, 96, 26, .zero, .zero, 25, .totalAmiibos, 12, 6, .zero, .zero, .zero, .totalAmiibos, 49, 32, .zero, .zero, 147, .totalAmiibos, .totalAmiibos, .totalAmiibos] + /// A list of errors are expected to be thrown from the `assertAmiibosThrows` assertion. + static let amiibosThrows: [AmiiboServiceError] = [.decoding, .decoding, .badRequest, .badRequest, .badRequest, .badRequest, .badRequest] /// A list of number of items that are expected from the `assertAmiiboSeries` assertion. static let amiiboSeries: [Int] = [.totalAmiiboSeries, 1, 1, 1, .totalAmiiboSeries] /// A list of errors are expected to be thrown from the `assertAmiiboSeriesThrows` assertion. @@ -1733,6 +675,8 @@ enum Output { // MARK: - Constants private extension Int { + /// A number that represents the total number of amiibo items currently available at the live service. + static let totalAmiibos = 889 /// A number that represents the total number of amiibo series currently available at the live service. static let totalAmiiboSeries = 29 /// A number that represents the total number of amiibo types currently available at the live service.