File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,6 +16,21 @@ describe('User Model', () => {
1616 expect ( usernamePath . options . lowercase ) . toBe ( true ) ;
1717 } ) ;
1818
19+ describe ( 'createdAt schema' , ( ) => {
20+ it ( 'uses a callable default that returns a timestamp' , ( ) => {
21+ const createdAtPath = User . schema . path ( 'createdAt' ) as mongoose . SchemaType & {
22+ options : { default ?: unknown } ;
23+ } ;
24+
25+ // Assertion 1: the default is a function
26+ expect ( typeof createdAtPath . options . default ) . toBe ( 'function' ) ;
27+
28+ // Assertion 2: calling the default returns a numeric timestamp
29+ const result = ( createdAtPath . options . default as ( ) => number ) ( ) ;
30+ expect ( typeof result ) . toBe ( 'number' ) ;
31+ expect ( Number . isFinite ( result ) ) . toBe ( true ) ;
32+ } ) ;
33+ } ) ;
1934 it ( 'has trim: true on username path' , ( ) => {
2035 const usernamePath = User . schema . path ( 'username' ) as mongoose . SchemaType & {
2136 options : Record < string , unknown > ;
You can’t perform that action at this time.
0 commit comments