Amiibo Service live tests refactoring #15
@@ -632,126 +632,33 @@ struct AmiiboServiceLiveTests {
|
|||||||
#expect(amiibos.first?.platform?.wiiU.first?.usages?.isEmpty == false)
|
#expect(amiibos.first?.platform?.wiiU.first?.usages?.isEmpty == false)
|
||||||
#expect(amiibos.last?.platform != nil)
|
#expect(amiibos.last?.platform != nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(arguments: zip(
|
||||||
func `get Amiibo series`() async throws {
|
Input.amiiboSeries,
|
||||||
// GIVEN
|
Output.amiiboSeries
|
||||||
// WHEN
|
))
|
||||||
let amiiboSeries = try await service.getAmiiboSeries()
|
func `get amiibo series`(
|
||||||
|
filter: AmiiboSeriesFilter,
|
||||||
// THEN
|
expects numberOfItems: Int
|
||||||
#expect(!amiiboSeries.isEmpty)
|
) async throws {
|
||||||
#expect(amiiboSeries.count == 28)
|
try await assertAmiiboSeries(
|
||||||
#expect(amiiboSeries.first?.key == "0x00")
|
with: filter,
|
||||||
#expect(amiiboSeries.last?.key == "0xff")
|
expects: numberOfItems
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(arguments: zip(
|
||||||
func `get Amiibo series by an existing key`() async throws {
|
Input.amiiboSeriesThrows,
|
||||||
// GIVEN
|
Output.amiiboSeriesThrows
|
||||||
let key = "0x01"
|
))
|
||||||
|
func `get amiibo series throws`(
|
||||||
// WHEN
|
filter: AmiiboSeriesFilter,
|
||||||
let amiiboSeries = try await service.getAmiiboSeries(.init(key: key))
|
expects error: AmiiboServiceError
|
||||||
|
) async throws {
|
||||||
// THEN
|
try await assertsAmiiboSeriesThrows(
|
||||||
#expect(!amiiboSeries.isEmpty)
|
error: error,
|
||||||
#expect(amiiboSeries.count == 1)
|
when: filter
|
||||||
#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(
|
@Test(arguments: zip(
|
||||||
@@ -1449,126 +1356,33 @@ struct AmiiboServiceLiveTests {
|
|||||||
#expect(amiibos.first?.platform?.wiiU.first?.usages?.isEmpty == false)
|
#expect(amiibos.first?.platform?.wiiU.first?.usages?.isEmpty == false)
|
||||||
#expect(amiibos.last?.platform != nil)
|
#expect(amiibos.last?.platform != nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test("Get Amiibo series")
|
@Test("get amiibo series", arguments: zip(
|
||||||
func getAmiiboSeries() async throws {
|
Input.amiiboSeries,
|
||||||
// GIVEN
|
Output.amiiboSeries
|
||||||
// WHEN
|
))
|
||||||
let amiiboSeries = try await service.getAmiiboSeries()
|
func getAmiiboSeries(
|
||||||
|
filter: AmiiboSeriesFilter,
|
||||||
// THEN
|
expects numberOfItems: Int
|
||||||
#expect(!amiiboSeries.isEmpty)
|
) async throws {
|
||||||
#expect(amiiboSeries.count == 29)
|
try await assertAmiiboSeries(
|
||||||
#expect(amiiboSeries.first?.key == "0x00")
|
with: filter,
|
||||||
#expect(amiiboSeries.last?.key == "0xff")
|
expects: numberOfItems
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test("Get Amiibo series by an existing key")
|
@Test("get amiibo series throws", arguments: zip(
|
||||||
func getAmiiboSeries_byExistingKey() async throws {
|
Input.amiiboSeriesThrows,
|
||||||
// GIVEN
|
Output.amiiboSeriesThrows
|
||||||
let key = "0x01"
|
))
|
||||||
|
func getAmiiboSeriesThrows(
|
||||||
// WHEN
|
filter: AmiiboSeriesFilter,
|
||||||
let amiiboSeries = try await service.getAmiiboSeries(.init(key: key))
|
expects error: AmiiboServiceError
|
||||||
|
) async throws {
|
||||||
// THEN
|
try await assertsAmiiboSeriesThrows(
|
||||||
#expect(!amiiboSeries.isEmpty)
|
error: error,
|
||||||
#expect(amiiboSeries.count == 1)
|
when: filter
|
||||||
#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 types", arguments: zip(
|
@Test("get amiibo types", arguments: zip(
|
||||||
@@ -1673,6 +1487,39 @@ private extension AmiiboServiceLiveTests {
|
|||||||
|
|
||||||
// MARK: Functions
|
// 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.
|
/// Asserts the number of items returned by the `amiiboTypes` endpoint that matched a given filter.
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - filter: An amiibo type filter type.
|
/// - filter: An amiibo type filter type.
|
||||||
@@ -1802,6 +1649,21 @@ private extension AmiiboServiceLiveTests {
|
|||||||
// MARK: - Arguments
|
// MARK: - Arguments
|
||||||
|
|
||||||
enum Input {
|
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.
|
/// A list of amiibo type filters to input to the `assertAmiiboTypes` assertion.
|
||||||
static let amiiboTypes: [AmiiboTypeFilter] = [
|
static let amiiboTypes: [AmiiboTypeFilter] = [
|
||||||
.init(),
|
.init(),
|
||||||
@@ -1850,6 +1712,10 @@ enum Input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum Output {
|
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.
|
/// A list of number of items that are expected from the `assertAmiiboTypes` assertion.
|
||||||
static let amiiboTypes: [Int] = [.totalAmiiboTypes, 1, 1, 1, .totalAmiiboTypes]
|
static let amiiboTypes: [Int] = [.totalAmiiboTypes, 1, 1, 1, .totalAmiiboTypes]
|
||||||
/// A list of errors are expected to be thrown from the `assertAmiiboTypesThrows` assertion.
|
/// A list of errors are expected to be thrown from the `assertAmiiboTypesThrows` assertion.
|
||||||
@@ -1867,6 +1733,8 @@ enum Output {
|
|||||||
// MARK: - Constants
|
// MARK: - Constants
|
||||||
|
|
||||||
private extension Int {
|
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.
|
/// A number that represents the total number of amiibo types currently available at the live service.
|
||||||
static let totalAmiiboTypes = 5
|
static let totalAmiiboTypes = 5
|
||||||
/// A number that represents the total number of game characters currently available at the live service.
|
/// A number that represents the total number of game characters currently available at the live service.
|
||||||
|
|||||||
Reference in New Issue
Block a user