aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentFormatSuite.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/DocumentFormatSuite.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/DocumentFormatSuite.scala')
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentFormatSuite.scala74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentFormatSuite.scala
new file mode 100644
index 0000000..9394735
--- /dev/null
+++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/DocumentFormatSuite.scala
@@ -0,0 +1,74 @@
+package xyz.driver.pdsuidomain.formats.json.sprayformats
+
+import java.time.{LocalDate, LocalDateTime}
+
+import spray.json._
+import org.scalatest.{FlatSpec, Matchers}
+import xyz.driver.pdsuicommon.domain.{LongId, TextJson}
+import xyz.driver.pdsuidomain.entities.Document
+
+class DocumentFormatSuite extends FlatSpec with Matchers {
+ import document._
+
+ "Json format for Document" should "read and write correct JSON" in {
+ val orig = Document(
+ id = LongId(1),
+ status = Document.Status.New,
+ assignee = None,
+ previousStatus = None,
+ previousAssignee = None,
+ lastActiveUserId = None,
+ lastUpdate = LocalDateTime.parse("2017-08-10T18:00:00"),
+ recordId = LongId(101),
+ physician = Some("physician"),
+ typeId = Some(LongId(10)),
+ providerName = Some("provider 21"),
+ providerTypeId = Some(LongId(21)),
+ requiredType = Some(Document.RequiredType.OPN),
+ meta = None,
+ startDate = None,
+ endDate = None
+ )
+ val writtenJson = documentFormat.write(orig)
+
+ writtenJson should be (
+ """{"id":1,"recordId":101,"physician":"physician","typeId":10,"provider":"provider 21","providerTypeId":21,
+ "requiredType":"OPN","startDate":null,"endDate":null,"status":"New","assignee":null,"previousStatus":null,
+ "previousAssignee":null,"lastActiveUser":null,"lastUpdate":"2017-08-10T18:00Z","meta":null}""".parseJson)
+
+ val createDocumentJson =
+ """{"recordId":101,"physician":"physician","typeId":10,"provider":"provider 21","providerTypeId":21}""".parseJson
+ val expectedCreatedDocument = orig.copy(
+ id = LongId(0),
+ lastUpdate = LocalDateTime.MIN,
+ requiredType = None
+ )
+ val parsedCreatedDocument = documentFormat.read(createDocumentJson)
+ parsedCreatedDocument should be(expectedCreatedDocument)
+
+ val updateDocumentJson =
+ """{"startDate":"2017-08-10","endDate":"2018-08-10","meta":{"predicted":true,"startPage":1.0,"endPage":2.0}}""".parseJson
+ val expectedUpdatedDocument = orig.copy(
+ startDate = Some(LocalDate.parse("2017-08-10")),
+ endDate = Some(LocalDate.parse("2018-08-10")),
+ meta = Some(TextJson(Document.Meta(predicted = Some(true), startPage = 1.0, endPage = 2.0)))
+ )
+ val parsedUpdatedDocument = applyUpdateToDocument(updateDocumentJson, orig)
+ parsedUpdatedDocument should be(expectedUpdatedDocument)
+ }
+
+ "Json format for Document.Meta" should "read and write correct JSON" in {
+ val meta = Document.Meta(predicted = None, startPage = 1.0, endPage = 2.0)
+ val writtenJson = documentMetaFormat.write(meta)
+ writtenJson should be ("""{"startPage":1.0,"endPage":2.0}""".parseJson)
+
+ val metaJsonWithoutPredicted = """{"startPage":1.0,"endPage":2.0}""".parseJson
+ val parsedMetaWithoutPredicted = documentMetaFormat.read(metaJsonWithoutPredicted)
+ parsedMetaWithoutPredicted should be(meta)
+
+ val metaJsonWithPredicted = """{"predicted":true,"startPage":1.0,"endPage":2.0}""".parseJson
+ val parsedMetaWithPredicted = documentMetaFormat.read(metaJsonWithPredicted)
+ parsedMetaWithPredicted should be(meta.copy(predicted = Some(true)))
+ }
+
+}