1882 lines
54 KiB
Swift
1882 lines
54 KiB
Swift
//===----------------------------------------------------------------------===
|
|
//
|
|
// This source file is part of the AmiiboService open source project
|
|
//
|
|
// Copyright (c) 2024-2025 Röck+Cöde VoF. and the AmiiboAPI project authors
|
|
// Licensed under the EUPL 1.2 or later.
|
|
//
|
|
// See LICENSE for license information
|
|
// See CONTRIBUTORS for the list of AmiiboAPI project authors
|
|
//
|
|
//===----------------------------------------------------------------------===
|
|
|
|
import AmiiboService
|
|
import Foundation
|
|
import Testing
|
|
|
|
@Suite("Amiibo Service", .tags(.live))
|
|
struct AmiiboServiceLiveTests {
|
|
|
|
// MARK: Properties
|
|
|
|
private let service: AmiiboService
|
|
|
|
// MARK: Initializers
|
|
|
|
init() {
|
|
self.service = .init()
|
|
}
|
|
|
|
// MARK: Functions tests
|
|
|
|
#if swift(>=6.2)
|
|
@Test
|
|
func `get Amiibo items`() async throws {
|
|
// GIVEN
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos()
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 885)
|
|
#expect(amiibos.first?.identifier == "0000000000000002")
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.identifier == "3f000000042e0002")
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an existing identifier`() async throws {
|
|
// GIVEN
|
|
let identifier = "0000000000000002"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(identifier: identifier))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 1)
|
|
#expect(amiibos.first?.identifier == identifier)
|
|
#expect(amiibos.first?.platform == nil)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by a non-existing identifier`() async throws {
|
|
// GIVEN
|
|
let identifier = "0000000000000000"
|
|
|
|
// WHEN
|
|
// THEN
|
|
await #expect(throws: AmiiboServiceError.decoding) {
|
|
try await service.getAmiibos(.init(identifier: identifier))
|
|
}
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an incomplete identifier`() async throws {
|
|
// GIVEN
|
|
let identifier = "0000000"
|
|
|
|
// WHEN
|
|
// THEN
|
|
await #expect(throws: AmiiboServiceError.decoding) {
|
|
try await service.getAmiibos(.init(identifier: identifier))
|
|
}
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an empty identifier`() async throws {
|
|
// GIVEN
|
|
let identifier = ""
|
|
|
|
// WHEN
|
|
// THEN
|
|
await #expect(throws: AmiiboServiceError.badRequest) {
|
|
try await service.getAmiibos(.init(identifier: identifier))
|
|
}
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an existing name`() async throws {
|
|
// GIVEN
|
|
let name = "zelda"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(name: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 5)
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.platform == nil)
|
|
|
|
let nameFirst = try #require(amiibos.first?.name.lowercased())
|
|
let nameLast = try #require(amiibos.last?.name.lowercased())
|
|
|
|
#expect(nameFirst.contains(name))
|
|
#expect(nameLast.contains(name))
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by a non-existing name`() async throws {
|
|
// GIVEN
|
|
let name = "Something"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(name: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an incomplete name`() async throws {
|
|
// GIVEN
|
|
let name = "zel"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(name: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 7)
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.platform == nil)
|
|
|
|
let nameFirst = try #require(amiibos.first?.name.lowercased())
|
|
let nameLast = try #require(amiibos.last?.name.lowercased())
|
|
|
|
#expect(nameFirst.contains(name))
|
|
#expect(nameLast.contains(name))
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an empty name`() async throws {
|
|
// GIVEN
|
|
let name = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(name: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 885)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an existing type key`() async throws {
|
|
// GIVEN
|
|
let key = "0x00"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(type: key))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 235)
|
|
#expect(amiibos.first?.type == "Figure")
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.type == "Figure")
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an existing type name`() async throws {
|
|
// GIVEN
|
|
let name = "figure"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(type: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 235)
|
|
#expect(amiibos.first?.type == "Figure")
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.type == "Figure")
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by a non-existing type key`() async throws {
|
|
// GIVEN
|
|
let key = "0x0f"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(type: key))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by a non-existing type name`() async throws {
|
|
// GIVEN
|
|
let name = "something"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(type: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an incomplete type key`() async throws {
|
|
// GIVEN
|
|
let key = "0x"
|
|
|
|
// WHEN
|
|
// THEN
|
|
await #expect(throws: AmiiboServiceError.badRequest) {
|
|
try await service.getAmiibos(.init(type: key))
|
|
}
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an incomplete type name`() async throws {
|
|
// GIVEN
|
|
let name = "fig"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(type: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an empty type key`() async throws {
|
|
// GIVEN
|
|
let key = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(type: key))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an empty type name`() async throws {
|
|
// GIVEN
|
|
let name = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(type: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an existing series key`() async throws {
|
|
// GIVEN
|
|
let key = "0x00"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(series: key))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 96)
|
|
#expect(amiibos.first?.series == "Super Smash Bros.")
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.series == "Super Smash Bros.")
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an existing series name`() async throws {
|
|
// GIVEN
|
|
let name = "Legend Of Zelda"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(series: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 26)
|
|
#expect(amiibos.first?.series == name)
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.series == name)
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by a non-existing series key`() async throws {
|
|
// GIVEN
|
|
let key = "0xf9"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(series: key))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by a non-existing series name`() async throws {
|
|
// GIVEN
|
|
let name = "something"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(series: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an incomplete series key`() async throws {
|
|
// GIVEN
|
|
let key = "0x"
|
|
|
|
// WHEN
|
|
// THEN
|
|
await #expect(throws: AmiiboServiceError.badRequest) {
|
|
try await service.getAmiibos(.init(series: key))
|
|
}
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an incomplete series name`() async throws {
|
|
// GIVEN
|
|
let name = "fig"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(series: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 25)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an empty series key`() async throws {
|
|
// GIVEN
|
|
let key = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(series: key))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 885)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an empty series name`() async throws {
|
|
// GIVEN
|
|
let name = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(series: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 885)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an existing game character key`() async throws {
|
|
// GIVEN
|
|
let key = "0x00"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameCharacter: key))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 11)
|
|
#expect(amiibos.first?.gameCharacter == "Mario")
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.gameCharacter == "Mario")
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an existing game character name`() async throws {
|
|
// GIVEN
|
|
let name = "Zelda"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameCharacter: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 6)
|
|
#expect(amiibos.first?.gameCharacter == name)
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.gameCharacter == name)
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by a non-existing game character key`() async throws {
|
|
// GIVEN
|
|
let key = "0xf9"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameCharacter: key))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by a non-existing game character name`() async throws {
|
|
// GIVEN
|
|
let name = "something"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameCharacter: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an incomplete game character key`() async throws {
|
|
// GIVEN
|
|
let key = "0x"
|
|
|
|
// WHEN
|
|
// THEN
|
|
await #expect(throws: AmiiboServiceError.badRequest) {
|
|
try await service.getAmiibos(.init(gameCharacter: key))
|
|
}
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an incomplete game character name`() async throws {
|
|
// GIVEN
|
|
let name = "fig"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameCharacter: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an empty game character key`() async throws {
|
|
// GIVEN
|
|
let key = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameCharacter: key))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 885)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an empty game character name`() async throws {
|
|
// GIVEN
|
|
let name = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameCharacter: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 885)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an existing game series key`() async throws {
|
|
// GIVEN
|
|
let key = "0x00"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameSeries: key))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 45)
|
|
#expect(amiibos.first?.gameSeries == "Super Mario")
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.gameSeries == "Super Mario")
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an existing game series name`() async throws {
|
|
// GIVEN
|
|
let name = "The Legend of Zelda"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameSeries: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 32)
|
|
#expect(amiibos.first?.gameSeries == name)
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.gameSeries == name)
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by a non-existing game series key`() async throws {
|
|
// GIVEN
|
|
let key = "0xf9"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameSeries: key))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by a non-existing game series name`() async throws {
|
|
// GIVEN
|
|
let name = "something"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameSeries: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an incomplete game series key`() async throws {
|
|
// GIVEN
|
|
let key = "0x"
|
|
|
|
// WHEN
|
|
// THEN
|
|
await #expect(throws: AmiiboServiceError.badRequest) {
|
|
try await service.getAmiibos(.init(gameSeries: key))
|
|
}
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an incomplete game series name`() async throws {
|
|
// GIVEN
|
|
let name = "Super"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameSeries: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 143)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an empty game series key`() async throws {
|
|
// GIVEN
|
|
let key = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameSeries: key))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 885)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items by an empty game series name`() async throws {
|
|
// GIVEN
|
|
let name = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameSeries: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 885)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items with games data`() async throws {
|
|
// GIVEN
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(showGames: true))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 885)
|
|
#expect(amiibos.first?.platform != nil)
|
|
#expect(amiibos.first?.platform?.switch.isEmpty == false)
|
|
#expect(amiibos.first?.platform?.switch.first?.usages == nil)
|
|
#expect(amiibos.first?.platform?.threeDS.isEmpty == false)
|
|
#expect(amiibos.first?.platform?.threeDS.first?.usages == nil)
|
|
#expect(amiibos.first?.platform?.wiiU.isEmpty == false)
|
|
#expect(amiibos.first?.platform?.wiiU.first?.usages == nil)
|
|
#expect(amiibos.last?.platform != nil)
|
|
}
|
|
|
|
@Test
|
|
func `get Amiibo items with games and usages data`() async throws {
|
|
// GIVEN
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(showUsage: true))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 885)
|
|
#expect(amiibos.first?.platform != nil)
|
|
#expect(amiibos.first?.platform?.switch.isEmpty == false)
|
|
#expect(amiibos.first?.platform?.switch.first?.usages?.isEmpty == false)
|
|
#expect(amiibos.first?.platform?.threeDS.isEmpty == false)
|
|
#expect(amiibos.first?.platform?.threeDS.first?.usages?.isEmpty == false)
|
|
#expect(amiibos.first?.platform?.wiiU.isEmpty == false)
|
|
#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
|
|
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.amiiboTypes,
|
|
Output.amiiboTypes
|
|
))
|
|
func `get amiibo types`(
|
|
filter: AmiiboTypeFilter,
|
|
expects numberOfItems: Int
|
|
) async throws {
|
|
try await assertAmiiboTypes(
|
|
with: filter,
|
|
expects: numberOfItems
|
|
)
|
|
}
|
|
|
|
@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(
|
|
Input.gameCharacters,
|
|
Output.gameCharacters
|
|
))
|
|
func `get game characters`(
|
|
filter: GameCharacterFilter,
|
|
expects numberOfItems: Int
|
|
) async throws {
|
|
try await assertGameCharacters(
|
|
with: filter,
|
|
expects: numberOfItems
|
|
)
|
|
}
|
|
|
|
@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(
|
|
Input.gameSeries,
|
|
Output.gameSeries
|
|
))
|
|
func `get game series`(
|
|
filter: GameSeriesFilter,
|
|
expects numberOfItems: Int
|
|
) async throws {
|
|
try await assertGameSeries(
|
|
with: filter,
|
|
expects: numberOfItems
|
|
)
|
|
}
|
|
|
|
@Test(arguments: zip(
|
|
Input.gameSeriesThrows,
|
|
Output.gameSeriesThrows
|
|
))
|
|
func `get game series throws`(
|
|
filter: GameSeriesFilter,
|
|
expects error: AmiiboServiceError
|
|
) async throws {
|
|
try await assertsGameSeriesThrows(
|
|
error: error,
|
|
when: filter
|
|
)
|
|
}
|
|
|
|
@Test
|
|
func `get the last updated timestamp`() async throws {
|
|
try await assertLastUpdated(
|
|
day: 21,
|
|
month: 9,
|
|
year: 2025
|
|
)
|
|
}
|
|
#else
|
|
@Test("Get Amiibo items")
|
|
func getAmiibos() async throws {
|
|
// GIVEN
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos()
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 889)
|
|
#expect(amiibos.first?.identifier == "0000000000000002")
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.identifier == "3f000000042e0002")
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an existing identifier")
|
|
func getAmiibos_byExistingIdentifier() async throws {
|
|
// GIVEN
|
|
let identifier = "0000000000000002"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(identifier: identifier))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 1)
|
|
#expect(amiibos.first?.identifier == identifier)
|
|
#expect(amiibos.first?.platform == nil)
|
|
}
|
|
|
|
@Test("Get Amiibo items by a non-existing identifier")
|
|
func getAmiibos_byNonExistingIdentifier() async throws {
|
|
// GIVEN
|
|
let identifier = "0000000000000000"
|
|
|
|
// WHEN
|
|
// THEN
|
|
await #expect(throws: AmiiboServiceError.decoding) {
|
|
try await service.getAmiibos(.init(identifier: identifier))
|
|
}
|
|
}
|
|
|
|
@Test("Get Amiibo items by an incomplete identifier")
|
|
func getAmiibos_byIncompleteIdentifier() async throws {
|
|
// GIVEN
|
|
let identifier = "0000000"
|
|
|
|
// WHEN
|
|
// THEN
|
|
await #expect(throws: AmiiboServiceError.decoding) {
|
|
try await service.getAmiibos(.init(identifier: identifier))
|
|
}
|
|
}
|
|
|
|
@Test("Get Amiibo items by an empty identifier")
|
|
func getAmiibos_byEmptyIdentifier() async throws {
|
|
// GIVEN
|
|
let identifier = ""
|
|
|
|
// WHEN
|
|
// THEN
|
|
await #expect(throws: AmiiboServiceError.badRequest) {
|
|
try await service.getAmiibos(.init(identifier: identifier))
|
|
}
|
|
}
|
|
|
|
@Test("Get Amiibo items by an existing name")
|
|
func getAmiibos_byExistingName() async throws {
|
|
// GIVEN
|
|
let name = "zelda"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(name: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 5)
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.platform == nil)
|
|
|
|
let nameFirst = try #require(amiibos.first?.name.lowercased())
|
|
let nameLast = try #require(amiibos.last?.name.lowercased())
|
|
|
|
#expect(nameFirst.contains(name))
|
|
#expect(nameLast.contains(name))
|
|
}
|
|
|
|
@Test("Get Amiibo items by a non-existing name")
|
|
func getAmiibos_byNonExistingName() async throws {
|
|
// GIVEN
|
|
let name = "Something"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(name: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an incomplete name")
|
|
func getAmiibos_byIncompleteName() async throws {
|
|
// GIVEN
|
|
let name = "zel"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(name: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 7)
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.platform == nil)
|
|
|
|
let nameFirst = try #require(amiibos.first?.name.lowercased())
|
|
let nameLast = try #require(amiibos.last?.name.lowercased())
|
|
|
|
#expect(nameFirst.contains(name))
|
|
#expect(nameLast.contains(name))
|
|
}
|
|
|
|
@Test("Get Amiibo items by an empty name")
|
|
func getAmiibos_byEmptyName() async throws {
|
|
// GIVEN
|
|
let name = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(name: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 889)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an existing type key")
|
|
func getAmiibos_byExistingTypeKey() async throws {
|
|
// GIVEN
|
|
let key = "0x00"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(type: key))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 235)
|
|
#expect(amiibos.first?.type == "Figure")
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.type == "Figure")
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an existing type name")
|
|
func getAmiibos_byExistingTypeName() async throws {
|
|
// GIVEN
|
|
let name = "figure"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(type: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 235)
|
|
#expect(amiibos.first?.type == "Figure")
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.type == "Figure")
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test("Get Amiibo items by a non-existing type key")
|
|
func getAmiibos_byNonExistingTypeKey() async throws {
|
|
// GIVEN
|
|
let key = "0x0f"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(type: key))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test("Get Amiibo items by a non-existing type name")
|
|
func getAmiibos_byNonExistingTypeName() async throws {
|
|
// GIVEN
|
|
let name = "something"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(type: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an incomplete type key")
|
|
func getAmiibos_byIncompleteTypeKey() async throws {
|
|
// GIVEN
|
|
let key = "0x"
|
|
|
|
// WHEN
|
|
// THEN
|
|
await #expect(throws: AmiiboServiceError.badRequest) {
|
|
try await service.getAmiibos(.init(type: key))
|
|
}
|
|
}
|
|
|
|
@Test("Get Amiibo items by an incomplete type name")
|
|
func getAmiibos_byIncompleteTypeName() async throws {
|
|
// GIVEN
|
|
let name = "fig"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(type: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an empty type key")
|
|
func getAmiibos_byEmptyTypeKey() async throws {
|
|
// GIVEN
|
|
let key = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(type: key))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an empty type name")
|
|
func getAmiibos_byEmptyTypeName() async throws {
|
|
// GIVEN
|
|
let name = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(type: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an existing series key")
|
|
func getAmiibos_byExistingSeriesKey() async throws {
|
|
// GIVEN
|
|
let key = "0x00"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(series: key))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 96)
|
|
#expect(amiibos.first?.series == "Super Smash Bros.")
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.series == "Super Smash Bros.")
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an existing series name")
|
|
func getAmiibos_byExistingSeriesName() async throws {
|
|
// GIVEN
|
|
let name = "Legend Of Zelda"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(series: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 26)
|
|
#expect(amiibos.first?.series == name)
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.series == name)
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test("Get Amiibo items by a non-existing series key")
|
|
func getAmiibos_byNonExistingSeriesKey() async throws {
|
|
// GIVEN
|
|
let key = "0xf9"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(series: key))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test("Get Amiibo items by a non-existing series name")
|
|
func getAmiibos_byNonExistingSeriesName() async throws {
|
|
// GIVEN
|
|
let name = "something"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(series: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an incomplete series key")
|
|
func getAmiibos_byIncompleteSeriesKey() async throws {
|
|
// GIVEN
|
|
let key = "0x"
|
|
|
|
// WHEN
|
|
// THEN
|
|
await #expect(throws: AmiiboServiceError.badRequest) {
|
|
try await service.getAmiibos(.init(series: key))
|
|
}
|
|
}
|
|
|
|
@Test("Get Amiibo items by an incomplete series name")
|
|
func getAmiibos_byIncompleteSeriesName() async throws {
|
|
// GIVEN
|
|
let name = "fig"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(series: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 25)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an empty series key")
|
|
func getAmiibos_byEmptySeriesKey() async throws {
|
|
// GIVEN
|
|
let key = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(series: key))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 889)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an empty series name")
|
|
func getAmiibos_byEmptySeriesName() async throws {
|
|
// GIVEN
|
|
let name = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(series: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 889)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an existing game character key")
|
|
func getAmiibos_byExistingGameCharacterKey() async throws {
|
|
// GIVEN
|
|
let key = "0x00"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameCharacter: key))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 12)
|
|
#expect(amiibos.first?.gameCharacter == "Mario")
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.gameCharacter == "Mario")
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an existing game character name")
|
|
func getAmiibos_byExistingGameCharacterName() async throws {
|
|
// GIVEN
|
|
let name = "Zelda"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameCharacter: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 6)
|
|
#expect(amiibos.first?.gameCharacter == name)
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.gameCharacter == name)
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test("Get Amiibo items by a non-existing game character key")
|
|
func getAmiibos_byNonExistingGameCharacterKey() async throws {
|
|
// GIVEN
|
|
let key = "0xf9"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameCharacter: key))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test("Get Amiibo items by a non-existing game character name")
|
|
func getAmiibos_byNonExistingGameCharacterName() async throws {
|
|
// GIVEN
|
|
let name = "something"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameCharacter: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an incomplete game character key")
|
|
func getAmiibos_byIncompleteGameCharacterKey() async throws {
|
|
// GIVEN
|
|
let key = "0x"
|
|
|
|
// WHEN
|
|
// THEN
|
|
await #expect(throws: AmiiboServiceError.badRequest) {
|
|
try await service.getAmiibos(.init(gameCharacter: key))
|
|
}
|
|
}
|
|
|
|
@Test("Get Amiibo items by an incomplete game character name")
|
|
func getAmiibos_byIncompleteGameCharacterName() async throws {
|
|
// GIVEN
|
|
let name = "fig"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameCharacter: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an empty game character key")
|
|
func getAmiibos_byEmptyGameCharacterKey() async throws {
|
|
// GIVEN
|
|
let key = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameCharacter: key))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 889)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an empty game character name")
|
|
func getAmiibos_byEmptyGameCharacterName() async throws {
|
|
// GIVEN
|
|
let name = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameCharacter: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 889)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an existing game series key")
|
|
func getAmiibos_byExistingGameSeriesKey() async throws {
|
|
// GIVEN
|
|
let key = "0x00"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameSeries: key))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 49)
|
|
#expect(amiibos.first?.gameSeries == "Super Mario")
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.gameSeries == "Super Mario")
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an existing game series name")
|
|
func getAmiibos_byExistingGameSeriesName() async throws {
|
|
// GIVEN
|
|
let name = "The Legend of Zelda"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameSeries: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 32)
|
|
#expect(amiibos.first?.gameSeries == name)
|
|
#expect(amiibos.first?.platform == nil)
|
|
#expect(amiibos.last?.gameSeries == name)
|
|
#expect(amiibos.last?.platform == nil)
|
|
}
|
|
|
|
@Test("Get Amiibo items by a non-existing game series key")
|
|
func getAmiibos_byNonExistingGameSeriesKey() async throws {
|
|
// GIVEN
|
|
let key = "0xf9"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameSeries: key))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test("Get Amiibo items by a non-existing game series name")
|
|
func getAmiibos_byNonExistingGameSeriesName() async throws {
|
|
// GIVEN
|
|
let name = "something"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameSeries: name))
|
|
|
|
// THEN
|
|
#expect(amiibos.isEmpty)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an incomplete game series key")
|
|
func getAmiibos_byIncompleteGameSeriesKey() async throws {
|
|
// GIVEN
|
|
let key = "0x"
|
|
|
|
// WHEN
|
|
// THEN
|
|
await #expect(throws: AmiiboServiceError.badRequest) {
|
|
try await service.getAmiibos(.init(gameSeries: key))
|
|
}
|
|
}
|
|
|
|
@Test("Get Amiibo items by an incomplete game series name")
|
|
func getAmiibos_byIncompleteGameSeriesName() async throws {
|
|
// GIVEN
|
|
let name = "Super"
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameSeries: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 147)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an empty game series key")
|
|
func getAmiibos_byEmptyGameSeriesKey() async throws {
|
|
// GIVEN
|
|
let key = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameSeries: key))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 889)
|
|
}
|
|
|
|
@Test("Get Amiibo items by an empty game series name")
|
|
func getAmiibos_byEmptyGameSeriesName() async throws {
|
|
// GIVEN
|
|
let name = ""
|
|
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(gameSeries: name))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 889)
|
|
}
|
|
|
|
@Test("Get Amiibo items with games data")
|
|
func getAmiibos_withGamesData() async throws {
|
|
// GIVEN
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(showGames: true))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 889)
|
|
#expect(amiibos.first?.platform != nil)
|
|
#expect(amiibos.first?.platform?.switch.isEmpty == false)
|
|
#expect(amiibos.first?.platform?.switch.first?.usages == nil)
|
|
#expect(amiibos.first?.platform?.threeDS.isEmpty == false)
|
|
#expect(amiibos.first?.platform?.threeDS.first?.usages == nil)
|
|
#expect(amiibos.first?.platform?.wiiU.isEmpty == false)
|
|
#expect(amiibos.first?.platform?.wiiU.first?.usages == nil)
|
|
#expect(amiibos.last?.platform != nil)
|
|
}
|
|
|
|
@Test("Get Amiibo items with games and usages data")
|
|
func getAmiibos_withGamesAndUsagesData() async throws {
|
|
// GIVEN
|
|
// WHEN
|
|
let amiibos = try await service.getAmiibos(.init(showUsage: true))
|
|
|
|
// THEN
|
|
#expect(!amiibos.isEmpty)
|
|
#expect(amiibos.count == 889)
|
|
#expect(amiibos.first?.platform != nil)
|
|
#expect(amiibos.first?.platform?.switch.isEmpty == false)
|
|
#expect(amiibos.first?.platform?.switch.first?.usages?.isEmpty == false)
|
|
#expect(amiibos.first?.platform?.threeDS.isEmpty == false)
|
|
#expect(amiibos.first?.platform?.threeDS.first?.usages?.isEmpty == false)
|
|
#expect(amiibos.first?.platform?.wiiU.isEmpty == false)
|
|
#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 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 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 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(
|
|
Input.gameCharacters,
|
|
Output.gameCharacters
|
|
))
|
|
func getGameCharacters(
|
|
filter: GameCharacterFilter,
|
|
expects numberOfItems: Int
|
|
) async throws {
|
|
try await assertGameCharacters(
|
|
with: filter,
|
|
expects: numberOfItems
|
|
)
|
|
}
|
|
|
|
@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(
|
|
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 `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.
|
|
/// - 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.
|
|
/// - numberOfItems: An expected number of items returned.
|
|
func assertGameSeries(
|
|
with filter: GameSeriesFilter,
|
|
expects numberOfItems: Int
|
|
) async throws {
|
|
// GIVEN
|
|
// WHEN
|
|
let gameSeries = try await service.getGameSeries(filter)
|
|
|
|
// THEN
|
|
#expect(!gameSeries.isEmpty)
|
|
#expect(gameSeries.count == numberOfItems)
|
|
}
|
|
|
|
/// Asserts the error thrown by the `gameSeries` endpoint.
|
|
/// - 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
|
|
// WHEN
|
|
let dateLastUpdated = try await service.getLastUpdated()
|
|
|
|
// THEN
|
|
let dateComponents = Calendar.current.dateComponents(
|
|
[.year, .month, .day],
|
|
from: dateLastUpdated
|
|
)
|
|
|
|
#expect(dateComponents.year == year)
|
|
#expect(dateComponents.month == month)
|
|
#expect(dateComponents.day == day)
|
|
}
|
|
|
|
}
|
|
|
|
// 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(),
|
|
.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"),
|
|
.init(name: "Pikmin"),
|
|
.init(name: "Pik"),
|
|
.init(name: .empty)
|
|
]
|
|
/// A list of game series filters 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 `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.
|
|
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.
|
|
static let gameSeriesThrows: [AmiiboServiceError] = [.notFound, .badRequest, .badRequest, .notFound]
|
|
}
|
|
|
|
// 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.
|
|
static let totalGameSeries = 117
|
|
}
|
|
|
|
private extension String {
|
|
/// An empty string.
|
|
static let empty = ""
|
|
}
|