Skip to content

Commit

Permalink
Añadido test de fallo por validación de contraseña
Browse files Browse the repository at this point in the history
  • Loading branch information
iyanfdezz committed Apr 18, 2024
1 parent a2fce22 commit c3d1830
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ app.post("/adduser", async (req, res) => {
validateRequiredFields(req, ["username", "password"]);

const username = req.body.username;

const password= req.body.password;

const passwordRegex = /^(?=.*[A-Z])(?=.*\d).{8,}$/;
if (!passwordRegex.test(password)) {
return res.status(401).json({
Expand Down
15 changes: 15 additions & 0 deletions users/userservice/user-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let app;
const username = "testuser";
const friendUsername = "testfriend";
const password = "Testpassword1";
const badPassword = "pass";

beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
Expand Down Expand Up @@ -45,6 +46,20 @@ describe("User Service", () => {
});
});


it("should send password validation error on POST /adduser", async () => {
const newUser = {
username: "testuser",
password: badPassword,
};

const response = await request(app).post("/adduser").send(newUser);
expect(response.status).toBe(401);
expect(response.body).toEqual({
error: "Password must be at least 8 characters long, contain at least one uppercase letter, and at least one number.",
});
});

it("should add a new user on POST /adduser", async () => {
const newUser = {
username: "testuser",
Expand Down

0 comments on commit c3d1830

Please sign in to comment.