-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.kt
75 lines (65 loc) · 2.63 KB
/
Test.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package tech.rican
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.equals.shouldBeEqual
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.shouldBeTypeOf
import io.micronaut.serde.ObjectMapper
import io.micronaut.test.extensions.kotest5.annotation.MicronautTest
import tech.rican.model.Message
import tech.rican.model.Request
import tech.rican.model.TextMessage
@MicronautTest
class Test(
private val objectMapper: ObjectMapper
) : StringSpec({
"should serialize the payload" {
val request = Request().also {
it.projectId = "project-id"
it.message = Message().also {
it.id = "message-id"
it.direction = "direction"
it.conversationId = "conversation-id"
it.contactId = "contact-id"
it.contactMessage = TextMessage().also { it.text = "Body" }
}
}
//Attributes miss-placed
// conversation-id within wrapper object "text-response"
// contact-id within wrapper object "text-response"
val result = objectMapper.writeValueAsString(request)
//If deserialized back to Request.class it actually creates the correct object
}
"should deserialize the payload - broken" {
val payload = this::class.java.classLoader.getResourceAsStream("broken-payload-text.json")
val result = objectMapper.readValue(payload, Request::class.java)
result.should {
it.projectId.shouldBe("project-id")
it.message.should {
it.id.shouldBe("message-id")
it.direction.shouldBe("direction")
it.contactMessage.shouldBeTypeOf<TextMessage>().should {
it.text.shouldBe("body")
}
it.conversationId.shouldBe("conversation-id")
it.contactId.shouldBe("contact-id")
}
}
}
"should deserialize the payload - working" {
val payload = this::class.java.classLoader.getResourceAsStream("payload-text-diff-order.json")
val result = objectMapper.readValue(payload, Request::class.java)
result.should {
it.projectId.shouldBe("project-id")
it.message.should {
it.id.shouldBe("message-id")
it.direction.shouldBe("direction")
it.contactMessage.shouldBeTypeOf<TextMessage>().should {
it.text.shouldBe("body")
}
it.conversationId.shouldBe("conversation-id")
it.contactId.shouldBe("contact-id")
}
}
}
})