api-swift / Tests / IrdAPITests / Flows / ActionsFlowTests.swift
119 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
import Foundation
import Testing
@testable import IrdAPI

func registryAction(_ state: String) -> HTTPResponse {
    json(200, #"{"action":{"id":"a1","seq":1,"type":"renew","state":"\#(state)","registration_id":"r1","charged":"12.00","refunded":false,"error":null,"error_code":null,"created_at":"2026-09-08T10:00:00Z"}}"#)
}
func vpsAction(_ state: String) -> HTTPResponse {
    json(200, #"{"action":{"id":"a1","type":"create","state":"\#(state)","instance_id":"i1","error":null,"created_at":"2026-09-08T10:00:00Z"}}"#)
}

@Suite struct ActionsFlowTests {
    @Test func registryActionsPollUntilTerminal() async throws {
        let (client, http) = captureClient(script: [registryAction("queued"), registryAction("submitted"), registryAction("succeeded")])
        let action = try await client.registrations.waitForAction(id: "a1")
        #expect(action.state == .succeeded)
        #expect(action.charged == "12.00")
        #expect(http.trail == ["GET /domains/actions/a1", "GET /domains/actions/a1", "GET /domains/actions/a1"])
    }

    @Test func failedActionsAreReturnedNotThrown() async throws {
        let (client, _) = captureClient(script: [vpsAction("claimed"), vpsAction("failed")])
        let action = try await client.vps.waitForAction(id: "a1")
        #expect(action.state == .failed)
    }

    @Test func unknownStatesKeepPolling() async throws {
        let (client, http) = captureClient(script: [vpsAction("brand-new-state"), vpsAction("cancelled")])
        let action = try await client.vps.waitForAction(id: "a1")
        #expect(action.state == .cancelled)
        #expect(http.count == 2)
    }
}

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