# Describing changeset validations

A particular test's expected results can be described with `changeset` (lines 4-5):

```elixir
    category(                           :success,
      ok: [
        params(      age: 1, date:   "2001-01-01"),
        changeset(
          changes: %{age: 1, date: ~D[2001-01-01]}
        )]
    ) |> 

```

That constructs (in effect) this assertion pipeline:

```elixir
Schema.changeset(%Schema{}, Tester.params(:ok))
|> assert_valid
|> assert_changes(age: 1,
                  date: ~D[2001-01-01])
```

Notice that the `assert_valid` wasn't made explicit. It's implied by the name of the category: `:success`(line 1). (Similarly, the`:validation_failure`category implies `assert_invalid`.)

The `changeset` function supports all of the [changeset assertions from ecto\_flow\_assertions](https://hexdocs.pm/ecto_flow_assertions/FlowAssertions.Ecto.ChangesetA.html#summary). Just leave off the `assert_` prefix and the `changeset` argument. For example:

```elixir
    category(                 :validation_failure,
      bad_date: [
        params(    age: 1, date: "2001-1-1"),
        changeset(
          changes: %{age: 1},
          no_changes: [:date],
          errors: [date: ~r/invalid/]
        )]
      )

```

Because this code reuses `ecto_flow_assertions`and `ecto_flow_assertions` reuses `ExUnit`'s reporting machinery, you get good error messages:

![colorization! and more!](https://902287157-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHC8R84w1IeNZSD7hAh%2F-MKVTvdXuuJFVEOAC4IK%2F-MKVZjM_ioubwGMXZquQ%2FScreen%20Shot%202020-10-25%20at%2011.23.33%20AM.png?alt=media\&token=235b2120-071d-41e8-a0cc-3ec88955b64e)

That's important because test generation frameworks are notorious for creating errors that are hard to understand.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://marick.gitbook.io/idiosyncratic-elixir/declarative-testing-of-structured-form-input/consistent-parameter-handling/creating-and-validating-a-changeset.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
