Amiibo Service live tests refactoring #15
@@ -995,142 +995,42 @@ struct AmiiboServiceLiveTests {
|
|||||||
#expect(gameCharacters.first?.key == "0x0000")
|
#expect(gameCharacters.first?.key == "0x0000")
|
||||||
#expect(gameCharacters.last?.key == "0x3f00")
|
#expect(gameCharacters.last?.key == "0x3f00")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(arguments: zip(
|
||||||
func `get Game series`() async throws {
|
Input.gameSeries,
|
||||||
// GIVEN
|
Output.gameSeries
|
||||||
// WHEN
|
))
|
||||||
let gameSeries = try await service.getGameSeries()
|
func `get game series`(
|
||||||
|
filter: GameSeriesFilter,
|
||||||
// THEN
|
expects numberOfItems: Int
|
||||||
#expect(!gameSeries.isEmpty)
|
) async throws {
|
||||||
#expect(gameSeries.count == 117)
|
try await assertGameSeries(
|
||||||
#expect(gameSeries.first?.key == "0x000")
|
with: filter,
|
||||||
#expect(gameSeries.last?.key == "0x3f0")
|
expects: numberOfItems
|
||||||
}
|
)
|
||||||
|
}
|
||||||
@Test
|
|
||||||
func `get Game series by an existing key`() async throws {
|
@Test(arguments: zip(
|
||||||
// GIVEN
|
Input.gameSeriesThrows,
|
||||||
let key = "0x001"
|
Output.gameSeriesThrows
|
||||||
|
))
|
||||||
// WHEN
|
func `get game series throws`(
|
||||||
let gameSeries = try await service.getGameSeries(.init(key: key))
|
filter: GameSeriesFilter,
|
||||||
|
expects error: AmiiboServiceError
|
||||||
// THEN
|
) async throws {
|
||||||
#expect(!gameSeries.isEmpty)
|
try await assertsGameSeriesThrows(
|
||||||
#expect(gameSeries.count == 1)
|
error: error,
|
||||||
#expect(gameSeries.first?.key == key)
|
when: filter
|
||||||
}
|
)
|
||||||
|
}
|
||||||
@Test
|
|
||||||
func `get Game Series by a non-existing key`() async throws {
|
@Test
|
||||||
// GIVEN
|
func `get the last updated timestamp`() async throws {
|
||||||
let key = "0xffff"
|
try await assertLastUpdated(
|
||||||
|
day: 21,
|
||||||
// WHEN
|
month: 9,
|
||||||
// THEN
|
year: 2025
|
||||||
await #expect(throws: AmiiboServiceError.notFound) {
|
|
||||||
try await service.getGameSeries(.init(key: key))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
func `get Game series by an incomplete key`() async throws {
|
|
||||||
// GIVEN
|
|
||||||
let key = "0x"
|
|
||||||
|
|
||||||
// WHEN & THEN
|
|
||||||
await #expect(throws: AmiiboServiceError.badRequest) {
|
|
||||||
try await service.getGameSeries(.init(key: key))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
func `get Game series by an empty key`() async throws {
|
|
||||||
// GIVEN
|
|
||||||
let key = ""
|
|
||||||
|
|
||||||
// WHEN
|
|
||||||
// THEN
|
|
||||||
await #expect(throws: AmiiboServiceError.badRequest) {
|
|
||||||
try await service.getGameSeries(.init(key: key))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
func `get Game series by an existing name`() async throws {
|
|
||||||
// GIVEN
|
|
||||||
let name = "Pikmin"
|
|
||||||
|
|
||||||
// WHEN
|
|
||||||
let gameSeries = try await service.getGameSeries(.init(name: name))
|
|
||||||
|
|
||||||
// THEN
|
|
||||||
#expect(!gameSeries.isEmpty)
|
|
||||||
#expect(gameSeries.count == 1)
|
|
||||||
#expect(gameSeries.first?.name == name)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
func `get Game series by a non-existing name`() async throws {
|
|
||||||
// GIVEN
|
|
||||||
let name = "Something"
|
|
||||||
|
|
||||||
// WHEN
|
|
||||||
// THEN
|
|
||||||
await #expect(throws: AmiiboServiceError.notFound) {
|
|
||||||
try await service.getGameSeries(.init(name: name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
func `get Game series by an incomplete name`() async throws {
|
|
||||||
// GIVEN
|
|
||||||
let name = "Pik"
|
|
||||||
|
|
||||||
// WHEN
|
|
||||||
let gameSeries = try await service.getGameSeries(.init(name: name))
|
|
||||||
|
|
||||||
// THEN
|
|
||||||
#expect(!gameSeries.isEmpty)
|
|
||||||
#expect(gameSeries.count == 1)
|
|
||||||
|
|
||||||
let gameSeriesName = try #require(gameSeries.first)
|
|
||||||
|
|
||||||
#expect(gameSeriesName.name.contains(name))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
func `get Game series by an empty name`() async throws {
|
|
||||||
// GIVEN
|
|
||||||
let name = ""
|
|
||||||
|
|
||||||
// WHEN
|
|
||||||
let gameSeries = try await service.getGameSeries(.init(name: name))
|
|
||||||
|
|
||||||
// THEN
|
|
||||||
#expect(!gameSeries.isEmpty)
|
|
||||||
#expect(gameSeries.count == 117)
|
|
||||||
#expect(gameSeries.first?.key == "0x000")
|
|
||||||
#expect(gameSeries.last?.key == "0x3f0")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
func `get the Last Updated timestamp`() async throws {
|
|
||||||
// GIVEN
|
|
||||||
// WHEN
|
|
||||||
let dateLastUpdated = try await service.getLastUpdated()
|
|
||||||
|
|
||||||
// THEN
|
|
||||||
let dateComponents = Calendar.current.dateComponents(
|
|
||||||
[.year, .month, .day],
|
|
||||||
from: dateLastUpdated
|
|
||||||
)
|
)
|
||||||
|
|
||||||
#expect(dateComponents.year == 2025)
|
|
||||||
#expect(dateComponents.month == 7)
|
|
||||||
#expect(dateComponents.day == 18)
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@Test("Get Amiibo items")
|
@Test("Get Amiibo items")
|
||||||
@@ -2098,130 +1998,96 @@ struct AmiiboServiceLiveTests {
|
|||||||
#expect(gameCharacters.first?.key == "0x0000")
|
#expect(gameCharacters.first?.key == "0x0000")
|
||||||
#expect(gameCharacters.last?.key == "0x3f00")
|
#expect(gameCharacters.last?.key == "0x3f00")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test("Get game series")
|
|
||||||
func getGameSeries() async throws {
|
|
||||||
// GIVEN
|
|
||||||
// WHEN
|
|
||||||
let gameSeries = try await service.getGameSeries()
|
|
||||||
|
|
||||||
// THEN
|
|
||||||
#expect(!gameSeries.isEmpty)
|
|
||||||
#expect(gameSeries.count == 117)
|
|
||||||
#expect(gameSeries.first?.key == "0x000")
|
|
||||||
#expect(gameSeries.last?.key == "0x3f0")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test("Get game series by an existing key")
|
|
||||||
func getGameSeries_byExistingKey() async throws {
|
|
||||||
// GIVEN
|
|
||||||
let key = "0x001"
|
|
||||||
|
|
||||||
// WHEN
|
|
||||||
let gameSeries = try await service.getGameSeries(.init(key: key))
|
|
||||||
|
|
||||||
// THEN
|
|
||||||
#expect(!gameSeries.isEmpty)
|
|
||||||
#expect(gameSeries.count == 1)
|
|
||||||
#expect(gameSeries.first?.key == key)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test("Get game series by a non-existing key")
|
|
||||||
func getGameSeries_byNonExistingKey() async throws {
|
|
||||||
// GIVEN
|
|
||||||
let key = "0xffff"
|
|
||||||
|
|
||||||
// WHEN
|
|
||||||
// THEN
|
|
||||||
await #expect(throws: AmiiboServiceError.notFound) {
|
|
||||||
try await service.getGameSeries(.init(key: key))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test("Get game series by an incomplete key")
|
|
||||||
func getGameSeries_byIncompleteKey() async throws {
|
|
||||||
// GIVEN
|
|
||||||
let key = "0x"
|
|
||||||
|
|
||||||
// WHEN & THEN
|
|
||||||
await #expect(throws: AmiiboServiceError.badRequest) {
|
|
||||||
try await service.getGameSeries(.init(key: key))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test("Get game series by an empty key")
|
|
||||||
func getGameSeries_byEmptyKey() async throws {
|
|
||||||
// GIVEN
|
|
||||||
let key = ""
|
|
||||||
|
|
||||||
// WHEN
|
|
||||||
// THEN
|
|
||||||
await #expect(throws: AmiiboServiceError.badRequest) {
|
|
||||||
try await service.getGameSeries(.init(key: key))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test("Get game series by an existing name")
|
|
||||||
func getGameSeries_byExistingName() async throws {
|
|
||||||
// GIVEN
|
|
||||||
let name = "Pikmin"
|
|
||||||
|
|
||||||
// WHEN
|
|
||||||
let gameSeries = try await service.getGameSeries(.init(name: name))
|
|
||||||
|
|
||||||
// THEN
|
|
||||||
#expect(!gameSeries.isEmpty)
|
|
||||||
#expect(gameSeries.count == 1)
|
|
||||||
#expect(gameSeries.first?.name == name)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test("Get game series by a non-existing name")
|
|
||||||
func getGameSeries_byNonExistingName() async throws {
|
|
||||||
// GIVEN
|
|
||||||
let name = "Something"
|
|
||||||
|
|
||||||
// WHEN
|
|
||||||
// THEN
|
|
||||||
await #expect(throws: AmiiboServiceError.notFound) {
|
|
||||||
try await service.getGameSeries(.init(name: name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test("Get game series by an incomplete name")
|
|
||||||
func getGameSeries_byIncompleteName() async throws {
|
|
||||||
// GIVEN
|
|
||||||
let name = "Pik"
|
|
||||||
|
|
||||||
// WHEN
|
|
||||||
let gameSeries = try await service.getGameSeries(.init(name: name))
|
|
||||||
|
|
||||||
// THEN
|
|
||||||
#expect(!gameSeries.isEmpty)
|
|
||||||
#expect(gameSeries.count == 1)
|
|
||||||
|
|
||||||
let gameSeriesName = try #require(gameSeries.first)
|
|
||||||
|
|
||||||
#expect(gameSeriesName.name.contains(name))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test("Get game series by an empty name")
|
|
||||||
func getGameSeries_byEmptyName() async throws {
|
|
||||||
|
|
||||||
|
@Test("get game series", arguments: zip(
|
||||||
|
Input.gameSeries,
|
||||||
|
Output.gameSeries
|
||||||
|
))
|
||||||
|
func getGameSeries(
|
||||||
|
filter: GameSeriesFilter,
|
||||||
|
expects numberOfItems: Int
|
||||||
|
) async throws {
|
||||||
|
try await assertGameSeries(
|
||||||
|
with: filter,
|
||||||
|
expects: numberOfItems
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test("get game series throws", arguments: zip(
|
||||||
|
Input.gameSeriesThrows,
|
||||||
|
Output.gameSeriesThrows
|
||||||
|
))
|
||||||
|
func getGameSeriesThrows(
|
||||||
|
filter: GameSeriesFilter,
|
||||||
|
expects error: AmiiboServiceError
|
||||||
|
) async throws {
|
||||||
|
try await assertsGameSeriesThrows(
|
||||||
|
error: error,
|
||||||
|
when: filter
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test("get last updated timestamp")
|
||||||
|
func getLastUpdated() async throws {
|
||||||
|
try await assertLastUpdated(
|
||||||
|
day: 21,
|
||||||
|
month: 9,
|
||||||
|
year: 2025
|
||||||
|
)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Assertions
|
||||||
|
|
||||||
|
private extension AmiiboServiceLiveTests {
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
/// Asserts the number of items returned by the `gameSeries` endpoint that matched a given filter.
|
||||||
|
/// - Parameters:
|
||||||
|
/// - filter: A game series filter type.
|
||||||
|
/// - numberOfItems: An expected number of items returned.
|
||||||
|
func assertGameSeries(
|
||||||
|
with filter: GameSeriesFilter,
|
||||||
|
expects numberOfItems: Int
|
||||||
|
) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let name = ""
|
|
||||||
|
|
||||||
// WHEN
|
// WHEN
|
||||||
let gameSeries = try await service.getGameSeries(.init(name: name))
|
let gameSeries = try await service.getGameSeries(filter)
|
||||||
|
|
||||||
// THEN
|
// THEN
|
||||||
#expect(!gameSeries.isEmpty)
|
#expect(!gameSeries.isEmpty)
|
||||||
#expect(gameSeries.count == 117)
|
#expect(gameSeries.count == numberOfItems)
|
||||||
#expect(gameSeries.first?.key == "0x000")
|
|
||||||
#expect(gameSeries.last?.key == "0x3f0")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test("Get the last updated timestamp")
|
/// Asserts the error thrown by the `gameSeries` endpoint.
|
||||||
func getLastUpdated() async throws {
|
/// - Parameters:
|
||||||
|
/// - error: An expected error.
|
||||||
|
/// - filter: A game series filter type.
|
||||||
|
func assertsGameSeriesThrows(
|
||||||
|
error: AmiiboServiceError,
|
||||||
|
when filter: GameSeriesFilter
|
||||||
|
) async throws {
|
||||||
|
// GIVEN
|
||||||
|
// WHEN
|
||||||
|
// THEN
|
||||||
|
await #expect(throws: error) {
|
||||||
|
try await service.getGameSeries(filter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Asserts the date returned by the `lastUpdated` endpoint.
|
||||||
|
/// - Parameters:
|
||||||
|
/// - day: A number of day of the last updated date.
|
||||||
|
/// - month: A number of month of the last updated date.
|
||||||
|
/// - year: A number of year of the last updated date.
|
||||||
|
func assertLastUpdated(
|
||||||
|
day: Int,
|
||||||
|
month: Int,
|
||||||
|
year: Int
|
||||||
|
) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
// WHEN
|
// WHEN
|
||||||
let dateLastUpdated = try await service.getLastUpdated()
|
let dateLastUpdated = try await service.getLastUpdated()
|
||||||
@@ -2232,10 +2098,48 @@ struct AmiiboServiceLiveTests {
|
|||||||
from: dateLastUpdated
|
from: dateLastUpdated
|
||||||
)
|
)
|
||||||
|
|
||||||
#expect(dateComponents.year == 2025)
|
#expect(dateComponents.year == year)
|
||||||
#expect(dateComponents.month == 9)
|
#expect(dateComponents.month == month)
|
||||||
#expect(dateComponents.day == 21)
|
#expect(dateComponents.day == day)
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Arguments
|
||||||
|
|
||||||
|
enum Input {
|
||||||
|
/// A list of game series filter to input to the `assertGameSeries` assertion.
|
||||||
|
static let gameSeries: [GameSeriesFilter] = [
|
||||||
|
.init(),
|
||||||
|
.init(key: "0x001"),
|
||||||
|
.init(name: "Pikmin"),
|
||||||
|
.init(name: "Pik"),
|
||||||
|
.init(name: .empty)
|
||||||
|
]
|
||||||
|
/// A list of game series filter to input to the `assertGameSeriesThrows` assertion.
|
||||||
|
static let gameSeriesThrows: [GameSeriesFilter] = [
|
||||||
|
.init(key: "0xffff"),
|
||||||
|
.init(key: "0x"),
|
||||||
|
.init(key: .empty),
|
||||||
|
.init(name: "Something")
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Output {
|
||||||
|
/// 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.
|
||||||
|
static let gameSeriesThrows: [AmiiboServiceError] = [.notFound, .badRequest, .badRequest, .notFound]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
private extension Int {
|
||||||
|
/// A number that represents the total number of game series currently available at the live service.
|
||||||
|
static let totalGameSeries = 117
|
||||||
|
}
|
||||||
|
|
||||||
|
private extension String {
|
||||||
|
/// An empty string.
|
||||||
|
static let empty = ""
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user