api-swift / Tests / IrdAPITests / Live / LiveSmokeTests.swift
283 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import Foundation
import Testing
@testable import IrdAPI

/// Read-only smoke tests against the live API. Set `IRD_API_KEY` to enable; nothing is
/// created and nothing beyond metered reads is charged. The key is read from the
/// environment only — never from a file in this repo.
enum LiveEnv {
    static var apiKey: String? { ProcessInfo.processInfo.environment["IRD_API_KEY"].flatMap { $0.isEmpty ? nil : $0 } }
    static var client: IrdClient { IrdClient(apiKey: apiKey ?? "") }
}

@Suite(.enabled(if: LiveEnv.apiKey != nil), .serialized) struct LiveSmokeTests {
    @Test func anonymousAvailabilityCheckWorks() async throws {
        let check = try await IrdClient().domains.check(domain: "ird.ro")
        #expect(check.domain == "ird.ro")
        #expect(check.status == .registered || check.status == .unrecognized(check.status.rawValue))
    }

    @Test func balanceCarriesMoneyAsStrings() async throws {
        let balance = try await LiveEnv.client.credits.balance()
        #expect(Decimal(string: balance.total) != nil)
        for b in balance.balances { #expect(Decimal(string: b.balance) != nil) }
        #expect(balance.spend.windowDays > 0)
    }

    @Test func catalogsDecode() async throws {
        let client = LiveEnv.client
        let tiers = try await client.vps.listTiers()
        #expect(!tiers.tiers.isEmpty)
        _ = try await client.vps.listSystemImages()
        _ = try await client.ipfs.usage()
        _ = try await client.p2p.usage()
        let prices = try await client.credits.prices()
        #expect(!prices.prices.isEmpty)
    }

    @Test func gatewayPinsPagesAgreeWithTheTotal() async throws {
        let client = LiveEnv.client
        guard let gateway = try await client.ipfs.listDomains().domains.first else { return }
        let page = try await client.ipfs.listDomainPins(id: gateway.id, query: ListDomainPinsQuery(limit: 1))
        let all = try await client.ipfs.listAllDomainPins(id: gateway.id)
        #expect(all.count == page.total)
        let e = await caught { _ = try await client.ipfs.getDomain(id: "does-not-exist") }
        #expect(e?.status == 404)
    }

    @Test func apiKeysGet401OnAccountOnlyEndpoints() async throws {
        let e = await caught { _ = try await LiveEnv.client.sharing.listGrants() }
        #expect(e?.status == 401)
        #expect(e?.isAuth == true)
    }

    @Test func p2pAppsCarryBooleanMailboxFlags() async throws {
        for app in try await LiveEnv.client.p2p.listApps().apps {
            #expect(app.mailboxEnabled == true || app.mailboxEnabled == false)
        }
    }
}

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