Skip to content

Commit

Permalink
Test refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
phoebe-lew committed Oct 20, 2023
1 parent 75c485d commit 935e018
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import com.networknt.schema.JsonSchemaFactory
import com.networknt.schema.SpecVersion
import org.erdtman.jcs.JsonCanonicalizer
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow

Expand Down Expand Up @@ -45,46 +47,26 @@ class PresentationDefinitionTest {
)
)
val serializedPd = jsonMapper.writeValueAsString(pd)
println(serializedPd)

assertThat(serializedPd).contains("input_descriptors")
assertThat(serializedPd).contains("123")
}

@Test
fun `serialization is idempotent`(){
val pdString = PRESENTATION_DEFINITION.trimIndent()
val parsedPd = jsonMapper.readValue(pdString, PresentationDefinitionV2::class.java)
val parsedString = jsonMapper.writeValueAsString(parsedPd)

assertEquals(
JsonCanonicalizer(PRESENTATION_DEFINITION).encodedString,
JsonCanonicalizer(parsedString).encodedString,
)
}

@Test
fun `can deserialize`() {
val pdString = """
{
"id": "398f69f3-a3d4-4fb1-939a-82281671f7e5",
"input_descriptors": [
{
"id": "0edade78-ed51-44ae-a0fd-5636372c0978",
"constraints": {
"fields": [
{
"path": [
"${'$'}.issuer"
],
"filter": {
"type": "string",
"const": "did:ion:EiD6Jcwrqb5lFLFWyW59uLizo5lBuChieiqtd0TFN0xsng:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJ6cC1mNnFMTW1EazZCNDFqTFhIXy1kd0xOLW9DS2lTcDJaa19WQ2t4X3ZFIiwicHVibGljS2V5SndrIjp7ImNydiI6InNlY3AyNTZrMSIsImt0eSI6IkVDIiwieCI6IjNmVFk3VXpBaU9VNVpGZ05VVjl3bm5pdEtGQk51RkNPLWxlRXBDVzhHOHMiLCJ5IjoidjJoNlRqTDF0TnYwSDNWb09Fbll0UVBxRHZOVC0wbVdZUUdLTGRSakJ3ayJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpQjk3STI2bmUwdkhXYXduODk1Y1dnVlE0cFF5NmN1OUFlSzV2aW44X3JVeXcifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaURqSmlEdm9RekstRl94V05VVzlzMTBUVmlpdEI0Z1JoS09iYlh2S1pwdlNRIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlCbEk1NWx6b3JoeE42TVBqUlZtV2ZZY3MxNzNKOFk3S0hTeU5LcmZiTzVfdyJ9fQ"
}
},
{
"path": [
"${'$'}.type[*]"
],
"filter": {
"type": "string",
"pattern": "^SanctionCredential${'$'}"
}
}
]
}
}
]
}
""".trimIndent()
val pdString = PRESENTATION_DEFINITION.trimIndent()

assertDoesNotThrow { jsonMapper.readValue(pdString, PresentationDefinitionV2::class.java) }
}
Expand Down
34 changes: 34 additions & 0 deletions credentials/src/test/kotlin/web5/sdk/credentials/TestData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package web5.sdk.credentials

const val PRESENTATION_DEFINITION = """
{
"id": "398f69f3-a3d4-4fb1-939a-82281671f7e5",
"input_descriptors": [
{
"id": "0edade78-ed51-44ae-a0fd-5636372c0978",
"constraints": {
"fields": [
{
"path": [
"${'$'}.issuer"
],
"filter": {
"type": "string",
"const": "did:ion:EiD6Jcwrqb5lFLFWyW59uLizo5lBuChieiqtd0TFN0xsng:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJ6cC1mNnFMTW1EazZCNDFqTFhIXy1kd0xOLW9DS2lTcDJaa19WQ2t4X3ZFIiwicHVibGljS2V5SndrIjp7ImNydiI6InNlY3AyNTZrMSIsImt0eSI6IkVDIiwieCI6IjNmVFk3VXpBaU9VNVpGZ05VVjl3bm5pdEtGQk51RkNPLWxlRXBDVzhHOHMiLCJ5IjoidjJoNlRqTDF0TnYwSDNWb09Fbll0UVBxRHZOVC0wbVdZUUdLTGRSakJ3ayJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpQjk3STI2bmUwdkhXYXduODk1Y1dnVlE0cFF5NmN1OUFlSzV2aW44X3JVeXcifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaURqSmlEdm9RekstRl94V05VVzlzMTBUVmlpdEI0Z1JoS09iYlh2S1pwdlNRIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlCbEk1NWx6b3JoeE42TVBqUlZtV2ZZY3MxNzNKOFk3S0hTeU5LcmZiTzVfdyJ9fQ"
}
},
{
"path": [
"${'$'}.type[*]"
],
"filter": {
"type": "string",
"pattern": "^SanctionCredential${'$'}"
}
}
]
}
}
]
}
"""

0 comments on commit 935e018

Please sign in to comment.