Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
larousso committed Sep 17, 2019
1 parent b6abe63 commit f5b7f24
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions izanami-server/test/domains/feature/FeatureSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ class FeatureSpec extends IzanamiSpec with ScalaFutures with IntegrationPatience

}

"Deserialize DefaultFeature without enabled" in {
import FeatureInstances._
val json = Json.parse("""
|{
| "id": "id",
| "activationStrategy": "NO_STRATEGY"
|}
""".stripMargin)

val result = json.validate[Feature]
result mustBe an[JsSuccess[_]]

result.get must be(DefaultFeature(Key("id"), false, None))
}

"Deserialize GlobalScriptFeature" in {
import FeatureInstances._
val json = Json.parse("""
Expand All @@ -102,6 +117,23 @@ class FeatureSpec extends IzanamiSpec with ScalaFutures with IntegrationPatience

}

"Deserialize GlobalScriptFeature without enabled" in {
import FeatureInstances._
val json = Json.parse("""
|{
| "id": "id",
| "activationStrategy": "GLOBAL_SCRIPT",
| "parameters": { "ref": "ref" }
|}
""".stripMargin)

val result = json.validate[Feature]
result mustBe an[JsSuccess[_]]

result.get must be(GlobalScriptFeature(Key("id"), false, None, "ref"))

}

"Deserialize ScriptFeature" in {
import FeatureInstances._
val json = Json.parse("""
Expand All @@ -120,6 +152,23 @@ class FeatureSpec extends IzanamiSpec with ScalaFutures with IntegrationPatience

}

"Deserialize ScriptFeature without enabled" in {
import FeatureInstances._
val json = Json.parse("""
|{
| "id": "id",
| "activationStrategy": "SCRIPT",
| "parameters": { "script": "script" }
|}
""".stripMargin)

val result = json.validate[Feature]
result mustBe an[JsSuccess[_]]

result.get must be(ScriptFeature(Key("id"), false, None, JavascriptScript("script")))

}

"Deserialize ReleaseDateFeature" in {
import FeatureInstances._
val json =
Expand All @@ -139,6 +188,24 @@ class FeatureSpec extends IzanamiSpec with ScalaFutures with IntegrationPatience

}

"Deserialize ReleaseDateFeature without enabled" in {
import FeatureInstances._
val json =
Json.parse("""
|{
| "id": "id",
| "activationStrategy": "RELEASE_DATE",
| "parameters": { "releaseDate": "01/01/2017 12:12:12" }
|}
""".stripMargin)

val result = json.validate[Feature]
result mustBe an[JsSuccess[_]]

result.get must be(ReleaseDateFeature(Key("id"), false, None, LocalDateTime.of(2017, 1, 1, 12, 12, 12)))

}

"Deserialize ReleaseDateFeature other format" in {
import FeatureInstances._
val json =
Expand Down Expand Up @@ -179,6 +246,25 @@ class FeatureSpec extends IzanamiSpec with ScalaFutures with IntegrationPatience

}

"Deserialize HourRangeFeature without enabled" in {
import FeatureInstances._
val json =
Json.parse("""
|{
| "id": "id",
| "activationStrategy": "HOUR_RANGE",
| "parameters": {
| "startAt": "02:15",
| "endAt": "17:30"
| }
|}""".stripMargin)

val result = json.validate[Feature]
result mustBe an[JsSuccess[_]]

result.get must be(HourRangeFeature(Key("id"), false, None, LocalTime.of(2, 15), LocalTime.of(17, 30)))
}

}

"Feature Serialisation" should {
Expand Down

0 comments on commit f5b7f24

Please sign in to comment.