From 977e5e1a17a385fdc215251924da0a64228413b5 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 15 Nov 2017 14:49:50 +0700 Subject: Fixed json formats for DocumentHistory and MedicalRecordHistory; Added tests for them --- .../pdsuidomain/entities/DocumentHistory.scala | 2 +- .../pdsuidomain/formats/json/documenthistory.scala | 20 ++++++++++------ .../pdsuidomain/formats/json/recordhistory.scala | 27 ++++++++++++++++------ .../formats/json/DocumentHistoryFormatSuite.scala | 24 ++++++++++++++++--- .../json/MedicalRecordHistoryFormatSuite.scala | 26 ++++++++++++++++++--- 5 files changed, 78 insertions(+), 21 deletions(-) diff --git a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala index 43a1832..f076074 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/entities/DocumentHistory.scala @@ -61,7 +61,7 @@ object DocumentHistory { case object Resolve extends Action case object Flag extends Action case object Archive extends Action - case object PostEvidence extends Action + case object PostEvidence extends Action case object CreateDocument extends Action case object ReadDocument extends Action diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory.scala index ea79b92..1652f7b 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/documenthistory.scala @@ -10,18 +10,24 @@ object documenthistory { import common._ implicit val documentStateFormat = new EnumJsonFormat[State]( + "New" -> State.New, "Extract" -> State.Extract, + "Done" -> State.Done, "Review" -> State.Review, - "Flag" -> State.Flag + "Flag" -> State.Flag, + "Archive" -> State.Archive ) implicit val documentActionFormat = new EnumJsonFormat[Action]( - "Start" -> Action.Start, - "Submit" -> Action.Submit, - "Unassign" -> Action.Unassign, - "Resolve" -> Action.Resolve, - "Flag" -> Action.Flag, - "Archive" -> Action.Archive + "Start" -> Action.Start, + "Submit" -> Action.Submit, + "Unassign" -> Action.Unassign, + "Resolve" -> Action.Resolve, + "Flag" -> Action.Flag, + "Archive" -> Action.Archive, + "PostEvidence" -> Action.PostEvidence, + "CreateDocument" -> Action.CreateDocument, + "ReadDocument" -> Action.ReadDocument ) implicit val documentHistoryFormat: RootJsonFormat[DocumentHistory] = jsonFormat6(DocumentHistory.apply) diff --git a/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory.scala b/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory.scala index 8341f97..be9dae9 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/formats/json/recordhistory.scala @@ -10,19 +10,32 @@ object recordhistory { import common._ implicit val recordStateFormat = new EnumJsonFormat[State]( + "New" -> State.New, "Clean" -> State.Clean, "Organize" -> State.Organize, "Review" -> State.Review, - "Flag" -> State.Flag + "Done" -> State.Done, + "Flag" -> State.Flag, + "Archive" -> State.Archive ) implicit val recordActionFormat = new EnumJsonFormat[Action]( - "Start" -> Action.Start, - "Submit" -> Action.Submit, - "Unassign" -> Action.Unassign, - "Resolve" -> Action.Resolve, - "Flag" -> Action.Flag, - "Archive" -> Action.Archive + "Start" -> Action.Start, + "Submit" -> Action.Submit, + "Unassign" -> Action.Unassign, + "Resolve" -> Action.Resolve, + "Flag" -> Action.Flag, + "Archive" -> Action.Archive, + "SaveDuplicate" -> Action.SaveDuplicate, + "SaveReorder" -> Action.SaveReorder, + "SaveRotation" -> Action.SaveRotation, + "DeleteDuplicate" -> Action.DeleteDuplicate, + "DeleteReorder" -> Action.DeleteReorder, + "DeleteRotation" -> Action.DeleteRotation, + "CreateDocument" -> Action.CreateDocument, + "DeleteDocument" -> Action.DeleteDocument, + "CreateRecord" -> Action.CreateRecord, + "ReadRecord" -> Action.ReadRecord ) implicit val recordHistoryFormat: RootJsonFormat[MedicalRecordHistory] = jsonFormat6(MedicalRecordHistory.apply) diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/DocumentHistoryFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/DocumentHistoryFormatSuite.scala index 4dc4d00..d85a53b 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/DocumentHistoryFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/DocumentHistoryFormatSuite.scala @@ -2,15 +2,33 @@ package xyz.driver.pdsuidomain.formats.json import java.time.LocalDateTime -import org.scalatest.{FlatSpec, Matchers} +import org.scalatest.{FreeSpecLike, Matchers} import spray.json._ import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities.DocumentHistory -class DocumentHistoryFormatSuite extends FlatSpec with Matchers { +class DocumentHistoryFormatSuite extends FreeSpecLike with Matchers { import xyz.driver.pdsuidomain.formats.json.documenthistory._ - "Json format for DocumentHistory" should "read and write correct JSON" in { + "Can read and write DocumentHistory states" - { + val states = DocumentHistory.State.All + states.foreach { state =>s"$state" in test(state)} + } + + "Can read and write DocumentHistory actions" - { + val actions = DocumentHistory.Action.All + actions.foreach { action =>s"$action" in test(action)} + } + + private def test(state: DocumentHistory.State) = { + documentStateFormat.read(documentStateFormat.write(state)) shouldBe state + } + + private def test(action: DocumentHistory.Action) = { + documentActionFormat.read(documentActionFormat.write(action)) shouldBe action + } + + "Json format for DocumentHistory should read and write correct JSON" - { val documentHistory = DocumentHistory( id = LongId(10), documentId = LongId(1), diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/MedicalRecordHistoryFormatSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/MedicalRecordHistoryFormatSuite.scala index 88240cd..c34f8c0 100644 --- a/src/test/scala/xyz/driver/pdsuidomain/formats/json/MedicalRecordHistoryFormatSuite.scala +++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/MedicalRecordHistoryFormatSuite.scala @@ -2,15 +2,35 @@ package xyz.driver.pdsuidomain.formats.json import java.time.LocalDateTime -import org.scalatest.{FlatSpec, Matchers} +import org.scalatest.{FreeSpecLike, Matchers} import spray.json._ import xyz.driver.pdsuicommon.domain.LongId import xyz.driver.pdsuidomain.entities.MedicalRecordHistory -class MedicalRecordHistoryFormatSuite extends FlatSpec with Matchers { +class MedicalRecordHistoryFormatSuite extends FreeSpecLike with Matchers { import xyz.driver.pdsuidomain.formats.json.recordhistory._ - "Json format for MedicalRecordHistory" should "read and write correct JSON" in { + + "Can read and write MedicalRecordHistory states" - { + val states = MedicalRecordHistory.State.All + states.foreach { state =>s"$state" in test(state)} + } + + "Can read and write MedicalRecordHistory actions" - { + val actions = MedicalRecordHistory.Action.All + actions.foreach { action =>s"$action" in test(action)} + } + + private def test(state: MedicalRecordHistory.State) = { + recordStateFormat.read(recordStateFormat.write(state)) shouldBe state + } + + private def test(action: MedicalRecordHistory.Action) = { + recordActionFormat.read(recordActionFormat.write(action)) shouldBe action + } + + + "Json format for MedicalRecordHistory should read and write correct JSON" - { val recordHistory = MedicalRecordHistory( id = LongId(10), recordId = LongId(1), -- cgit v1.2.3