|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { Notification } from './Notification'; |
| 3 | + |
| 4 | +describe('Notification massive scaling behavior', () => { |
| 5 | + it('creates 1000 notification documents without throwing', () => { |
| 6 | + expect(() => { |
| 7 | + Array.from({ length: 1000 }, (_, i) => { |
| 8 | + return new Notification({ |
| 9 | + username: `user${i}`, |
| 10 | + email: `user${i}@example.com`, |
| 11 | + }); |
| 12 | + }); |
| 13 | + }).not.toThrow(); |
| 14 | + }); |
| 15 | + |
| 16 | + it('keeps default notification flags stable across many documents', () => { |
| 17 | + const notifications = Array.from({ length: 500 }, (_, i) => { |
| 18 | + return new Notification({ |
| 19 | + username: `user${i}`, |
| 20 | + email: `user${i}@example.com`, |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + expect(notifications.every((n) => n.notifyOnCommit === true)).toBe(true); |
| 25 | + expect(notifications.every((n) => n.notifyOnStreak === true)).toBe(true); |
| 26 | + expect(notifications.every((n) => n.notifyOnMilestone === true)).toBe(true); |
| 27 | + expect(notifications.every((n) => n.isActive === true)).toBe(true); |
| 28 | + }); |
| 29 | + |
| 30 | + it('normalizes usernames and emails consistently under high volume', () => { |
| 31 | + const notifications = Array.from({ length: 300 }, (_, i) => { |
| 32 | + return new Notification({ |
| 33 | + username: ` USER${i} `, |
| 34 | + email: ` USER${i}@EXAMPLE.COM `, |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + expect(notifications[0].username).toBe('user0'); |
| 39 | + expect(notifications[0].email).toBe('user0@example.com'); |
| 40 | + expect(notifications[299].username).toBe('user299'); |
| 41 | + expect(notifications[299].email).toBe('user299@example.com'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('supports all allowed frequency values across many documents', () => { |
| 45 | + const frequencies = ['realtime', 'daily', 'weekly'] as const; |
| 46 | + |
| 47 | + const notifications = Array.from({ length: 300 }, (_, i) => { |
| 48 | + return new Notification({ |
| 49 | + username: `user${i}`, |
| 50 | + email: `user${i}@example.com`, |
| 51 | + frequency: frequencies[i % frequencies.length], |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + expect(notifications.filter((n) => n.frequency === 'realtime')).toHaveLength(100); |
| 56 | + expect(notifications.filter((n) => n.frequency === 'daily')).toHaveLength(100); |
| 57 | + expect(notifications.filter((n) => n.frequency === 'weekly')).toHaveLength(100); |
| 58 | + }); |
| 59 | + |
| 60 | + it('preserves date defaults across bulk-created documents', () => { |
| 61 | + const notifications = Array.from({ length: 200 }, (_, i) => { |
| 62 | + return new Notification({ |
| 63 | + username: `user${i}`, |
| 64 | + email: `user${i}@example.com`, |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + expect(notifications.every((n) => n.createdAt instanceof Date)).toBe(true); |
| 69 | + expect(notifications.every((n) => n.updatedAt instanceof Date)).toBe(true); |
| 70 | + }); |
| 71 | +}); |
0 commit comments