Skip to content

Commit 3a197a2

Browse files
authored
Merge pull request #1384 from Abhay5855/fix/username-automate-modifications
2 parents 21d306b + f935792 commit 3a197a2

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

middlewares/validators/user.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ const updateUser = async (req, res, next) => {
1616
username: joi
1717
.string()
1818
.optional()
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."),
19+
.regex(/^[a-z]+-[a-z]+(-[1-9])?$/)
20+
.message("Username must be lowercase only hypen, numbers are allowed."),
2321
first_name: joi.string().optional(),
2422
last_name: joi.string().optional(),
2523
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: "validUsername123",
109+
username: "valid-username-1",
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 between 4 and 20 characters long and contain only letters or numbers.",
233+
message: "Username must be lowercase only hypen, numbers are allowed.",
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)