Skip to content

Commit 8072f67

Browse files
committed
test: add unit tests for Notification model
1 parent 41222eb commit 8072f67

2 files changed

Lines changed: 91 additions & 1 deletion

File tree

models/Notification.test.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import mongoose from 'mongoose';
2+
import { describe, it, expect } from 'vitest';
3+
import { Notification } from './Notification';
4+
5+
describe('Notification Model', () => {
6+
it('is compiled properly and exposed', () => {
7+
expect(Notification).toBeDefined();
8+
expect(Notification.modelName).toBe('Notification');
9+
});
10+
11+
it('enforces required, unique, and lowercase fields on username', () => {
12+
const usernamePath = Notification.schema.path('username') as mongoose.SchemaType & {
13+
options: Record<string, unknown>;
14+
};
15+
16+
expect(usernamePath).toBeDefined();
17+
expect(usernamePath.options.required).toBe(true);
18+
expect(usernamePath.options.unique).toBe(true);
19+
expect(usernamePath.options.lowercase).toBe(true);
20+
expect(usernamePath.options.trim).toBe(true);
21+
});
22+
23+
it('enforces required, lowercase, and trim fields on email', () => {
24+
const emailPath = Notification.schema.path('email') as mongoose.SchemaType & {
25+
options: Record<string, unknown>;
26+
};
27+
28+
expect(emailPath).toBeDefined();
29+
expect(emailPath.options.required).toBe(true);
30+
expect(emailPath.options.lowercase).toBe(true);
31+
expect(emailPath.options.trim).toBe(true);
32+
});
33+
34+
it('validates frequency field and its defaults and enums', () => {
35+
const frequencyPath = Notification.schema.path('frequency') as mongoose.SchemaType & {
36+
options: Record<string, unknown>;
37+
enumValues: string[];
38+
};
39+
40+
expect(frequencyPath).toBeDefined();
41+
expect(frequencyPath.options.default).toBe('daily');
42+
expect(frequencyPath.enumValues).toContain('realtime');
43+
expect(frequencyPath.enumValues).toContain('daily');
44+
expect(frequencyPath.enumValues).toContain('weekly');
45+
});
46+
47+
it('checks boolean notification switches have default value as true', () => {
48+
const notifyOnCommitPath = Notification.schema.path('notifyOnCommit') as mongoose.SchemaType & {
49+
options: Record<string, unknown>;
50+
};
51+
const notifyOnStreakPath = Notification.schema.path('notifyOnStreak') as mongoose.SchemaType & {
52+
options: Record<string, unknown>;
53+
};
54+
const notifyOnMilestonePath = Notification.schema.path(
55+
'notifyOnMilestone'
56+
) as mongoose.SchemaType & {
57+
options: Record<string, unknown>;
58+
};
59+
60+
expect(notifyOnCommitPath.options.default).toBe(true);
61+
expect(notifyOnStreakPath.options.default).toBe(true);
62+
expect(notifyOnMilestonePath.options.default).toBe(true);
63+
});
64+
65+
it('checks isActive default value is true', () => {
66+
const isActivePath = Notification.schema.path('isActive') as mongoose.SchemaType & {
67+
options: Record<string, unknown>;
68+
};
69+
expect(isActivePath.options.default).toBe(true);
70+
});
71+
72+
it('checks createdAt and updatedAt have default values', () => {
73+
const createdAtPath = Notification.schema.path('createdAt') as mongoose.SchemaType & {
74+
options: Record<string, unknown>;
75+
};
76+
const updatedAtPath = Notification.schema.path('updatedAt') as mongoose.SchemaType & {
77+
options: Record<string, unknown>;
78+
};
79+
80+
expect(createdAtPath.options.default).toBeDefined();
81+
expect(updatedAtPath.options.default).toBeDefined();
82+
});
83+
});

vercel.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
{
2-
"ignoreCommand": "bash vercel-ignore.sh"
2+
"ignoreCommand": "bash vercel-ignore.sh",
3+
"git": {
4+
"deploymentEnabled": {
5+
"main": true,
6+
"fix/issue-*": false,
7+
"test/*": false
8+
}
9+
}
310
}

0 commit comments

Comments
 (0)