Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
larousso committed Oct 10, 2024
1 parent 43540c0 commit 0b3ed63
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nio-server/test/models/ModelValidationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ModelValidationSpec extends AnyWordSpecLike with Matchers {
val now: LocalDateTime = LocalDateTime.now(Clock.systemUTC)

"Validation ConsentFact" should {

val consentFact: ConsentFact = ConsentFact(
_id = "1",
userId = "user1",
Expand All @@ -30,7 +31,8 @@ class ModelValidationSpec extends AnyWordSpecLike with Matchers {
Consent(
key = "g1c1",
label = "group 1 consent 1",
checked = false
checked = false,
expiredAt = Some(LocalDateTime.now().plusMinutes(20))
),
Consent(
key = "g1c2",
Expand Down
68 changes: 68 additions & 0 deletions nio-server/test/models/OrganisationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import org.scalatest.wordspec.AnyWordSpecLike
import org.scalatestplus.play.PlaySpec
import play.api.libs.json.Json

import java.util.concurrent.TimeUnit
import scala.concurrent.duration.FiniteDuration

class OrganisationSpec extends PlaySpec with AnyWordSpecLike {

"Organisation" should {
Expand Down Expand Up @@ -189,4 +192,69 @@ println(Json.prettyPrint(json))
fromJson.map(_.key) mustBe Right(org.key)
}


"serialize/deserialize from XML with validity" in {
val org = Organisation(
_id = "cf",
key = "maif",
label = "test org",
version = VersionInfo(),
groups = Seq(
PermissionGroup(
key = "a",
label = "a",
permissions = Seq(
Permission(
key = "a1",
label = "a1",
validityPeriod = Some(FiniteDuration(1, TimeUnit.DAYS))
),
Permission(
key = "a2",
label = "a2"
)
)
)
)
)

val xml = org.asXml()

val fromXml = Organisation.fromXml(xml)

fromXml.map(_.key) mustBe Right(org.key)
}

"serialize/deserialize from JSON with validity" in {
val org = Organisation(
_id = "cf",
key = "maif",
label = "test org",
version = VersionInfo(),
groups = Seq(
PermissionGroup(
key = "a",
label = "a",
permissions = Seq(
Permission(
key = "a1",
label = "a1",
validityPeriod = Some(FiniteDuration(1, TimeUnit.DAYS))
),
Permission(
key = "a2",
label = "a2"
)
)
)
)
)

val json = org.asJson()

val fromJson = Organisation.fromJson(json)

fromJson.map(_.key) mustBe Right(org.key)
}

}

0 comments on commit 0b3ed63

Please sign in to comment.