# AZ106: A test or an invariant written wrongly

The `test` section holds checks on the data there: `user 3 can view file 11`, `user 3 cannot edit file 11`. A named test, `test "name"`, brings its own data first, `given ann = {INSERT ... RETURNING id}`, then checks: `user $ann can view folder $top`, `as user $ann refused {UPDATE ...}`, `as user $ann sees 2 {SELECT ...}`. A test needs at least one line, a named test a name (in double quotes, nothing after it on the line), a `given` or an `as` line a statement, and a test file holds only named tests. `sees N` counts the rows of a SELECT, so its statement doesn't write: for a write that must change no row, write `as ... refused {...}`. `anyone` is nobody signed in, so it takes no `with scope`. An id that starts with `$` is a name a `given` line binds: write any other such id in quotes, `'$x'`.

Invariants are `never type: expression`, under `invariants`.

Reported when the tests are compiled: `rowstile test`, the editor, `rowstile dev`.

## The mistake

```authz
app role app_user
type user = app.users
type folder = app.folders
  owner : user = owner_id
  can view = owner
test "owners see their folders"
  user 1 may view folder 1
```

```
line 7: a test's lines are: given name = {INSERT ... RETURNING id}, user $name can view file $f, or as user $name allowed|refused|sees N {SQL} (after who: `with scope read`, to check as a key limited to a scope) [AZ106]
```

## Fixed

```authz
app role app_user
type user = app.users
type folder = app.folders
  owner : user = owner_id
  can view = owner
test "owners see their folders"
  given ann = {INSERT INTO app.users (name) VALUES ('Ann') RETURNING id}
  given top = {INSERT INTO app.folders (owner_id, name) VALUES ($ann, 'Top') RETURNING id}
  user $ann can view folder $top
```
