grillon icon indicating copy to clipboard operation
grillon copied to clipboard

Json context assertions

Open theredfish opened this issue 2 years ago • 0 comments

For the moment we have a couple of assertions with the Value type that represents a json value.

As we are separating the assertion logic from the DSL, it makes sense to identify the different types of json Value, that we can call json contexts:

  • json body
  • json path
  • pure json value

For example the Equality trait can be implemented for Values coming from those different contexts. For debug/logging purposes it is essential to know the Part under test, arising from the context.

The corresponding parts should be:

/// A json value
#[strum(serialize = "json value")]
#[serde(rename = "json value")]
JsonValue,
/// The json body of an http response.
#[strum(serialize = "json body")]
#[serde(rename = "json body")]
JsonBody,
/// The json value of an http response at the given path.
#[strum(serialize = "json path")]
#[serde(rename = "json path")]
JsonPath,

The lib API should stay simple and cover these different examples:

  • json!(1).eq(&json!(1)): the resulting assertion's part should be a JsonValue
  • JsonBody(json!(1)).eq(&json!(1)): the resulting assertion's part should be a JsonBody
  • JsonPath(json!(1)).eq(&json!(1)): the resulting assertion's part should be a JsonPath

This way we can easily wrap the json value into its context, or just fallback to a default JsonValue when we want to assert some json data.

theredfish avatar Sep 05 '23 12:09 theredfish