Closed fzhnf closed 4 months ago
i figured the problem was that i don't implement vinejs normalizeEmail
to faker.internet.email()
, but i don't know how to do that
I finally figured out what's the real problem and was able to solve it myself after 5 days, lol. I'm sorry for my lack of knowledge.
Here is my solution: faker emails will be modified by the validator's normalizeEmail
method inside userFactory.
import User from "#models/user";
import factory from "@adonisjs/lucid/factories";
import validator from "validator";
export const UserFactory = factory
.define(User, async ({ faker }) => {
const email = faker.internet.email();
const normalizedEmail = validator.normalizeEmail(email) || email; // Fallback to original email if normalization fails
return {
username: faker.internet.userName(),
fullName: faker.person.fullName(),
email: normalizedEmail,
password: "12341234",
};
})
.build();
Package version
21.1.0
Describe the bug
SUMMARY
Using a factory-created user leads to both validation,
unique()
andexitst()
, works oppositely. In contrast, using user created manually using controller works just fine as expected, register validator has methodunique()
for email field, and will return false if my argument for email is exist in database. login validator has methodexists()
for email field, and will return false if my argument for email is not exist in database, but both method is not working as it supposed to if the user is created using factory.STEPS TO REPRODUCE
run
node ace migration:refresh --seed
copy password from factory
copy the generated email from db or print the user value from seeder file
use http method to login using created email and password, example using
httpie
from clihttp POST localhost:3333/api/auth/login email=Oda_Zemlak@gmail.com password=12341234
for login, try this firsthttp POST localhost:3333/api/auth/register fullName=fzhnf email=Oda_Zemlak@gmail.com password=12341234 password_confirmation=12341234
for register, try this secondOBSERVED RESULT
login
in result, the user do not get the authentication token event though the email with the same value is exist in the database.
register
in result, the email is inserted into database, making the column has two email with same exact value
EXPECTED RESULT
login
in result, the user is get the authentication token because the email with the same value is exist in the database.
register
in result, the user is not inserted into database because the email with the same value is exist in the database.
Reproduction repo
https://github.com/fzhnf/test-adonis