Refactored the amiibo types cases for the AmiiboServiceLiveTests tests in the tests target.
This commit is contained in:
@@ -754,125 +754,32 @@ struct AmiiboServiceLiveTests {
|
||||
#expect(amiiboSeries.last?.key == "0xff")
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Amiibo types`() async throws {
|
||||
// GIVEN
|
||||
// WHEN
|
||||
let amiiboTypes = try await service.getAmiiboTypes()
|
||||
|
||||
// THEN
|
||||
#expect(!amiiboTypes.isEmpty)
|
||||
#expect(amiiboTypes.count == 4)
|
||||
#expect(amiiboTypes.first?.key == "0x00")
|
||||
#expect(amiiboTypes.last?.key == "0x03")
|
||||
@Test(arguments: zip(
|
||||
Input.amiiboTypes,
|
||||
Output.amiiboTypes
|
||||
))
|
||||
func `get amiibo types`(
|
||||
filter: AmiiboTypeFilter,
|
||||
expects numberOfItems: Int
|
||||
) async throws {
|
||||
try await assertAmiiboTypes(
|
||||
with: filter,
|
||||
expects: numberOfItems
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Amiibo types by an existing key`() async throws {
|
||||
// GIVEN
|
||||
let key = "0x01"
|
||||
|
||||
// WHEN
|
||||
let amiiboTypes = try await service.getAmiiboTypes(.init(key: key))
|
||||
|
||||
// THEN
|
||||
#expect(!amiiboTypes.isEmpty)
|
||||
#expect(amiiboTypes.count == 1)
|
||||
#expect(amiiboTypes.first?.key == key)
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Amiibo types by a non-existing key`() async throws {
|
||||
// GIVEN
|
||||
let key = "0x09"
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.notFound) {
|
||||
try await service.getAmiiboTypes(.init(key: key))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Amiibo types by an incomplete key`() async throws {
|
||||
// GIVEN
|
||||
let key = "0x"
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.badRequest) {
|
||||
try await service.getAmiiboTypes(.init(key: key))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Amiibo types by an empty key`() async throws {
|
||||
// GIVEN
|
||||
let key = ""
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.badRequest) {
|
||||
try await service.getAmiiboTypes(.init(key: key))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Amiibo types by an existing name`() async throws {
|
||||
// GIVEN
|
||||
let name = "Card"
|
||||
|
||||
// WHEN
|
||||
let amiiboTypes = try await service.getAmiiboTypes(.init(name: name))
|
||||
|
||||
// THEN
|
||||
#expect(!amiiboTypes.isEmpty)
|
||||
#expect(amiiboTypes.count == 1)
|
||||
#expect(amiiboTypes.first?.name == name)
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Amiibo types by a non-existing name`() async throws {
|
||||
// GIVEN
|
||||
let name = "Something"
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.notFound) {
|
||||
try await service.getAmiiboTypes(.init(name: name))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Amiibo types by an incomplete name`() async throws {
|
||||
// GIVEN
|
||||
let name = "Ca"
|
||||
|
||||
// WHEN
|
||||
let amiiboTypes = try await service.getAmiiboTypes(.init(name: name))
|
||||
|
||||
// THEN
|
||||
#expect(!amiiboTypes.isEmpty)
|
||||
#expect(amiiboTypes.count == 1)
|
||||
|
||||
let amiiboTypeName = try #require(amiiboTypes.first)
|
||||
|
||||
#expect(amiiboTypeName.name.contains(name))
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Amiibo types by an empty name`() async throws {
|
||||
// GIVEN
|
||||
let name = ""
|
||||
|
||||
// WHEN
|
||||
let amiiboTypes = try await service.getAmiiboTypes(.init(name: name))
|
||||
|
||||
// THEN
|
||||
#expect(!amiiboTypes.isEmpty)
|
||||
#expect(amiiboTypes.count == 4)
|
||||
#expect(amiiboTypes.first?.key == "0x00")
|
||||
#expect(amiiboTypes.last?.key == "0x03")
|
||||
@Test(arguments: zip(
|
||||
Input.amiiboTypesThrows,
|
||||
Output.amiiboTypesThrows
|
||||
))
|
||||
func `get amiibo types throws`(
|
||||
filter: AmiiboTypeFilter,
|
||||
expects error: AmiiboServiceError
|
||||
) async throws {
|
||||
try await assertsAmiiboTypesThrows(
|
||||
error: error,
|
||||
when: filter
|
||||
)
|
||||
}
|
||||
|
||||
@Test(arguments: zip(
|
||||
@@ -1663,126 +1570,33 @@ struct AmiiboServiceLiveTests {
|
||||
#expect(amiiboSeries.first?.key == "0x00")
|
||||
#expect(amiiboSeries.last?.key == "0xff")
|
||||
}
|
||||
|
||||
@Test("Get Amiibo types")
|
||||
func getAmiiboTypes() async throws {
|
||||
// GIVEN
|
||||
// WHEN
|
||||
let amiiboTypes = try await service.getAmiiboTypes()
|
||||
|
||||
// THEN
|
||||
#expect(!amiiboTypes.isEmpty)
|
||||
#expect(amiiboTypes.count == 5)
|
||||
#expect(amiiboTypes.first?.key == "0x00")
|
||||
#expect(amiiboTypes.last?.key == "0x04")
|
||||
|
||||
@Test("get amiibo types", arguments: zip(
|
||||
Input.amiiboTypes,
|
||||
Output.amiiboTypes
|
||||
))
|
||||
func getAmiiboTypes(
|
||||
filter: AmiiboTypeFilter,
|
||||
expects numberOfItems: Int
|
||||
) async throws {
|
||||
try await assertAmiiboTypes(
|
||||
with: filter,
|
||||
expects: numberOfItems
|
||||
)
|
||||
}
|
||||
|
||||
@Test("Get Amiibo types by an existing key")
|
||||
func getAmiiboTypes_byExistingKey() async throws {
|
||||
// GIVEN
|
||||
let key = "0x01"
|
||||
|
||||
// WHEN
|
||||
let amiiboTypes = try await service.getAmiiboTypes(.init(key: key))
|
||||
|
||||
// THEN
|
||||
#expect(!amiiboTypes.isEmpty)
|
||||
#expect(amiiboTypes.count == 1)
|
||||
#expect(amiiboTypes.first?.key == key)
|
||||
}
|
||||
|
||||
@Test("Get Amiibo types by a non-existing key")
|
||||
func getAmiiboTypes_byNonExistingKey() async throws {
|
||||
// GIVEN
|
||||
let key = "0x09"
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.notFound) {
|
||||
try await service.getAmiiboTypes(.init(key: key))
|
||||
}
|
||||
}
|
||||
|
||||
@Test("Get Amiibo types by an incomplete key")
|
||||
func getAmiiboTypes_byIncompleteKey() async throws {
|
||||
// GIVEN
|
||||
let key = "0x"
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.badRequest) {
|
||||
try await service.getAmiiboTypes(.init(key: key))
|
||||
}
|
||||
}
|
||||
|
||||
@Test("Get Amiibo types by an empty key")
|
||||
func getAmiiboTypes_byEmptyKey() async throws {
|
||||
// GIVEN
|
||||
let key = ""
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.badRequest) {
|
||||
try await service.getAmiiboTypes(.init(key: key))
|
||||
}
|
||||
}
|
||||
|
||||
@Test("Get Amiibo types by an existing name")
|
||||
func getAmiiboTypes_byExistingName() async throws {
|
||||
// GIVEN
|
||||
let name = "Card"
|
||||
|
||||
// WHEN
|
||||
let amiiboTypes = try await service.getAmiiboTypes(.init(name: name))
|
||||
|
||||
// THEN
|
||||
#expect(!amiiboTypes.isEmpty)
|
||||
#expect(amiiboTypes.count == 1)
|
||||
#expect(amiiboTypes.first?.name == name)
|
||||
}
|
||||
|
||||
@Test("Get Amiibo types by a non-existing name")
|
||||
func getAmiiboTypes_byNonExistingName() async throws {
|
||||
// GIVEN
|
||||
let name = "Something"
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.notFound) {
|
||||
try await service.getAmiiboTypes(.init(name: name))
|
||||
}
|
||||
}
|
||||
|
||||
@Test("Get Amiibo types by an incomplete name")
|
||||
func getAmiiboTypes_byIncompleteName() async throws {
|
||||
// GIVEN
|
||||
let name = "Ca"
|
||||
|
||||
// WHEN
|
||||
let amiiboTypes = try await service.getAmiiboTypes(.init(name: name))
|
||||
|
||||
// THEN
|
||||
#expect(!amiiboTypes.isEmpty)
|
||||
#expect(amiiboTypes.count == 1)
|
||||
|
||||
let amiiboTypeName = try #require(amiiboTypes.first)
|
||||
|
||||
#expect(amiiboTypeName.name.contains(name))
|
||||
}
|
||||
|
||||
@Test("Get Amiibo types by an empty name")
|
||||
func getAmiiboTypes_byEmptyName() async throws {
|
||||
// GIVEN
|
||||
let name = ""
|
||||
|
||||
// WHEN
|
||||
let amiiboTypes = try await service.getAmiiboTypes(.init(name: name))
|
||||
|
||||
// THEN
|
||||
#expect(!amiiboTypes.isEmpty)
|
||||
#expect(amiiboTypes.count == 5)
|
||||
#expect(amiiboTypes.first?.key == "0x00")
|
||||
#expect(amiiboTypes.last?.key == "0x04")
|
||||
@Test("get amiibo types throws", arguments: zip(
|
||||
Input.amiiboTypesThrows,
|
||||
Output.amiiboTypesThrows
|
||||
))
|
||||
func getAmiiboTypesThrows(
|
||||
filter: AmiiboTypeFilter,
|
||||
expects error: AmiiboServiceError
|
||||
) async throws {
|
||||
try await assertsAmiiboTypesThrows(
|
||||
error: error,
|
||||
when: filter
|
||||
)
|
||||
}
|
||||
|
||||
@Test("get game characters", arguments: zip(
|
||||
@@ -1859,6 +1673,39 @@ private extension AmiiboServiceLiveTests {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
/// Asserts the number of items returned by the `amiiboTypes` endpoint that matched a given filter.
|
||||
/// - Parameters:
|
||||
/// - filter: An amiibo type filter type.
|
||||
/// - numberOfItems: An expected number of items returned.
|
||||
func assertAmiiboTypes(
|
||||
with filter: AmiiboTypeFilter,
|
||||
expects numberOfItems: Int
|
||||
) async throws {
|
||||
// GIVEN
|
||||
// WHEN
|
||||
let amiiboTypes = try await service.getAmiiboTypes(filter)
|
||||
|
||||
// THEN
|
||||
#expect(!amiiboTypes.isEmpty)
|
||||
#expect(amiiboTypes.count == numberOfItems)
|
||||
}
|
||||
|
||||
/// Asserts the error thrown by the `amiiboTypes` endpoint.
|
||||
/// - Parameters:
|
||||
/// - error: An expected error.
|
||||
/// - filter: An amiibo type filter type.
|
||||
func assertsAmiiboTypesThrows(
|
||||
error: AmiiboServiceError,
|
||||
when filter: AmiiboTypeFilter
|
||||
) async throws {
|
||||
// GIVEN
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: error) {
|
||||
try await service.getAmiiboTypes(filter)
|
||||
}
|
||||
}
|
||||
|
||||
/// Asserts the number of items returned by the `gameCharacters` endpoint that matched a given filter.
|
||||
/// - Parameters:
|
||||
/// - filter: A game character filter type.
|
||||
@@ -1955,6 +1802,21 @@ private extension AmiiboServiceLiveTests {
|
||||
// MARK: - Arguments
|
||||
|
||||
enum Input {
|
||||
/// A list of amiibo type filters to input to the `assertAmiiboTypes` assertion.
|
||||
static let amiiboTypes: [AmiiboTypeFilter] = [
|
||||
.init(),
|
||||
.init(key: "0x01"),
|
||||
.init(name: "Card"),
|
||||
.init(name: "Ca"),
|
||||
.init(name: .empty)
|
||||
]
|
||||
/// A list of amiibo type filters to input to the `assertAmiiboTypesThrows` assertion.
|
||||
static let amiiboTypesThrows: [AmiiboTypeFilter] = [
|
||||
.init(key: "0x09"),
|
||||
.init(key: "0x"),
|
||||
.init(key: .empty),
|
||||
.init(name: "Something")
|
||||
]
|
||||
/// A list of game character filters to input to the `assertGameCharacters` assertion.
|
||||
static let gameCharacters: [GameCharacterFilter] = [
|
||||
.init(),
|
||||
@@ -1988,6 +1850,10 @@ enum Input {
|
||||
}
|
||||
|
||||
enum Output {
|
||||
/// 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.
|
||||
static let amiiboTypesThrows: [AmiiboServiceError] = [.notFound, .badRequest, .badRequest, .notFound]
|
||||
/// A list of number of items that are expected from the `assertGameCharacters` assertion.
|
||||
static let gameCharacters: [Int] = [.totalGameCharacters, 1, 1, 1, .totalGameCharacters]
|
||||
/// A list of errors are expected to be thrown from the `assertGameCharactersThrows` assertion.
|
||||
@@ -2001,6 +1867,8 @@ enum Output {
|
||||
// MARK: - Constants
|
||||
|
||||
private extension Int {
|
||||
/// 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.
|
||||
static let totalGameCharacters = 668
|
||||
/// A number that represents the total number of game series currently available at the live service.
|
||||
|
||||
Reference in New Issue
Block a user