Skip to content

Commit 6d88463

Browse files
authored
Revert "Fix/username validator"
1 parent 3a197a2 commit 6d88463

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

middlewares/validators/user.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ const updateUser = async (req, res, next) => {
1616
username: joi
1717
.string()
1818
.optional()
19-
.regex(/^[a-z]+-[a-z]+(-[1-9])?$/)
20-
.message("Username must be lowercase only hypen, numbers are allowed."),
19+
.min(4)
20+
.max(20)
21+
.regex(/^[a-zA-Z0-9]+$/)
22+
.message("Username must be between 4 and 20 characters long and contain only letters or numbers."),
2123
first_name: joi.string().optional(),
2224
last_name: joi.string().optional(),
2325
yoe: joi.number().min(0).optional(),

test/integration/users.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe("Users", function () {
106106
.patch("/users/self")
107107
.set("cookie", `${cookieName}=${jwt}`)
108108
.send({
109-
username: "valid-username-1",
109+
username: "validUsername123",
110110
})
111111
.end((err, res) => {
112112
if (err) {
@@ -218,7 +218,7 @@ describe("Users", function () {
218218
.patch("/users/self")
219219
.set("cookie", `${cookieName}=${jwt}`)
220220
.send({
221-
username: "InvalidUser-name",
221+
username: "@invalidUser-name",
222222
})
223223
.end((err, res) => {
224224
if (err) {
@@ -230,7 +230,7 @@ describe("Users", function () {
230230
expect(res.body).to.eql({
231231
statusCode: 400,
232232
error: "Bad Request",
233-
message: "Username must be lowercase only hypen, numbers are allowed.",
233+
message: "Username must be between 4 and 20 characters long and contain only letters or numbers.",
234234
});
235235

236236
return done();

test/unit/middlewares/user-validator.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe("Middleware | Validators | User", function () {
113113
body: {
114114
last_name: "patil",
115115
first_name: "Abhay",
116-
username: "Invalidusername-12",
116+
username: "@invalidusername-12",
117117
twitter_id: "abhayisawesome",
118118
},
119119
};

0 commit comments

Comments
 (0)