import Foundation
import Testing
@testable import IrdAPI
/// Every typed body and response decodes the synthesised JSON and re-encodes to the
/// same value — for the fully populated variant and for the one where optional fields
/// are absent and required-nullable ones are null.
@Suite struct SynthRoundTripTests {
@Test func theTableCoversEveryOperation() {
#expect(GeneratedSynth.all.count == 161)
}
@Test(arguments: GeneratedSynth.all.map(\.key), ["full", "nulls"])
func decodeThenEncodeIsTheIdentity(key: String, variant: String) throws {
let c = try #require(GeneratedSynth.all.first { $0.key == key })
let fx = try #require(CoverageTests.fixtures[key])
for (part, fn) in [("body", c.body), ("response", c.response)] {
guard let fn else { #expect(fx[part] == nil, "\(part) fixture without a type"); continue }
let input = try #require(fx[part]?[variant], "\(part).\(variant) fixture")
let output = try JSONValue.parse(try fn(try input.serialized()))
#expect(output == input, "\(key) \(part) \(variant)")
}
}
}