Files
amiibo-service/Tests/AmiiboService/Cases/Internal/Transcoders/ISODateTimeTranscoderTests.swift
T
javier 4cbac015b1
CI / Build and test (push) Canceled after 0s
Documentation / Build documentation (push) Canceled after 0s
Documentation / Deploy to GitHub Pages (push) Canceled after 0s
Some fixes to the live test suite (#32)
This PR contains the work done to fix the live test suite, which started failing once the Amiibo API began returning Switch 2 games, and tidies the test suite around it.

### Changes

- **Live tests:** replaced the assertion that the first amiibo has no Switch 2 games with a usage check, matching the other platforms. The live data now includes Switch 2 entries for most amiibos.
- **Live tests:** refreshed the minimum item counts and the earliest accepted last-updated date to the values observed in October 2026, and documented in the README how to refresh them.
- **All tests:** moved test descriptions from `@Test("...")` strings into backticked function names, and aligned every case on the same GIVEN/WHEN/THEN structure.
- **Live client:** replaced the TODO about DocC inherited docs with a note. The compiler does not inherit documentation for protocol witnesses, so the repeated doc comments stay on purpose.

Reviewed-on: #32
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
2026-10-25 21:53:31 +00:00

79 lines
1.9 KiB
Swift

// ===----------------------------------------------------------------------===
//
// This source file is part of the Amiibo Service open source project
//
// Copyright (c) 2026 Röck+Cöde VoF. and the Amiibo Service project authors
// Licensed under Apache license v2.0
//
// See LICENSE for license information
// See CONTRIBUTORS for the list of Amiibo Service project authors
//
// SPDX-License-Identifier: Apache-2.0
//
// ===----------------------------------------------------------------------===
@testable import AmiiboService
import Foundation
import Testing
@Suite("ISO Date Time Transcoder")
struct ISODateTimeTranscoderTests {
// MARK: Properties
private let transcoder = ISODateTimeTranscoder()
// MARK: Decode tests
@Test
func `decodes a timestamp as UTC`() throws {
// GIVEN
let string = "2026-07-24T12:34:56.123000"
// WHEN
let date = try transcoder.decode(string)
// THEN
#expect(abs(date.timeIntervalSince(.utc(2026, 7, 24, 12, 34, 56)) - 0.123) < 0.001)
}
@Test
func `decodes a date-only string as midnight UTC`() throws {
// GIVEN
let string = "2014-11-21"
// WHEN
let date = try transcoder.decode(string)
// THEN
#expect(date == .utc(2014, 11, 21))
}
@Test(arguments: [
"", "2014-11", "2014-11-21T12:34:56", "2014-11-21T12:34:56Z", "21/11/2014", "yesterday"
])
func `throws a decoding error for an unsupported string`(string: String) {
// GIVEN
// WHEN
// THEN
#expect(throws: DecodingError.self) {
try transcoder.decode(string)
}
}
// MARK: Encode tests
@Test
func `encodes a date as a timestamp`() throws {
// GIVEN
let date: Date = .utc(2026, 7, 24, 12, 34, 56)
// WHEN
let string = try transcoder.encode(date)
// THEN
#expect(string == "2026-07-24T12:34:56.000000")
}
}