aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatSuite.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/InterventionFormatSuite.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/InterventionFormatSuite.scala')
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatSuite.scala63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatSuite.scala
new file mode 100644
index 0000000..784a655
--- /dev/null
+++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatSuite.scala
@@ -0,0 +1,63 @@
+package xyz.driver.pdsuidomain.formats.json.sprayformats
+
+import spray.json._
+import org.scalatest.{FlatSpec, Matchers}
+import xyz.driver.pdsuicommon.domain.{LongId, StringId}
+import xyz.driver.pdsuidomain.entities.{Intervention, InterventionArm, InterventionType, InterventionWithArms}
+
+class InterventionFormatSuite extends FlatSpec with Matchers {
+ import intervention._
+
+ "Json format for Intervention" should "read and write correct JSON" in {
+ val intervention = Intervention(
+ id = LongId(1),
+ trialId = StringId("NCT000001"),
+ name = "intervention name",
+ originalName = "orig name",
+ typeId = Some(LongId(10)),
+ originalType = Some("orig type"),
+ description = "",
+ originalDescription = "",
+ isActive = true
+ )
+ val arms = List(
+ InterventionArm(interventionId = intervention.id, armId = LongId(20)),
+ InterventionArm(interventionId = intervention.id, armId = LongId(21)),
+ InterventionArm(interventionId = intervention.id, armId = LongId(22))
+ )
+ val orig = InterventionWithArms(
+ intervention = intervention,
+ arms = arms
+ )
+ val writtenJson = interventionWriter.write(orig)
+
+ writtenJson should be(
+ """{"id":1,"name":"intervention name","typeId":10,"description":"","isActive":true,"arms":[20,21,22],
+ "trialId":"NCT000001","originalName":"orig name","originalDescription":"","originalType":"orig type"}""".parseJson)
+
+ val updateInterventionJson = """{"description":"descr","arms":[21,22]}""".parseJson
+ val expectedUpdatedIntervention = orig.copy(
+ intervention = intervention.copy(description = "descr"),
+ arms = List(
+ InterventionArm(interventionId = intervention.id, armId = LongId(21)),
+ InterventionArm(interventionId = intervention.id, armId = LongId(22))
+ )
+ )
+ val parsedUpdateIntervention = applyUpdateToInterventionWithArms(updateInterventionJson, orig)
+ parsedUpdateIntervention should be(expectedUpdatedIntervention)
+ }
+
+ "Json format for InterventionType" should "read and write correct JSON" in {
+ val interventionType = InterventionType(
+ id = LongId(10),
+ name = "type name"
+ )
+ val writtenJson = interventionTypeFormat.write(interventionType)
+
+ writtenJson should be("""{"id":10,"name":"type name"}""".parseJson)
+
+ val parsedInterventionType = interventionTypeFormat.read(writtenJson)
+ parsedInterventionType should be(interventionType)
+ }
+
+}