CHANGELOG_BEGIN (#3969)

- [JSON API - Experimental] When contract is not found, ``/contracts/lookup`` endpoint returns
  ``{"status":200,"result":null}`` instead of ``{"status":200,"result":{}}``.
  This is consistent with how DAML-LF JSON Encoding spec treats Optional.

CHANGELOG_END
This commit is contained in:
Leonid Shlyapnikov 2020-01-07 13:51:00 -05:00 committed by mergify[bot]
parent a8b4a84b08
commit 29d5995454
2 changed files with 22 additions and 4 deletions

View File

@ -152,7 +152,7 @@ class Endpoints(
): ET[Option[domain.ActiveContract[LfValue]]]
jsVal <- either(
ac.cata(x => lfAcToJsValue(x).leftMap(e => ServerError(e.shows)), \/-(JsObject()))
ac.cata(x => lfAcToJsValue(x).leftMap(e => ServerError(e.shows)), \/-(JsNull))
): ET[JsValue]
} yield jsVal

View File

@ -536,6 +536,25 @@ abstract class AbstractHttpServiceIntegrationTest
}: Future[Assertion]
}
"contracts/lookup returns {status:200, result:null} when contract is not found" in withHttpService {
(uri, _, _) =>
val owner = domain.Party("Alice")
val accountNumber = "abc123"
val locator = domain.EnrichedContractKey(
domain.TemplateId(None, "Account", "Account"),
JsArray(JsString(owner.unwrap), JsString(accountNumber))
)
postContractsLookup(locator, uri.withPath(Uri.Path("/contracts/lookup"))).flatMap {
case (status, output) =>
status shouldBe StatusCodes.OK
assertStatus(output, StatusCodes.OK)
output
.asJsObject(s"expected JsObject, got: $output")
.fields
.get("result") shouldBe Some(JsNull)
}: Future[Assertion]
}
"contracts/lookup by contractKey" in withHttpService { (uri, encoder, decoder) =>
val owner = domain.Party("Alice")
val accountNumber = "abc123"
@ -803,9 +822,8 @@ abstract class AbstractHttpServiceIntegrationTest
output
.asJsObject(errorMsg)
.getFields("result")
.headOption
.getOrElse(fail(errorMsg))
.fields
.getOrElse("result", fail(errorMsg))
.asJsObject(errorMsg)
}