Skip to content

Commit 05ff12c

Browse files
authored
Merge pull request #1995 from hackforla/correct-db-casing
Correct db casing
2 parents 0841c55 + 71b0efd commit 05ff12c

File tree

11 files changed

+600
-7
lines changed

11 files changed

+600
-7
lines changed

backend/models/user.model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const userSchema = mongoose.Schema({
88
firstName: { type: String },
99
lastName: { type: String },
1010
},
11-
email: { type: String, unique: true },
11+
email: { type: String, unique: true, lowercase: true },
1212
accessLevel: {
1313
type: String,
1414
enum: ["user", "admin", "superadmin"], // restricts values to "user", "admin" and "superadmin"

backend/models/user.model.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ describe('Unit tests for User Model', () => {
9696
expect(error.errors.accessLevel).toBeDefined();
9797
});
9898

99+
it('should enforce that emails are stored in lowercase', async () => {
100+
// Create a mock user with an uppercase email
101+
const uppercaseEmail = 'TEST@test.com';
102+
const mockUser = new User({
103+
email: uppercaseEmail,
104+
});
105+
106+
mockUser.validate();
107+
// Tests
108+
expect(mockUser.email).toBe(uppercaseEmail.toLowerCase());
109+
});
110+
111+
99112
it('should pass validation with valid user data', async () => {
100113
// Create a mock user with valid data
101114
const mockUser = new User({
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Created by venv; see https://docs.python.org/3/library/venv.html
2+
*

0 commit comments

Comments
 (0)