UNPKG

ddd-tool-kit

Version:

A development tool kit for using Domain Driven Design in your Web API Node.js

59 lines (58 loc) 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const date_errors_1 = require("./date.errors"); const date_value_object_1 = require("./date.value-object"); describe('date.value-object.spec', () => { it('should be defined a new date', () => { const valueObject = date_value_object_1.DateValueObject.getDefault(); expect(valueObject.value).toBeInstanceOf(Date); }); it('should be fail to init some date', () => { const initDate = date_value_object_1.DateValueObject.init({ value: { isDate: false }, }); expect(initDate.isFailure).toBeTruthy(); expect(initDate.result).toEqual(date_errors_1.INVALID_DATE); }); it('should be sanitize numbers to date', () => { const initDate = date_value_object_1.DateValueObject.init({ value: 4984092, }); expect(initDate.isSuccess).toBeTruthy(); expect(initDate.result).toBeInstanceOf(date_value_object_1.DateValueObject); }); it('should verify is same day true', () => { const date1 = date_value_object_1.DateValueObject.getDefault(); const date2 = date_value_object_1.DateValueObject.getDefault(); expect(date1.isSameDay(date2)).toBeTruthy(); expect(date1.isSameDay(date1)).toBeTruthy(); }); it('should verify is same day true', () => { const today = new Date(); const tomorrowDayNumber = today.getDate() + 1; const tomorrow = new Date(); tomorrow.setDate(tomorrowDayNumber); const dateToday = date_value_object_1.DateValueObject.init({ value: today, }).result; const dateTomorrow = date_value_object_1.DateValueObject.init({ value: tomorrow, }).result; const isSameDay = dateToday.isSameDay(dateTomorrow); expect(isSameDay).toBeFalsy(); }); it('should be add one days for today', () => { const today = date_value_object_1.DateValueObject.getDefault(); const tomorrow = date_value_object_1.DateValueObject.getDefault(); expect(today.isSameDay(tomorrow)).toBeTruthy(); tomorrow.addDays(1); expect(today.isSameDay(tomorrow)).toBeFalsy(); }); it('should be difference in days is 1', () => { const differenceInDays = 1; const today = date_value_object_1.DateValueObject.getDefault(); const tomorrow = date_value_object_1.DateValueObject.getDefault(); tomorrow.addDays(differenceInDays); expect(tomorrow.differenceInDays(today)).toBe(differenceInDays); }); });