N06
Error
Requests
N06 — A fake that does not match its group's contract
A fake OneUser for Backend.users { … } answers in place of the network, so it is held to what the network would have to do: every endpoint it answers is one the group has, every name it binds is one of that endpoint's parameters, and every answer is the result the endpoint declares — .ok(value) of its type, or .err(error) of its error. A test's fakes: names fakes, and expect called an endpoint.
What the compiler said
error[N06]: `Backend.users` has no endpoint `lists` for `fake OneUser` to answer --> src/App.wf:10:5 | 10 | lists(page) { | ^^^^^ = help: Did you mean `list`? It has `list` = docs: https://webfluent.monzeromer.dev/errors/N06
Your editor offers this fix: Change to list. wf fix --code N06 applies it to every place it fits.
The fix
Broken
type User { id: String, name: String }
api Backend(base: "/api") { }
api Backend.users {
get list(page: Number = 1) at "users" -> [User]!
}
fake OneUser for Backend.users {
lists(page) {
.ok([User(id: "1", name: "Ada")])
}
}
page P(path: "/", title: "T", description: "D") {
resource users = Backend.users.list()
Heading("Users").h1
match users {
.loaded(list) { Text("{list.length} users") }
else { Spinner }
}
}
Fixed
type User { id: String, name: String }
api Backend(base: "/api") { }
api Backend.users {
get list(page: Number = 1) at "users" -> [User]!
}
fake OneUser for Backend.users {
list(page) {
.ok([User(id: "1", name: "Ada")])
}
}
page P(path: "/", title: "T", description: "D") {
resource users = Backend.users.list()
Heading("Users").h1
match users {
.loaded(list) { Text("{list.length} users") }
else { Spinner }
}
}
Answer the endpoints the group declares, by their names and parameters, with the result each declares.
Each example is a whole program: it is all of src/App.wf in a project with no other .wf file (trying an example).
Why this rule exists
Error.
A fake answers a group's endpoints in place of the network, for a test
that names it in fakes: or for wf verify --fakes. It is held to what
the network would have to do: every endpoint it answers is one the group
has, every name it binds is one of that endpoint's parameters, and every
answer is the result the endpoint declares — .ok(value) of its type, or
.err(error) of its error. A fake that answered something else would let
a test pass against a server that cannot exist.
A test is held to its fakes too: each name in fakes: is a fake the
project or the test's file declares, no two of them answer one endpoint,
and expect called names an endpoint an api declares.
lints cannot lower it: it would ship a broken page.