Make testing more accessible (database layer)
Testing with Adonis is amazingly simple, however, the docs are not really explaining much about its capabilities. The only reason I know of them is because I have experience working with Laravel and watched Laracasts. But testing Adonis shouldn't require prior knowledge in a framework from a different language that is only really taught in a course behind a paywall.
Only because of my prior knowledge I was searching everywhere in the docs and code for things like using migrations within the tests (eventually found it in vowfile.js commented out) or the databaseTransactions trait (eventually found under "Fakes" in the documentation?).
I know that not every project requires lucid, but I still believe that the docs could be improved by shuffling around some of the sections and also by making use of "Recipes".
Idea
Introduce a new section under "Testing" called "Database"
This section should explain the following topics
- The fact that you don't have to mock out the database layer
- The usage of a sqlite database for tests, even though you actually use something else
- How to make use of migrations for testing (vowfile.js)
- Move "DatabaseTransactions" trait section from "Fakes" to here
- Link to "Factories" section and quickly describe how they can simplify your tests
- Link to new recipe that describes a simple example that gives people creative ideas for their own test scenarios.
Example of recipe (only including test file for now):
// ...
trait('DatabaseTransactions')
test('updates user name', async ({ assert, client }) => {
const user = await Factory.model('App/Models/User').create()
const response = await client.put('/user/name').send({ name: 'new name' }).end()
await user.reload()
assert.equal(user.name, 'new name')
})