Skip to content

Commit fbfa307

Browse files
test(models): verify createdAt default is callable and returns timestamp
1 parent 82ce406 commit fbfa307

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

models/User.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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>;

0 commit comments

Comments
 (0)