-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove escaping of json, write tests to check stringified json and no…
…n stringified json, add changelog
- Loading branch information
1 parent
e1673a4
commit dddd95a
Showing
3 changed files
with
30 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 27 additions & 25 deletions
52
service/src/test/kotlin/io/provenance/explorer/domain/extensions/ExtenstionsKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,34 @@ | ||
package io.provenance.explorer.domain.extensions | ||
|
||
import org.junit.jupiter.api.Tag | ||
Check failure on line 3 in service/src/test/kotlin/io/provenance/explorer/domain/extensions/ExtenstionsKtTest.kt GitHub Actions / ktlint
|
||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.Assertions.* | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.databind.node.ObjectNode | ||
import org.apache.commons.lang3.StringEscapeUtils | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
|
||
class ExtensionsKtTest { | ||
|
||
@Test | ||
fun toObjectNode() { | ||
// // Given an input JSON string | ||
// val inputJson = "{\"key\":\"value\"}" | ||
// | ||
// // Create an ObjectMapper for testing | ||
// val objectMapper = ObjectMapper() | ||
// | ||
// // Escape the input JSON | ||
// val escapedInput = StringEscapeUtils.escapeJson(inputJson) | ||
// | ||
// // Convert the escaped JSON to an ObjectNode | ||
// val resultObjectNode = escapedInput.toObjectNode(objectMapper) | ||
// | ||
// // Create an expected ObjectNode | ||
// val expectedObjectNode = objectMapper.createObjectNode() | ||
// expectedObjectNode.put("key", "value") | ||
// | ||
// // Assert that the result ObjectNode is equal to the expected ObjectNode | ||
// assertEquals(expectedObjectNode, resultObjectNode) | ||
@Tag("junit-jupiter") | ||
fun testToObjectNode() { | ||
val inputJsonWithJsonStrObj = "{\"amount\":\"1\",\"denom\":\"psa.3zlqy2ecncvalbycokxnoh.stock\",\"memo\":\"{\\\"marker\\\":{\\\"transfer-auths\\\":[\\\"tp19zf8q9swrsspkdljumwh04zjac4nkfvju6ehl9\\\",\\\"tp1tk6fqws0su7fzp090edrauaa756mdyjfdw0507\\\",\\\"tp1a53udazy8ayufvy0s434pfwjcedzqv34vfvvyc\\\"],\\\"allow-force-transfer\\\":false}}\",\"receiver\":\"tp12wyy028sd3yf3j0z950fq5p3zvzgpzgds3dqp3\",\"sender\":\"tp12wyy028sd3yf3j0z950fq5p3zvzgpzgds3dqp3\"}" | ||
val inputFormatedJsonWithJsonStrObj = "{\n" + | ||
" \"amount\": \"1\",\n" + | ||
" \"denom\": \"psa.3zlqy2ecncvalbycokxnoh.stock\",\n" + | ||
" \"memo\": \"{\\\"marker\\\":{\\\"transfer-auths\\\":[\\\"tp19zf8q9swrsspkdljumwh04zjac4nkfvju6ehl9\\\",\\\"tp1tk6fqws0su7fzp090edrauaa756mdyjfdw0507\\\",\\\"tp1a53udazy8ayufvy0s434pfwjcedzqv34vfvvyc\\\"],\\\"allow-force-transfer\\\":false}}\",\n" + | ||
" \"receiver\": \"tp12wyy028sd3yf3j0z950fq5p3zvzgpzgds3dqp3\",\n" + | ||
" \"sender\": \"tp12wyy028sd3yf3j0z950fq5p3zvzgpzgds3dqp3\"\n" + | ||
"}" | ||
|
||
val tests = mapOf( | ||
"test input with string that has json string as value for memo" to inputJsonWithJsonStrObj, | ||
"test input with formatted json and json string as value for memo" to inputFormatedJsonWithJsonStrObj | ||
) | ||
|
||
for ((testname, json) in tests) { | ||
val actualJsonObj = json.toObjectNode() | ||
assertEquals("tp12wyy028sd3yf3j0z950fq5p3zvzgpzgds3dqp3", actualJsonObj.get("receiver").asText(), testname) | ||
assertEquals("tp12wyy028sd3yf3j0z950fq5p3zvzgpzgds3dqp3", actualJsonObj.get("sender").asText(), testname) | ||
assertEquals("1", actualJsonObj.get("amount").asText(), testname) | ||
assertEquals("psa.3zlqy2ecncvalbycokxnoh.stock", actualJsonObj.get("denom").asText(), testname) | ||
assertEquals("{\"marker\":{\"transfer-auths\":[\"tp19zf8q9swrsspkdljumwh04zjac4nkfvju6ehl9\",\"tp1tk6fqws0su7fzp090edrauaa756mdyjfdw0507\",\"tp1a53udazy8ayufvy0s434pfwjcedzqv34vfvvyc\"],\"allow-force-transfer\":false}}", actualJsonObj.get("memo").asText(), testname) | ||
} | ||
} | ||
} | ||
} |