refactor
This commit is contained in:
43
core/racing/domain/entities/AppliedAt.test.ts
Normal file
43
core/racing/domain/entities/AppliedAt.test.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { AppliedAt } from './AppliedAt';
|
||||
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
||||
|
||||
describe('AppliedAt', () => {
|
||||
describe('create', () => {
|
||||
it('should create an AppliedAt with valid date', () => {
|
||||
const date = new Date('2023-01-01T00:00:00Z');
|
||||
const appliedAt = AppliedAt.create(date);
|
||||
expect(appliedAt.toDate().getTime()).toBe(date.getTime());
|
||||
});
|
||||
|
||||
it('should create a copy of the date', () => {
|
||||
const date = new Date();
|
||||
const appliedAt = AppliedAt.create(date);
|
||||
date.setFullYear(2000); // modify original
|
||||
expect(appliedAt.toDate().getFullYear()).not.toBe(2000);
|
||||
});
|
||||
|
||||
it('should throw error for invalid date', () => {
|
||||
expect(() => AppliedAt.create(new Date('invalid'))).toThrow(RacingDomainValidationError);
|
||||
});
|
||||
|
||||
it('should throw error for non-Date', () => {
|
||||
expect(() => AppliedAt.create('2023-01-01' as unknown as Date)).toThrow(RacingDomainValidationError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('equals', () => {
|
||||
it('should return true for equal dates', () => {
|
||||
const date1 = new Date('2023-01-01T00:00:00Z');
|
||||
const date2 = new Date('2023-01-01T00:00:00Z');
|
||||
const appliedAt1 = AppliedAt.create(date1);
|
||||
const appliedAt2 = AppliedAt.create(date2);
|
||||
expect(appliedAt1.equals(appliedAt2)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for different dates', () => {
|
||||
const appliedAt1 = AppliedAt.create(new Date('2023-01-01'));
|
||||
const appliedAt2 = AppliedAt.create(new Date('2023-01-02'));
|
||||
expect(appliedAt1.equals(appliedAt2)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user