1+ import mongoose from 'mongoose' ;
12import { describe , it , expect } from 'vitest' ;
23import { 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