cosmos-db-repositories
Version:
cosmos-db repositories
68 lines (67 loc) • 2.66 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const time_range_1 = __importDefault(require("./time-range"));
const time_utils_1 = __importDefault(require("./time.utils"));
const luxon_1 = require("luxon");
describe('Time Range', () => {
const sut = time_range_1.default;
it('today', () => {
const time = 'today';
const answer = sut.parse(time);
expect(answer).toBeDefined();
expect(answer.length).toEqual(2);
const [from, to] = answer;
expect(from).toBeDefined();
expect(time_utils_1.default.isDateTimeFormat(from)).toEqual(true);
expect(luxon_1.DateTime.fromISO(from)).toBeDefined();
expect(to).toBeDefined();
expect(luxon_1.DateTime.fromISO(to)).toBeDefined();
});
it('all', () => {
const timeRanges = [
'yesterday', 'today', 'tomorrow',
'last week', 'this week', 'next week',
'last month', 'this month', 'next month',
'last quarter', 'this quarter', 'next quarter',
'1 quarter', '2 quarter', '3 quarter', '4 quarter'
];
timeRanges.forEach(it => {
const answer = sut.parse(it);
expect(answer).toBeDefined();
expect(answer === null || answer === void 0 ? void 0 : answer.length).toEqual(2);
console.log(it, ' -> ', answer);
});
});
it('today with custom zone', () => {
const time = 'today';
const zone = 'Europe/Berlin';
const answer = sut.parse(time, zone);
expect(answer).toEqual(sut.parse(time));
});
it('custom', () => {
const time = '2025-01-02,2025-03-02';
const answer = sut.parse(time);
expect(answer).toBeDefined();
expect(answer.length).toEqual(2);
const [from, to] = answer;
expect(from).toBeDefined();
expect(from).toEqual('2025-01-01T23:00:00.000Z');
expect(to).toBeDefined();
expect(to).toEqual('2025-03-01T23:00:00.000Z');
});
it('custom with custom zone', () => {
const time = '2025-01-02, 2025-03-02';
const zone = 'Europe/Berlin';
const answer = sut.parse(time, zone);
expect(answer).toBeDefined();
expect(answer.length).toEqual(2);
const [from, to] = answer;
expect(from).toBeDefined();
expect(from).toEqual('2025-01-01T23:00:00.000Z');
expect(to).toBeDefined();
expect(to).toEqual('2025-03-01T23:00:00.000Z');
});
});