Defined some seeds to use in test cases in the String+Seed and the Data+Seed extensions.
This commit is contained in:
parent
4292885031
commit
a717592fa6
@ -53,17 +53,6 @@ extension AmiiboService: Service {
|
||||
).items
|
||||
}
|
||||
|
||||
public func gameSeries(
|
||||
filter: GameSeriesFilter = .init()
|
||||
) async throws -> [GameSeries] {
|
||||
client.setDateDecodingStrategy(.deferredToDate)
|
||||
|
||||
return try await client.request(
|
||||
endpoint: GetGameSeriesEndpoint(parameters: filter.makeParameters()),
|
||||
as: Result<GameSeries>.self
|
||||
).items
|
||||
}
|
||||
|
||||
public func characters(
|
||||
filter: CharacterFilter = .init()
|
||||
) async throws -> [Character] {
|
||||
@ -75,6 +64,17 @@ extension AmiiboService: Service {
|
||||
).items
|
||||
}
|
||||
|
||||
public func gameSeries(
|
||||
filter: GameSeriesFilter = .init()
|
||||
) async throws -> [GameSeries] {
|
||||
client.setDateDecodingStrategy(.deferredToDate)
|
||||
|
||||
return try await client.request(
|
||||
endpoint: GetGameSeriesEndpoint(parameters: filter.makeParameters()),
|
||||
as: Result<GameSeries>.self
|
||||
).items
|
||||
}
|
||||
|
||||
public func lastUpdated() async throws -> Date {
|
||||
client.setDateDecodingStrategy(.formatted(.dateAndTime))
|
||||
|
||||
|
@ -38,7 +38,7 @@ final class AmiiboClientTests: XCTestCase {
|
||||
|
||||
MockURLProtocol.mockData[.init(url: url)] = .init(
|
||||
status: .ok,
|
||||
data: .Seed.dataWithoutTimestamp
|
||||
data: .Client.Seed.dataWithoutTimestamp
|
||||
)
|
||||
|
||||
// WHEN
|
||||
@ -58,7 +58,7 @@ final class AmiiboClientTests: XCTestCase {
|
||||
|
||||
MockURLProtocol.mockData[.init(url: url)] = .init(
|
||||
status: .ok,
|
||||
data: .Seed.dataWithDateAndTime
|
||||
data: .Client.Seed.dataWithDateAndTime
|
||||
)
|
||||
|
||||
client.setDateDecodingStrategy(.formatted(.dateAndTime))
|
||||
@ -80,7 +80,7 @@ final class AmiiboClientTests: XCTestCase {
|
||||
|
||||
MockURLProtocol.mockData[.init(url: url)] = .init(
|
||||
status: .ok,
|
||||
data: .Seed.dataUnrelated
|
||||
data: .Client.Seed.dataUnrelated
|
||||
)
|
||||
|
||||
// WHEN & THEN
|
||||
@ -102,7 +102,7 @@ final class AmiiboClientTests: XCTestCase {
|
||||
|
||||
MockURLProtocol.mockData[.init(url: url)] = .init(
|
||||
status: .ok,
|
||||
data: .Seed.dataWithDateAndTime
|
||||
data: .Client.Seed.dataWithDateAndTime
|
||||
)
|
||||
|
||||
client.setDateDecodingStrategy(.formatted(.dateOnly))
|
||||
@ -126,7 +126,7 @@ final class AmiiboClientTests: XCTestCase {
|
||||
|
||||
MockURLProtocol.mockData[.init(url: url)] = .init(
|
||||
status: .notFound,
|
||||
data: .Seed.dataWithoutTimestamp
|
||||
data: .Client.Seed.dataWithoutTimestamp
|
||||
)
|
||||
|
||||
// WHEN & THEN
|
||||
|
@ -1,10 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
extension Data {
|
||||
enum Seed {
|
||||
static let dataUnrelated = "{\"something\":\"Something goes in here...\"}".data(using: .utf8)
|
||||
static let dataWithoutTimestamp = "{\"timestamp\":null}".data(using: .utf8)
|
||||
static let dataWithDateOnly = "{\"timestamp\":\"2023-03-23\"}".data(using: .utf8)
|
||||
static let dataWithDateAndTime = "{\"timestamp\":\"2023-03-23T13:11:20.382254\"}".data(using: .utf8)
|
||||
}
|
||||
}
|
31
Tests/Helpers/Extensions/Data+Seed.swift
Normal file
31
Tests/Helpers/Extensions/Data+Seed.swift
Normal file
@ -0,0 +1,31 @@
|
||||
import Foundation
|
||||
|
||||
extension Data {
|
||||
enum Client {
|
||||
enum Seed {
|
||||
static let dataUnrelated = "{\"something\":\"Something goes in here...\"}".data(using: .utf8)
|
||||
static let dataWithoutTimestamp = "{\"timestamp\":null}".data(using: .utf8)
|
||||
static let dataWithDateOnly = "{\"timestamp\":\"2023-03-23\"}".data(using: .utf8)
|
||||
static let dataWithDateAndTime = "{\"timestamp\":\"2023-03-23T13:11:20.382254\"}".data(using: .utf8)
|
||||
}
|
||||
}
|
||||
|
||||
enum Service {
|
||||
static let amiibos = String.Amiibo.withoutGameOrUsage.data(using: .utf8)
|
||||
static let amiibosWithGames = String.Amiibo.withGames.data(using: .utf8)
|
||||
static let amiibosWithUsage = String.Amiibo.withUsage.data(using: .utf8)
|
||||
static let amiiboWithBadFormattedDates = String.Amiibo.withBadFormattedReleaseDates.data(using: .utf8)
|
||||
static let amiiboWithMissingFields = String.Amiibo.withMissingFields.data(using: .utf8)
|
||||
static let amiiboSeries = String.AmiiboSeries.all.data(using: .utf8)
|
||||
static let amiiboSeriesWithMissingFields = String.AmiiboSeries.withMissingFields.data(using: .utf8)
|
||||
static let amiiboTypes = String.AmiiboType.all.data(using: .utf8)
|
||||
static let amiiboTypesWithMissingFields = String.AmiiboType.withMissingFields.data(using: .utf8)
|
||||
static let characters = String.Character.all.data(using: .utf8)
|
||||
static let charactersWithMissingFields = String.Character.withMissingFields.data(using: .utf8)
|
||||
static let gameSeries = String.GameSeries.all.data(using: .utf8)
|
||||
static let gameSeriesWithMissingFields = String.GameSeries.withMissingFields.data(using: .utf8)
|
||||
static let lastUpdated = String.LastUpdated.all.data(using: .utf8)
|
||||
static let lastUpdatedWithBadFormattedDate = String.LastUpdated.withBadFormattedDate.data(using: .utf8)
|
||||
static let lastUpdatedWithBadInfo = String.LastUpdated.withBadInfo.data(using: .utf8)
|
||||
}
|
||||
}
|
35
Tests/Helpers/Extensions/String+Seed.swift
Normal file
35
Tests/Helpers/Extensions/String+Seed.swift
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user