Skip to content

Commit 7da058e

Browse files
authored
test: add unit tests for Notification model (JhaSourav07#3549)
## Description This PR implements unit tests for the Notification mongoose schema, verifying compile validity, path definitions, required and unique properties, enum values, default booleans, and timestamp declarations. Fixes JhaSourav07#3458 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A (Utility/Unit Tests only) ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally. - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors. - [x] My commits follow the Conventional Commits format. - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard. - [ ] (Recommended) I joined the CommitPulse Discord community.
2 parents a756184 + 8072f67 commit 7da058e

1 file changed

Lines changed: 83 additions & 0 deletions

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+
});

0 commit comments

Comments
 (0)