jevResult

fun jevResult(body: JsonObject, questions: QuestionSet, model: String = JevDefaults.MODEL, requestId: String? = null): JevResult(source)

A JevResult built from a raw response body, as JevApi.evaluate would have returned it for questions.

val jev = mockk<JevApi>()
coEvery { jev.evaluate(any(), any(), any()) } returns
jevResult("""{"answers":{"urgent":{"type":"noul","noul":0.92}}}""", Triage.questions)

The body is validated exactly as a real one is, so a malformed answer raises JevResponseValidationException here too. Recording a real response and replaying it is a good way to keep a fixture honest.

A result answers only the handles of the set it was built for. Code that builds its questions on each call (inline handles, or a JevQuery class) sends a new set every time, so build the result from the one the mock received:

coEvery { jev.evaluate(any(), any(), any()) } answers { jevResult(body, secondArg()) }

fun jevResult(body: String, questions: QuestionSet, model: String = JevDefaults.MODEL, requestId: String? = null): JevResult(source)

The same, from the response body as JSON text. Text that isn't JSON, or isn't a JSON object, raises JevResponseValidationException, as it does from the client, so a garbled response can be simulated too. A leading byte-order mark is dropped, as the client drops one.