@itsmworkbench/utils
Version:
The usual utility functions
36 lines (35 loc) • 1.86 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const timeservice_1 = require("./timeservice");
describe('calculateSinceDate', () => {
const fixedTime = new Date('2024-05-25T12:00:00Z').getTime();
const timeService = () => fixedTime;
it('should correctly calculate the date for "-1d"', () => {
const result = (0, timeservice_1.calculateSinceDate)(timeService)('1d');
expect(result.toISOString()).toBe('2024-05-24T12:00:00.000Z');
});
it('should correctly calculate the date for "-10d"', () => {
const result = (0, timeservice_1.calculateSinceDate)(timeService)('1d');
expect(result.toISOString()).toBe('2024-05-24T12:00:00.000Z');
});
it('should correctly calculate the date for "-100d"', () => {
const result = (0, timeservice_1.calculateSinceDate)(timeService)('1d');
expect(result.toISOString()).toBe('2024-05-24T12:00:00.000Z');
});
it('should not die when used with real time service', () => {
const result = (0, timeservice_1.calculateSinceDate)(timeservice_1.DateTimeService)('1d');
const string = result.toISOString();
expect(string.indexOf('NaN')).toBe(-1);
});
it('should correctly calculate the date for "-5h"', () => {
const result = (0, timeservice_1.calculateSinceDate)(timeService)('5h');
expect(result.toISOString()).toBe('2024-05-25T07:00:00.000Z');
});
it('should correctly calculate the date for "-30m"', () => {
const result = (0, timeservice_1.calculateSinceDate)(timeService)('30m');
expect(result.toISOString()).toBe('2024-05-25T11:30:00.000Z');
});
it('should throw an error for unsupported time unit', () => {
expect(() => (0, timeservice_1.calculateSinceDate)(timeService)('1w')).toThrow('Unsupported time unit: w');
});
});
;