38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { JoinedAt } from './JoinedAt';
|
|
|
|
describe('JoinedAt', () => {
|
|
it('should create a joined date', () => {
|
|
const past = new Date('2020-01-01');
|
|
const joined = JoinedAt.create(past);
|
|
expect(joined.toDate()).toEqual(past);
|
|
});
|
|
|
|
it('should throw on future date', () => {
|
|
const future = new Date();
|
|
future.setFullYear(future.getFullYear() + 1);
|
|
expect(() => JoinedAt.create(future)).toThrow('Joined date cannot be in the future');
|
|
});
|
|
|
|
it('should allow current date', () => {
|
|
const now = new Date();
|
|
const joined = JoinedAt.create(now);
|
|
expect(joined.toDate().getTime()).toBeCloseTo(now.getTime(), -3); // close enough
|
|
});
|
|
|
|
it('should equal same date', () => {
|
|
const d1 = new Date('2020-01-01');
|
|
const d2 = new Date('2020-01-01');
|
|
const j1 = JoinedAt.create(d1);
|
|
const j2 = JoinedAt.create(d2);
|
|
expect(j1.equals(j2)).toBe(true);
|
|
});
|
|
|
|
it('should not equal different date', () => {
|
|
const d1 = new Date('2020-01-01');
|
|
const d2 = new Date('2020-01-02');
|
|
const j1 = JoinedAt.create(d1);
|
|
const j2 = JoinedAt.create(d2);
|
|
expect(j1.equals(j2)).toBe(false);
|
|
});
|
|
}); |