aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialIssueFormatSuite.scala
diff options
context:
space:
mode:
authorKseniya Tomskikh <ktomskih@datamonsters.co>2017-08-11 14:40:19 +0600
committerKseniya Tomskikh <ktomskih@datamonsters.co>2017-08-11 14:41:30 +0600
commitbfac6a54dcf37e0280cc8f2ec6ff3802dc8e8dfe (patch)
tree2d66348851ad61b43cc0cb114aa56537cedad926 /src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialIssueFormatSuite.scala
parent9e60edb6216fce615b13f9bcc68d8f86258b85c3 (diff)
downloadrest-query-bfac6a54dcf37e0280cc8f2ec6ff3802dc8e8dfe.tar.gz
rest-query-bfac6a54dcf37e0280cc8f2ec6ff3802dc8e8dfe.tar.bz2
rest-query-bfac6a54dcf37e0280cc8f2ec6ff3802dc8e8dfe.zip
PDSUI-2188 Created and fixed test for json formats for ReP and TM
Diffstat (limited to 'src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialIssueFormatSuite.scala')
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialIssueFormatSuite.scala49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialIssueFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialIssueFormatSuite.scala
new file mode 100644
index 0000000..02e14ba
--- /dev/null
+++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialIssueFormatSuite.scala
@@ -0,0 +1,49 @@
+package xyz.driver.pdsuidomain.formats.json.sprayformats
+
+import java.time.LocalDateTime
+
+import spray.json._
+import org.scalatest.{FlatSpec, Matchers}
+import xyz.driver.pdsuicommon.domain.{LongId, StringId}
+import xyz.driver.pdsuidomain.entities.TrialIssue
+
+class TrialIssueFormatSuite extends FlatSpec with Matchers {
+ import trialissue._
+
+ "Json format for TrialIssue" should "read and write correct JSON" in {
+ val trialIssue = TrialIssue(
+ id = LongId(10),
+ trialId = StringId("NCT000001"),
+ userId = StringId("userId-001"),
+ lastUpdate = LocalDateTime.parse("2017-08-10T18:00:00"),
+ isDraft = false,
+ text = "message text",
+ evidence = "evidence",
+ archiveRequired = false,
+ meta = "{}"
+ )
+ val writtenJson = trialIssueWriter.write(trialIssue)
+
+ writtenJson should be(
+ """{"id":10,"userId":"userId-001","lastUpdate":"2017-08-10T18:00Z","isDraft":false,
+ "text":"message text","evidence":"evidence","archiveRequired":false,"meta":"{}"}""".parseJson)
+
+ val createTrialIssueJson = """{"text":"message text","evidence":"evidence","meta":"{}"}""".parseJson
+ val expectedCreatedTrialIssue = trialIssue.copy(id = LongId(0), lastUpdate = LocalDateTime.MIN, isDraft = true)
+ val parsedCreateTrialIssue = jsValueToTrialIssue(createTrialIssueJson, StringId("NCT000001"), StringId("userId-001"))
+ parsedCreateTrialIssue should be(expectedCreatedTrialIssue)
+
+ val updateTrialIssueJson =
+ """{"text":"new issue text","evidence":"issue evidence","archiveRequired":true,
+ "meta":"{\"startPage\":1.0,\"endPage\":2.0}"}""".parseJson
+ val expectedUpdatedTrialIssue = trialIssue.copy(
+ text = "new issue text",
+ evidence = "issue evidence",
+ archiveRequired = true,
+ meta = """{"startPage":1.0,"endPage":2.0}"""
+ )
+ val parsedUpdateTrialIssue = applyUpdateToTrialIssue(updateTrialIssueJson, trialIssue)
+ parsedUpdateTrialIssue should be(expectedUpdatedTrialIssue)
+ }
+
+}