api-swift / Tests / IrdAPITests / OperationTableTests.swift
163 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
25
26
27
28
29
30
31
32
33
34
35
36
import Foundation
import Testing
@testable import IrdAPI

/// Pins the generated operation table to the vendored spec.
@Suite struct OperationTableTests {
    @Test func everySpecOperationIsGeneratedAndNothingElse() {
        let declared = Spec.operations
        let generated = Set(IrdOperation.all.map(\.key))
        #expect(declared.count == 161, "spec operation count (update README and site when this moves)")
        #expect(generated.count == IrdOperation.all.count, "duplicate operations")
        #expect(generated == declared, "\n in spec but not generated: \(declared.subtracting(generated).sorted())\n generated but not in spec: \(generated.subtracting(declared).sorted())")
    }

    @Test func moduleAndNamePairsAreUnique() {
        let pairs = IrdOperation.all.map { "\($0.module).\($0.name)" }
        #expect(Set(pairs).count == pairs.count)
        #expect(Set(IrdOperation.all.map(\.module)).count == 14)
    }

    @Test func securityMatchesTheSpec() throws {
        for op in IrdOperation.all {
            let spec = try #require(Spec.operation(op.key))
            let schemes = (spec["security"]?.arrayValue ?? []).map { Set(($0.objectValue ?? [:]).keys) }
            let expected: IrdSecurity
            switch schemes.sorted(by: { $0.count < $1.count }) {
            case [[]]: expected = .anonymous
            case [[], ["apiKey"]]: expected = .anonymousOrKey
            case [["accountJwt"]]: expected = .jwtOnly
            case [["apiKey"], ["accountJwt"]], [["accountJwt"], ["apiKey"]]: expected = .keyOrJwt
            default: Issue.record("unexpected security for \(op.key): \(schemes)"); continue
            }
            #expect(op.security == expected, Comment(rawValue: op.key))
        }
    }
}

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