You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing test scenarios for my Adonis JS API application and some requests need special privileges to be done. Such like : Create, update and delete.
Prior the scenario i'm having an issue with, I made an authentication scenario which actually register a user in the database.
However, when I try to use this user in my CRUD scenario (which runs AFTER the authentication one), the following error is returned when I use User.findOrFail: E_ROW_NOT_FOUND.
I was wondering if it has something to do with asynchronous tasks. But according to which order the tests are executed, it is not supposed to fail.
Here is my code :
const baseUrl = '/api/blog/categories';
let user;
test.group('Blog post categories', async () => {
user = await User.findOrFail(1); // Please note that I have already tried other ways to get the user instead of just its id.
user.idRole = (await Role.findByOrFail('code', 'ADMIN')).id;
await user.save();
test('Ajouter une catégorie (POST ' + baseUrl + ')', async ({ client }) => {
const category = await client.post(baseUrl).loginAs(user).field('label', 'Catégorie de test 1');
category.assertStatus(201);
category.assertBody({
label: category.body().label,
slug: category.body().slug,
postList: category.body().postList,
});
});
// [...] (other scenarios have been omitted since the issues remain the same for the other endpoints that needs special privileges)
});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello there 👋
I'm writing test scenarios for my Adonis JS API application and some requests need special privileges to be done. Such like : Create, update and delete.
Prior the scenario i'm having an issue with, I made an authentication scenario which actually register a user in the database.
However, when I try to use this user in my CRUD scenario (which runs AFTER the authentication one), the following error is returned when I use
User.findOrFail
:E_ROW_NOT_FOUND
.It seems a bit weird to me. As the user is not supposed to be missing in the database. I have followed the documentation on there https://docs.adonisjs.com/guides/testing/http-tests#authentication.
Am I missing something ? What did I do wrong ?
I was wondering if it has something to do with asynchronous tasks. But according to which order the tests are executed, it is not supposed to fail.
Here is my code :
Beta Was this translation helpful? Give feedback.
All reactions