wip
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { NotificationId } from '../../../../../packages/notifications/domain/value-objects/NotificationId';
|
||||
import { NotificationDomainError } from '../../../../../packages/notifications/domain/errors/NotificationDomainError';
|
||||
|
||||
describe('NotificationId', () => {
|
||||
it('creates a valid NotificationId from a non-empty string', () => {
|
||||
const id = NotificationId.create('noti_123');
|
||||
|
||||
expect(id.value).toBe('noti_123');
|
||||
});
|
||||
|
||||
it('trims whitespace from the raw value', () => {
|
||||
const id = NotificationId.create(' noti_456 ');
|
||||
|
||||
expect(id.value).toBe('noti_456');
|
||||
});
|
||||
|
||||
it('throws NotificationDomainError for empty string', () => {
|
||||
expect(() => NotificationId.create('')).toThrow(NotificationDomainError);
|
||||
expect(() => NotificationId.create(' ')).toThrow(NotificationDomainError);
|
||||
|
||||
try {
|
||||
NotificationId.create(' ');
|
||||
} catch (error) {
|
||||
if (error instanceof NotificationDomainError) {
|
||||
expect(error.kind).toBe('validation');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('compares equality based on underlying value', () => {
|
||||
const a = NotificationId.create('noti_1');
|
||||
const b = NotificationId.create('noti_1');
|
||||
const c = NotificationId.create('noti_2');
|
||||
|
||||
expect(a.equals(b)).toBe(true);
|
||||
expect(a.equals(c)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
import { QuietHours } from '../../../../../packages/notifications/domain/value-objects/QuietHours';
|
||||
|
||||
describe('QuietHours', () => {
|
||||
it('creates a valid normal-range window', () => {
|
||||
const qh = QuietHours.create(9, 17);
|
||||
expect(qh.props.startHour).toBe(9);
|
||||
expect(qh.props.endHour).toBe(17);
|
||||
});
|
||||
|
||||
it('creates a valid overnight window', () => {
|
||||
const qh = QuietHours.create(22, 7);
|
||||
expect(qh.props.startHour).toBe(22);
|
||||
expect(qh.props.endHour).toBe(7);
|
||||
});
|
||||
|
||||
it('throws when hours are out of range', () => {
|
||||
expect(() => QuietHours.create(-1, 10)).toThrow();
|
||||
expect(() => QuietHours.create(0, 24)).toThrow();
|
||||
});
|
||||
|
||||
it('throws when start and end are equal', () => {
|
||||
expect(() => QuietHours.create(10, 10)).toThrow();
|
||||
});
|
||||
|
||||
it('detects containment for normal range', () => {
|
||||
const qh = QuietHours.create(9, 17);
|
||||
expect(qh.containsHour(8)).toBe(false);
|
||||
expect(qh.containsHour(9)).toBe(true);
|
||||
expect(qh.containsHour(12)).toBe(true);
|
||||
expect(qh.containsHour(17)).toBe(false);
|
||||
});
|
||||
|
||||
it('detects containment for overnight range', () => {
|
||||
const qh = QuietHours.create(22, 7);
|
||||
expect(qh.containsHour(21)).toBe(false);
|
||||
expect(qh.containsHour(22)).toBe(true);
|
||||
expect(qh.containsHour(23)).toBe(true);
|
||||
expect(qh.containsHour(0)).toBe(true);
|
||||
expect(qh.containsHour(6)).toBe(true);
|
||||
expect(qh.containsHour(7)).toBe(false);
|
||||
});
|
||||
|
||||
it('implements value-based equality', () => {
|
||||
const a = QuietHours.create(22, 7);
|
||||
const b = QuietHours.create(22, 7);
|
||||
const c = QuietHours.create(9, 17);
|
||||
|
||||
expect(a.equals(b)).toBe(true);
|
||||
expect(a.equals(c)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user