Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Arnaud Gourlay
committed
Oct 16, 2019
1 parent
0d894b8
commit 3d75cfa
Showing
3 changed files
with
90 additions
and
92 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
cornichon-core/src/test/scala/com/github/agourlay/cornichon/json/JsonStepsProperties.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.github.agourlay.cornichon.json | ||
|
||
import com.github.agourlay.cornichon.core.{ Scenario, ScenarioRunner, Session, SessionKey } | ||
import com.github.agourlay.cornichon.json.JsonSteps.JsonStepBuilder | ||
import com.github.agourlay.cornichon.steps.StepUtilSpec | ||
import io.circe.{ Json, JsonObject } | ||
import io.circe.testing.ArbitraryInstances | ||
import org.scalacheck.Properties | ||
import org.scalacheck.Prop._ | ||
import org.typelevel.claimant.Claim | ||
|
||
class JsonStepsProperties extends Properties("JsonSteps") with ArbitraryInstances with StepUtilSpec { | ||
|
||
private val testKey = "test-key" | ||
private val jsonStepBuilder = JsonStepBuilder(SessionKey(testKey), Some("test body")) | ||
|
||
property("JsonStepBuild is value") = | ||
forAll { input: String ⇒ | ||
val session = Session.newEmpty.addValuesUnsafe(testKey -> input) | ||
val step = jsonStepBuilder.is(input) | ||
val s = Scenario("scenario with JsonSteps", step :: Nil) | ||
val t = awaitFuture(ScenarioRunner.runScenario(session)(s)) | ||
Claim(t.isSuccess) | ||
} | ||
|
||
property("JsonStepBuild is value fail") = | ||
forAll { input: String ⇒ | ||
val session = Session.newEmpty.addValuesUnsafe(testKey -> input) | ||
val step = jsonStepBuilder.is(input + "42") | ||
val s = Scenario("scenario with JsonSteps", step :: Nil) | ||
val t = awaitFuture(ScenarioRunner.runScenario(session)(s)) | ||
Claim(!t.isSuccess) | ||
} | ||
|
||
property("JsonStepBuild isNot value") = | ||
forAll { input: String ⇒ | ||
val session = Session.newEmpty.addValuesUnsafe(testKey -> input) | ||
val step = jsonStepBuilder.isNot(input + "42") | ||
val s = Scenario("scenario with JsonSteps", step :: Nil) | ||
val t = awaitFuture(ScenarioRunner.runScenario(session)(s)) | ||
Claim(t.isSuccess) | ||
} | ||
|
||
property("JsonStepBuild isNot value fail") = | ||
forAll { input: String ⇒ | ||
val session = Session.newEmpty.addValuesUnsafe(testKey -> input) | ||
val step = jsonStepBuilder.isNot(input) | ||
val s = Scenario("scenario with JsonSteps", step :: Nil) | ||
val t = awaitFuture(ScenarioRunner.runScenario(session)(s)) | ||
Claim(!t.isSuccess) | ||
} | ||
|
||
property("JsonStepBuilder is any Circe jsonObject") = | ||
forAll { jsonOb: JsonObject ⇒ | ||
val json = Json.fromJsonObject(jsonOb) | ||
val session = Session.newEmpty.addValuesUnsafe(testKey -> json.spaces2) | ||
val step = jsonStepBuilder.is(json) | ||
val s = Scenario("scenario with JsonSteps", step :: Nil) | ||
val t = awaitFuture(ScenarioRunner.runScenario(session)(s)) | ||
Claim(t.isSuccess) | ||
} | ||
|
||
property("JsonStepBuilder is any Circe jsonObject with placeholder") = | ||
forAll { jsonOb: JsonObject ⇒ | ||
val fullJsonObj = jsonOb.add("myKeyOther", Json.fromString("myOtherValue")) | ||
val session = Session.newEmpty.addValuesUnsafe( | ||
testKey -> Json.fromJsonObject(fullJsonObj).spaces2, | ||
"a-placeholder" -> "myOtherValue" | ||
) | ||
val fullPlaceholderJsonObj = jsonOb.add("myKeyOther", Json.fromString("<a-placeholder>")) | ||
val step = jsonStepBuilder.is(Json.fromJsonObject(fullPlaceholderJsonObj)) | ||
val s = Scenario("scenario with JsonSteps", step :: Nil) | ||
val t = awaitFuture(ScenarioRunner.runScenario(session)(s)) | ||
Claim(t.isSuccess) | ||
} | ||
|
||
property("JsonStepBuilder is Circe jsonObject with absent placeholder") = | ||
forAll { jsonOb: JsonObject ⇒ | ||
val fullJsonObj = jsonOb.add("myKeyOther", Json.fromString("myOtherValue")) | ||
val session = Session.newEmpty.addValuesUnsafe(testKey -> Json.fromJsonObject(fullJsonObj).spaces2) | ||
val fullPlaceholderJsonObj = jsonOb.add("myKeyOther", Json.fromString("<a-placeholder>")) | ||
val step = jsonStepBuilder.is(Json.fromJsonObject(fullPlaceholderJsonObj)) | ||
val s = Scenario("scenario with JsonSteps", step :: Nil) | ||
val t = awaitFuture(ScenarioRunner.runScenario(session)(s)) | ||
Claim(!t.isSuccess) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters