api-swift / Tests / IrdAPITests / SynthRoundTripTests.swift
130 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)")
        }
    }
}

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/api-swift.git