Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Test Vectors to be Correct Naming Schema #145

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,68 @@ import com.fasterxml.jackson.databind.JsonNode
import org.junit.jupiter.api.Test
import tbdex.sdk.protocol.models.Close
import tbdex.sdk.protocol.models.Message
import tbdex.sdk.protocol.models.Offering
import tbdex.sdk.protocol.models.Order
import tbdex.sdk.protocol.models.OrderStatus
import tbdex.sdk.protocol.models.Quote
import tbdex.sdk.protocol.models.Resource
import tbdex.sdk.protocol.models.Rfq
import tbdex.sdk.protocol.serialization.Json
import kotlin.test.assertEquals
import kotlin.test.assertIs
import kotlin.test.assertNotNull

class TbdexTestVectorsMessageTest {
class TbdexTestVectorsProtocol {
/**
* Tbdex Test Vectors Message Tests
*/
@Test
fun `parse-close json`() {
fun parse_close() {
val vector = TestVectors.getVector("parse-close.json")
assertNotNull(vector)
testNonErrorTestVector<Close>(vector)
testNonErrorMessageTestVector<Close>(vector)
}

@Test
fun `parse-order json`() {
fun parse_order() {
val vector = TestVectors.getVector("parse-order.json")
assertNotNull(vector)
testNonErrorTestVector<Order>(vector)
testNonErrorMessageTestVector<Order>(vector)
}

@Test
fun `parse-orderstatus json`() {
fun parse_orderstatus() {
val vector = TestVectors.getVector("parse-orderstatus.json")
assertNotNull(vector)
testNonErrorTestVector<OrderStatus>(vector)
testNonErrorMessageTestVector<OrderStatus>(vector)
}


@Test
fun `parse-quote json`() {
fun parse_quote() {
val vector = TestVectors.getVector("parse-quote.json")
assertNotNull(vector)
testNonErrorTestVector<Quote>(vector)
testNonErrorMessageTestVector<Quote>(vector)
}

@Test
fun `parse-rfq json`() {
fun parse_rfq() {
val vector = TestVectors.getVector("parse-rfq.json")
assertNotNull(vector)
testNonErrorTestVector<Rfq>(vector)
testNonErrorMessageTestVector<Rfq>(vector)
}

private inline fun <reified T> testNonErrorTestVector(vector: JsonNode) {
/**
* Tbdex Test Vectors Resource Tests
*/
@Test
fun parse_offering() {
val vector = TestVectors.getVector("parse-offering.json")
assertNotNull(vector)
testNonErrorResourceTestVector<Offering>(vector)
}

private inline fun <reified T> testNonErrorMessageTestVector(vector: JsonNode) {
val input = vector["input"].textValue()
assertNotNull(input)

Expand All @@ -60,6 +75,16 @@ class TbdexTestVectorsMessageTest {
assertEquals(vector["output"], Json.jsonMapper.readTree(tbDEXMessage.toString()))
}

private inline fun <reified T> testNonErrorResourceTestVector(vector: JsonNode) {
val input = vector["input"].textValue()
assertNotNull(input)

val tbDEXMessage = Resource.parse(input)
assertIs<T>(tbDEXMessage)

assertEquals(vector["output"], Json.jsonMapper.readTree(tbDEXMessage.toString()))
}

// When we create test vectors with `error: true`
// private fun testErrorTestVector(vector: JsonNode) {
// val input = vector["input"].textValue()
Expand Down

This file was deleted.

Loading