diff --git a/Tests/AmiiboService/Tests/Public/Services/AmiiboServiceLiveTests.swift b/Tests/AmiiboService/Tests/Public/Services/AmiiboServiceLiveTests.swift index db4b9c1..777fb9d 100644 --- a/Tests/AmiiboService/Tests/Public/Services/AmiiboServiceLiveTests.swift +++ b/Tests/AmiiboService/Tests/Public/Services/AmiiboServiceLiveTests.swift @@ -632,126 +632,33 @@ struct AmiiboServiceLiveTests { #expect(amiibos.first?.platform?.wiiU.first?.usages?.isEmpty == false) #expect(amiibos.last?.platform != nil) } - - @Test - func `get Amiibo series`() async throws { - // GIVEN - // WHEN - let amiiboSeries = try await service.getAmiiboSeries() - - // THEN - #expect(!amiiboSeries.isEmpty) - #expect(amiiboSeries.count == 28) - #expect(amiiboSeries.first?.key == "0x00") - #expect(amiiboSeries.last?.key == "0xff") + + @Test(arguments: zip( + Input.amiiboSeries, + Output.amiiboSeries + )) + func `get amiibo series`( + filter: AmiiboSeriesFilter, + expects numberOfItems: Int + ) async throws { + try await assertAmiiboSeries( + with: filter, + expects: numberOfItems + ) } - @Test - func `get Amiibo series by an existing key`() async throws { - // GIVEN - let key = "0x01" - - // WHEN - let amiiboSeries = try await service.getAmiiboSeries(.init(key: key)) - - // THEN - #expect(!amiiboSeries.isEmpty) - #expect(amiiboSeries.count == 1) - #expect(amiiboSeries.first?.key == key) - } - - @Test - func `get Amiibo series by a non-existing key`() async throws { - // GIVEN - let key = "0xf9" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.notFound) { - try await service.getAmiiboSeries(.init(key: key)) - } - } - - @Test - func `get Amiibo series by an incomplete key`() async throws { - // GIVEN - let key = "0x" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.badRequest) { - try await service.getAmiiboSeries(.init(key: key)) - } - } - - @Test - func `get Amiibo series by an empty key`() async throws { - // GIVEN - let key = "" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.badRequest) { - try await service.getAmiiboSeries(.init(key: key)) - } - } - - @Test - func `get Amiibo series by an existing name`() async throws { - // GIVEN - let name = "Legend Of Zelda" - - // WHEN - let amiiboSeries = try await service.getAmiiboSeries(.init(name: name)) - - // THEN - #expect(!amiiboSeries.isEmpty) - #expect(amiiboSeries.count == 1) - #expect(amiiboSeries.first?.name == name) - } - - @Test - func `get Amiibo series by a non-existing name`() async throws { - // GIVEN - let name = "Something" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.notFound) { - try await service.getAmiiboSeries(.init(name: name)) - } - } - - @Test - func `get Amiibo series by an incomplete name`() async throws { - // GIVEN - let name = "Zelda" - - // WHEN - let amiiboSeries = try await service.getAmiiboSeries(.init(name: name)) - - // THEN - #expect(!amiiboSeries.isEmpty) - #expect(amiiboSeries.count == 1) - - let amiiboSeriesName = try #require(amiiboSeries.first) - - #expect(amiiboSeriesName.name.contains(name)) - } - - @Test - func `get Amiibo series by an empty name`() async throws { - // GIVEN - let name = "" - - // WHEN - let amiiboSeries = try await service.getAmiiboSeries(.init(name: name)) - - // THEN - #expect(!amiiboSeries.isEmpty) - #expect(amiiboSeries.count == 28) - #expect(amiiboSeries.first?.key == "0x00") - #expect(amiiboSeries.last?.key == "0xff") + @Test(arguments: zip( + Input.amiiboSeriesThrows, + Output.amiiboSeriesThrows + )) + func `get amiibo series throws`( + filter: AmiiboSeriesFilter, + expects error: AmiiboServiceError + ) async throws { + try await assertsAmiiboSeriesThrows( + error: error, + when: filter + ) } @Test(arguments: zip( @@ -1449,126 +1356,33 @@ struct AmiiboServiceLiveTests { #expect(amiibos.first?.platform?.wiiU.first?.usages?.isEmpty == false) #expect(amiibos.last?.platform != nil) } - - @Test("Get Amiibo series") - func getAmiiboSeries() async throws { - // GIVEN - // WHEN - let amiiboSeries = try await service.getAmiiboSeries() - - // THEN - #expect(!amiiboSeries.isEmpty) - #expect(amiiboSeries.count == 29) - #expect(amiiboSeries.first?.key == "0x00") - #expect(amiiboSeries.last?.key == "0xff") + + @Test("get amiibo series", arguments: zip( + Input.amiiboSeries, + Output.amiiboSeries + )) + func getAmiiboSeries( + filter: AmiiboSeriesFilter, + expects numberOfItems: Int + ) async throws { + try await assertAmiiboSeries( + with: filter, + expects: numberOfItems + ) } - @Test("Get Amiibo series by an existing key") - func getAmiiboSeries_byExistingKey() async throws { - // GIVEN - let key = "0x01" - - // WHEN - let amiiboSeries = try await service.getAmiiboSeries(.init(key: key)) - - // THEN - #expect(!amiiboSeries.isEmpty) - #expect(amiiboSeries.count == 1) - #expect(amiiboSeries.first?.key == key) - } - - @Test("Get Amiibo series by a non-existing key") - func getAmiiboSeries_byNonExistingKey() async throws { - // GIVEN - let key = "0xf9" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.notFound) { - try await service.getAmiiboSeries(.init(key: key)) - } - } - - @Test("Get Amiibo series by an incomplete key") - func getAmiiboSeries_byIncompleteKey() async throws { - // GIVEN - let key = "0x" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.badRequest) { - try await service.getAmiiboSeries(.init(key: key)) - } - } - - @Test("Get Amiibo series by an empty key") - func getAmiiboSeries_byEmptyKey() async throws { - // GIVEN - let key = "" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.badRequest) { - try await service.getAmiiboSeries(.init(key: key)) - } - } - - @Test("Get Amiibo series by an existing name") - func getAmiiboSeries_byExistingName() async throws { - // GIVEN - let name = "Legend Of Zelda" - - // WHEN - let amiiboSeries = try await service.getAmiiboSeries(.init(name: name)) - - // THEN - #expect(!amiiboSeries.isEmpty) - #expect(amiiboSeries.count == 1) - #expect(amiiboSeries.first?.name == name) - } - - @Test("Get Amiibo series by a non-existing name") - func getAmiiboSeries_byNonExistingName() async throws { - // GIVEN - let name = "Something" - - // WHEN - // THEN - await #expect(throws: AmiiboServiceError.notFound) { - try await service.getAmiiboSeries(.init(name: name)) - } - } - - @Test("Get Amiibo series by an incomplete name") - func getAmiiboSeries_byIncompleteName() async throws { - // GIVEN - let name = "Zelda" - - // WHEN - let amiiboSeries = try await service.getAmiiboSeries(.init(name: name)) - - // THEN - #expect(!amiiboSeries.isEmpty) - #expect(amiiboSeries.count == 1) - - let amiiboSeriesName = try #require(amiiboSeries.first) - - #expect(amiiboSeriesName.name.contains(name)) - } - - @Test("Get Amiibo series by an empty name") - func getAmiiboSeries_byEmptyName() async throws { - // GIVEN - let name = "" - - // WHEN - let amiiboSeries = try await service.getAmiiboSeries(.init(name: name)) - - // THEN - #expect(!amiiboSeries.isEmpty) - #expect(amiiboSeries.count == 29) - #expect(amiiboSeries.first?.key == "0x00") - #expect(amiiboSeries.last?.key == "0xff") + @Test("get amiibo series throws", arguments: zip( + Input.amiiboSeriesThrows, + Output.amiiboSeriesThrows + )) + func getAmiiboSeriesThrows( + filter: AmiiboSeriesFilter, + expects error: AmiiboServiceError + ) async throws { + try await assertsAmiiboSeriesThrows( + error: error, + when: filter + ) } @Test("get amiibo types", arguments: zip( @@ -1673,6 +1487,39 @@ private extension AmiiboServiceLiveTests { // MARK: Functions + /// Asserts the number of items returned by the `amiiboSeries` endpoint that matched a given filter. + /// - Parameters: + /// - filter: An amiibo series filter type. + /// - numberOfItems: An expected number of items returned. + func assertAmiiboSeries( + with filter: AmiiboSeriesFilter, + expects numberOfItems: Int + ) async throws { + // GIVEN + // WHEN + let amiiboSeries = try await service.getAmiiboSeries(filter) + + // THEN + #expect(!amiiboSeries.isEmpty) + #expect(amiiboSeries.count == numberOfItems) + } + + /// Asserts the error thrown by the `amiiboSeries` endpoint. + /// - Parameters: + /// - error: An expected error. + /// - filter: An amiibo series filter type. + func assertsAmiiboSeriesThrows( + error: AmiiboServiceError, + when filter: AmiiboSeriesFilter + ) async throws { + // GIVEN + // WHEN + // THEN + await #expect(throws: error) { + try await service.getAmiiboSeries(filter) + } + } + /// Asserts the number of items returned by the `amiiboTypes` endpoint that matched a given filter. /// - Parameters: /// - filter: An amiibo type filter type. @@ -1802,6 +1649,21 @@ private extension AmiiboServiceLiveTests { // MARK: - Arguments enum Input { + /// A list of amiibo series filters to input to the `assertAmiiboSeries` assertion. + static let amiiboSeries: [AmiiboSeriesFilter] = [ + .init(), + .init(key: "0x01"), + .init(name: "Legend of Zelda"), + .init(name: "Zelda"), + .init(name: .empty) + ] + /// A list of amiibo series filters to input to the `assertAmiiboSeriesThrows` assertion. + static let amiiboSeriesThrows: [AmiiboSeriesFilter] = [ + .init(key: "0xf9"), + .init(key: "0x"), + .init(key: .empty), + .init(name: "Something") + ] /// A list of amiibo type filters to input to the `assertAmiiboTypes` assertion. static let amiiboTypes: [AmiiboTypeFilter] = [ .init(), @@ -1850,6 +1712,10 @@ enum Input { } enum Output { + /// 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. + static let amiiboSeriesThrows: [AmiiboServiceError] = [.notFound, .badRequest, .badRequest, .notFound] /// A list of number of items that are expected from the `assertAmiiboTypes` assertion. static let amiiboTypes: [Int] = [.totalAmiiboTypes, 1, 1, 1, .totalAmiiboTypes] /// A list of errors are expected to be thrown from the `assertAmiiboTypesThrows` assertion. @@ -1867,6 +1733,8 @@ enum Output { // MARK: - Constants private extension Int { + /// 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. static let totalAmiiboTypes = 5 /// A number that represents the total number of game characters currently available at the live service.