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)
}
}
}