import Foundation
import Testing
@testable import IrdAPI
@Suite struct EnumTests {
@Test func unknownValuesRoundTripAsUnrecognized() throws {
let decoded = try JSONDecoder().decode([InstanceState].self, from: Data(#"["running","hibernating"]"#.utf8))
#expect(decoded == [.running, .unrecognized("hibernating")])
#expect(decoded[1].rawValue == "hibernating")
let encoded = String(decoding: try JSONEncoder().encode(decoded), as: UTF8.self)
#expect(encoded == #"["running","hibernating"]"#)
}
@Test func knownListsEverySpecValue() {
#expect(InstanceState.known.contains(.running))
#expect(!InstanceState.known.isEmpty)
#expect(JobStatus.known == [.queued, .processing, .succeeded, .failed])
#expect(UploadFormat(rawValue: "car") == .car)
#expect(MetricSeriesUnit.bytesPerSecond.rawValue == "bytes/s")
}
@Test func jobSpecCarriesTheDiscriminator() throws {
let spec = JobSpec.embedding(EmbeddingJob(input: "hello"))
let json = try JSONValue(encoding: spec)
#expect(json["type"] == "embedding")
#expect(json["input"] == "hello")
#expect(try JSONDecoder().decode(JobSpec.self, from: try json.serialized()) == spec)
#expect(spec.type == "embedding")
}
@Test func metricPointsAreArrays() throws {
let series = try JSONDecoder().decode(MetricSeries.self, from: Data(#"{"name":"cpu","unit":"percent","points":[[1700000000,12.5]]}"#.utf8))
#expect(series.points == [MetricPoint(timestamp: 1_700_000_000, value: 12.5)])
#expect(String(decoding: try JSONEncoder().encode(series.points), as: UTF8.self) == "[[1700000000,12.5]]")
}
}