Skip to content

Commit 0315e85

Browse files
authored
test(user): verify username schema constraints (JhaSourav07#946)
* test(user): verify username schema constraints * chore: remove pnpm lock and workspace files
1 parent a7ee991 commit 0315e85

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

models/User.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import mongoose from 'mongoose';
12
import { describe, it, expect } from 'vitest';
23
import { User } from './User';
34

@@ -6,4 +7,34 @@ describe('User Model', () => {
67
expect(User).toBeDefined();
78
expect(User.modelName).toBe('User');
89
});
10+
11+
describe('username schema constraints', () => {
12+
it('has lowercase: true on username path', () => {
13+
const usernamePath = User.schema.path('username') as mongoose.SchemaType & {
14+
options: Record<string, unknown>;
15+
};
16+
expect(usernamePath.options.lowercase).toBe(true);
17+
});
18+
19+
it('has trim: true on username path', () => {
20+
const usernamePath = User.schema.path('username') as mongoose.SchemaType & {
21+
options: Record<string, unknown>;
22+
};
23+
expect(usernamePath.options.trim).toBe(true);
24+
});
25+
26+
it('has unique: true on username path', () => {
27+
const usernamePath = User.schema.path('username') as mongoose.SchemaType & {
28+
options: Record<string, unknown>;
29+
};
30+
expect(usernamePath.options.unique).toBe(true);
31+
});
32+
33+
it('has required: true on username path', () => {
34+
const usernamePath = User.schema.path('username') as mongoose.SchemaType & {
35+
options: Record<string, unknown>;
36+
};
37+
expect(usernamePath.options.required).toBe(true);
38+
});
39+
});
940
});

0 commit comments

Comments
 (0)