aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/xyz/driver/pdsuidomain/formats/json/PatientHistoryFormatSuite.scala
blob: 74f6f7098b072ca3f50395b0450eabe2bc34b248 (plain) (blame)
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
package xyz.driver.pdsuidomain.formats.json

import java.time.LocalDateTime

import org.scalatest.{FlatSpec, Matchers}
import spray.json._
import xyz.driver.pdsuicommon.domain.{LongId, UuidId}
import xyz.driver.pdsuidomain.entities.PatientHistory

class PatientHistoryFormatSuite extends FlatSpec with Matchers {
  import xyz.driver.pdsuidomain.formats.json.patienthistory._

  "Json format for PatientHistory" should "read and write correct JSON" in {
    val patientHistory = PatientHistory(
      id = LongId(10),
      patientId = UuidId("40892a07-c638-49d2-9795-1edfefbbcc7c"),
      executor = xyz.driver.core.Id("userId-001"),
      state = PatientHistory.State.Verify,
      action = PatientHistory.Action.Start,
      created = LocalDateTime.parse("2017-08-10T18:00:00")
    )
    val writtenJson = patientHistoryFormat.write(patientHistory)

    writtenJson should be(
      """{"id":10,"executor":"userId-001","patientId":"40892a07-c638-49d2-9795-1edfefbbcc7c","state":"Verify",
        "action":"Start","created":"2017-08-10T18:00Z"}""".parseJson)

    val parsedPatientHistory = patientHistoryFormat.read(writtenJson)
    parsedPatientHistory should be(patientHistory)
  }

}