Refactored the game characters cases for the AmiiboServiceLiveTests tests in the tests target.
This commit is contained in:
@@ -874,126 +874,33 @@ struct AmiiboServiceLiveTests {
|
||||
#expect(amiiboTypes.first?.key == "0x00")
|
||||
#expect(amiiboTypes.last?.key == "0x03")
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Game characters`() async throws {
|
||||
// GIVEN
|
||||
// WHEN
|
||||
let gameCharacters = try await service.getGameCharacters()
|
||||
|
||||
// THEN
|
||||
#expect(!gameCharacters.isEmpty)
|
||||
#expect(gameCharacters.count == 668)
|
||||
#expect(gameCharacters.first?.key == "0x0000")
|
||||
#expect(gameCharacters.last?.key == "0x3f00")
|
||||
|
||||
@Test(arguments: zip(
|
||||
Input.gameCharacters,
|
||||
Output.gameCharacters
|
||||
))
|
||||
func `get game characters`(
|
||||
filter: GameCharacterFilter,
|
||||
expects numberOfItems: Int
|
||||
) async throws {
|
||||
try await assertGameCharacters(
|
||||
with: filter,
|
||||
expects: numberOfItems
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Game characters by an existing key`() async throws {
|
||||
// GIVEN
|
||||
let key = "0x0001"
|
||||
|
||||
// WHEN
|
||||
let gameCharacters = try await service.getGameCharacters(.init(key: key))
|
||||
|
||||
// THEN
|
||||
#expect(!gameCharacters.isEmpty)
|
||||
#expect(gameCharacters.count == 1)
|
||||
#expect(gameCharacters.first?.key == key)
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Game characters by a non-existing key`() async throws {
|
||||
// GIVEN
|
||||
let key = "0xffff"
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.notFound) {
|
||||
try await service.getGameCharacters(.init(key: key))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Game characters by an incomplete key`() async throws {
|
||||
// GIVEN
|
||||
let key = "0x"
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.badRequest) {
|
||||
try await service.getGameCharacters(.init(key: key))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Game characters by an empty key`() async throws {
|
||||
// GIVEN
|
||||
let key = ""
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.badRequest) {
|
||||
try await service.getGameCharacters(.init(key: key))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Game characters by an existing name`() async throws {
|
||||
// GIVEN
|
||||
let name = "Zelda"
|
||||
|
||||
// WHEN
|
||||
let gameCharacters = try await service.getGameCharacters(.init(name: name))
|
||||
|
||||
// THEN
|
||||
#expect(!gameCharacters.isEmpty)
|
||||
#expect(gameCharacters.count == 1)
|
||||
#expect(gameCharacters.first?.name == name)
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Game characters by a non-existing name`() async throws {
|
||||
// GIVEN
|
||||
let name = "Something"
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.notFound) {
|
||||
try await service.getGameCharacters(.init(name: name))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Game characters by an incomplete name`() async throws {
|
||||
// GIVEN
|
||||
let name = "Zeld"
|
||||
|
||||
// WHEN
|
||||
let gameCharacters = try await service.getGameCharacters(.init(name: name))
|
||||
|
||||
// THEN
|
||||
#expect(!gameCharacters.isEmpty)
|
||||
#expect(gameCharacters.count == 1)
|
||||
|
||||
let gameCharactersName = try #require(gameCharacters.first)
|
||||
|
||||
#expect(gameCharactersName.name.contains(name))
|
||||
}
|
||||
|
||||
@Test
|
||||
func `get Game characters by an empty name`() async throws {
|
||||
// GIVEN
|
||||
let name = ""
|
||||
|
||||
// WHEN
|
||||
let gameCharacters = try await service.getGameCharacters(.init(name: name))
|
||||
|
||||
// THEN
|
||||
#expect(!gameCharacters.isEmpty)
|
||||
#expect(gameCharacters.count == 668)
|
||||
#expect(gameCharacters.first?.key == "0x0000")
|
||||
#expect(gameCharacters.last?.key == "0x3f00")
|
||||
@Test(arguments: zip(
|
||||
Input.gameCharactersThrows,
|
||||
Output.gameCharactersThrows
|
||||
))
|
||||
func `get game characters throws`(
|
||||
filter: GameCharacterFilter,
|
||||
expects error: AmiiboServiceError
|
||||
) async throws {
|
||||
try await assertsGameCharactersThrows(
|
||||
error: error,
|
||||
when: filter
|
||||
)
|
||||
}
|
||||
|
||||
@Test(arguments: zip(
|
||||
@@ -1877,126 +1784,33 @@ struct AmiiboServiceLiveTests {
|
||||
#expect(amiiboTypes.first?.key == "0x00")
|
||||
#expect(amiiboTypes.last?.key == "0x04")
|
||||
}
|
||||
|
||||
@Test("Get game characters")
|
||||
func getGameCharacters() async throws {
|
||||
// GIVEN
|
||||
// WHEN
|
||||
let gameCharacters = try await service.getGameCharacters()
|
||||
|
||||
// THEN
|
||||
#expect(!gameCharacters.isEmpty)
|
||||
#expect(gameCharacters.count == 668)
|
||||
#expect(gameCharacters.first?.key == "0x0000")
|
||||
#expect(gameCharacters.last?.key == "0x3f00")
|
||||
|
||||
@Test("get game characters", arguments: zip(
|
||||
Input.gameCharacters,
|
||||
Output.gameCharacters
|
||||
))
|
||||
func getGameCharacters(
|
||||
filter: GameCharacterFilter,
|
||||
expects numberOfItems: Int
|
||||
) async throws {
|
||||
try await assertGameCharacters(
|
||||
with: filter,
|
||||
expects: numberOfItems
|
||||
)
|
||||
}
|
||||
|
||||
@Test("Get game characters by an existing key")
|
||||
func getGameCharacters_byExistingKey() async throws {
|
||||
// GIVEN
|
||||
let key = "0x0001"
|
||||
|
||||
// WHEN
|
||||
let gameCharacters = try await service.getGameCharacters(.init(key: key))
|
||||
|
||||
// THEN
|
||||
#expect(!gameCharacters.isEmpty)
|
||||
#expect(gameCharacters.count == 1)
|
||||
#expect(gameCharacters.first?.key == key)
|
||||
}
|
||||
|
||||
@Test("Get game characters by a non-existing key")
|
||||
func getGameCharacters_byNonExistingKey() async throws {
|
||||
// GIVEN
|
||||
let key = "0xffff"
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.notFound) {
|
||||
try await service.getGameCharacters(.init(key: key))
|
||||
}
|
||||
}
|
||||
|
||||
@Test("Get game characters by an incomplete key")
|
||||
func getGameCharacters_byIncompleteKey() async throws {
|
||||
// GIVEN
|
||||
let key = "0x"
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.badRequest) {
|
||||
try await service.getGameCharacters(.init(key: key))
|
||||
}
|
||||
}
|
||||
|
||||
@Test("Get game characters by an empty key")
|
||||
func getGameCharacters_byEmptyKey() async throws {
|
||||
// GIVEN
|
||||
let key = ""
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.badRequest) {
|
||||
try await service.getGameCharacters(.init(key: key))
|
||||
}
|
||||
}
|
||||
|
||||
@Test("Get game characters by an existing name")
|
||||
func getGameCharacters_byExistingName() async throws {
|
||||
// GIVEN
|
||||
let name = "Zelda"
|
||||
|
||||
// WHEN
|
||||
let gameCharacters = try await service.getGameCharacters(.init(name: name))
|
||||
|
||||
// THEN
|
||||
#expect(!gameCharacters.isEmpty)
|
||||
#expect(gameCharacters.count == 1)
|
||||
#expect(gameCharacters.first?.name == name)
|
||||
}
|
||||
|
||||
@Test("Get game characters by a non-existing name")
|
||||
func getGameCharacters_byNonExistingName() async throws {
|
||||
// GIVEN
|
||||
let name = "Something"
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.notFound) {
|
||||
try await service.getGameCharacters(.init(name: name))
|
||||
}
|
||||
}
|
||||
|
||||
@Test("Get game characters by an incomplete name")
|
||||
func getGameCharacters_byIncompleteName() async throws {
|
||||
// GIVEN
|
||||
let name = "Zeld"
|
||||
|
||||
// WHEN
|
||||
let gameCharacters = try await service.getGameCharacters(.init(name: name))
|
||||
|
||||
// THEN
|
||||
#expect(!gameCharacters.isEmpty)
|
||||
#expect(gameCharacters.count == 1)
|
||||
|
||||
let gameCharactersName = try #require(gameCharacters.first)
|
||||
|
||||
#expect(gameCharactersName.name.contains(name))
|
||||
}
|
||||
|
||||
@Test("Get game characters by an empty name")
|
||||
func getGameCharacters_byEmptyName() async throws {
|
||||
// GIVEN
|
||||
let name = ""
|
||||
|
||||
// WHEN
|
||||
let gameCharacters = try await service.getGameCharacters(.init(name: name))
|
||||
|
||||
// THEN
|
||||
#expect(!gameCharacters.isEmpty)
|
||||
#expect(gameCharacters.count == 668)
|
||||
#expect(gameCharacters.first?.key == "0x0000")
|
||||
#expect(gameCharacters.last?.key == "0x3f00")
|
||||
@Test("get game characters throws", arguments: zip(
|
||||
Input.gameCharactersThrows,
|
||||
Output.gameCharactersThrows
|
||||
))
|
||||
func getGameCharactersThrows(
|
||||
filter: GameCharacterFilter,
|
||||
expects error: AmiiboServiceError
|
||||
) async throws {
|
||||
try await assertsGameCharactersThrows(
|
||||
error: error,
|
||||
when: filter
|
||||
)
|
||||
}
|
||||
|
||||
@Test("get game series", arguments: zip(
|
||||
@@ -2045,6 +1859,39 @@ private extension AmiiboServiceLiveTests {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
/// Asserts the number of items returned by the `gameCharacters` endpoint that matched a given filter.
|
||||
/// - Parameters:
|
||||
/// - filter: A game character filter type.
|
||||
/// - numberOfItems: An expected number of items returned.
|
||||
func assertGameCharacters(
|
||||
with filter: GameCharacterFilter,
|
||||
expects numberOfItems: Int
|
||||
) async throws {
|
||||
// GIVEN
|
||||
// WHEN
|
||||
let gameCharacters = try await service.getGameCharacters(filter)
|
||||
|
||||
// THEN
|
||||
#expect(!gameCharacters.isEmpty)
|
||||
#expect(gameCharacters.count == numberOfItems)
|
||||
}
|
||||
|
||||
/// Asserts the error thrown by the `gameCharacters` endpoint.
|
||||
/// - Parameters:
|
||||
/// - error: An expected error.
|
||||
/// - filter: A game character filter type.
|
||||
func assertsGameCharactersThrows(
|
||||
error: AmiiboServiceError,
|
||||
when filter: GameCharacterFilter
|
||||
) async throws {
|
||||
// GIVEN
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: error) {
|
||||
try await service.getGameCharacters(filter)
|
||||
}
|
||||
}
|
||||
|
||||
/// Asserts the number of items returned by the `gameSeries` endpoint that matched a given filter.
|
||||
/// - Parameters:
|
||||
/// - filter: A game series filter type.
|
||||
@@ -2108,7 +1955,22 @@ private extension AmiiboServiceLiveTests {
|
||||
// MARK: - Arguments
|
||||
|
||||
enum Input {
|
||||
/// A list of game series filter to input to the `assertGameSeries` assertion.
|
||||
/// A list of game character filters to input to the `assertGameCharacters` assertion.
|
||||
static let gameCharacters: [GameCharacterFilter] = [
|
||||
.init(),
|
||||
.init(key: "0x0001"),
|
||||
.init(name: "Zelda"),
|
||||
.init(name: "Zeld"),
|
||||
.init(name: .empty)
|
||||
]
|
||||
/// A list of game character filters to input to the `assertGameCharactersThrows` assertion.
|
||||
static let gameCharactersThrows: [GameCharacterFilter] = [
|
||||
.init(key: "0xffff"),
|
||||
.init(key: "0x"),
|
||||
.init(key: .empty),
|
||||
.init(name: "Something")
|
||||
]
|
||||
/// A list of game series filters to input to the `assertGameSeries` assertion.
|
||||
static let gameSeries: [GameSeriesFilter] = [
|
||||
.init(),
|
||||
.init(key: "0x001"),
|
||||
@@ -2116,7 +1978,7 @@ enum Input {
|
||||
.init(name: "Pik"),
|
||||
.init(name: .empty)
|
||||
]
|
||||
/// A list of game series filter to input to the `assertGameSeriesThrows` assertion.
|
||||
/// A list of game series filters to input to the `assertGameSeriesThrows` assertion.
|
||||
static let gameSeriesThrows: [GameSeriesFilter] = [
|
||||
.init(key: "0xffff"),
|
||||
.init(key: "0x"),
|
||||
@@ -2126,6 +1988,10 @@ enum Input {
|
||||
}
|
||||
|
||||
enum Output {
|
||||
/// 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.
|
||||
static let gameCharactersThrows: [AmiiboServiceError] = [.notFound, .badRequest, .badRequest, .notFound]
|
||||
/// A list of number of items that are expected from the `assertGameSeries` assertion.
|
||||
static let gameSeries: [Int] = [.totalGameSeries, 1, 1, 1, .totalGameSeries]
|
||||
/// A list of errors are expected to be thrown from the `assertGameSeriesThrows` assertion.
|
||||
@@ -2135,6 +2001,8 @@ enum Output {
|
||||
// MARK: - Constants
|
||||
|
||||
private extension Int {
|
||||
/// 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.
|
||||
static let totalGameSeries = 117
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user