Skip to content

Commit

Permalink
Added tests for parseScheduleDates.
Browse files Browse the repository at this point in the history
  • Loading branch information
yctercero committed Jan 29, 2020
1 parent 6171df3 commit 9c5f3a2
Showing 1 changed file with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
*/

import moment from 'moment';
import dateMath from '@elastic/datemath';

import { generateId, parseInterval, getDriftTolerance, getGapBetweenRuns } from './utils';
import {
generateId,
parseInterval,
parseScheduleDates,
getDriftTolerance,
getGapBetweenRuns,
} from './utils';

describe('utils', () => {
let nowDate = moment('2020-01-01T00:00:00.000Z');
Expand All @@ -27,7 +34,7 @@ describe('utils', () => {
});
});

describe('getIntervalMilliseconds', () => {
describe('parseInterval', () => {
test('it returns a duration when given one that is valid', () => {
const duration = parseInterval('5m');
expect(duration).not.toBeNull();
Expand All @@ -40,6 +47,34 @@ describe('utils', () => {
});
});

describe('parseScheduleDates', () => {
test('it returns a moment when given an ISO string', () => {
const result = parseScheduleDates('2020-01-01T00:00:00.000Z');
expect(result).not.toBeNull();
expect(result).toEqual(moment('2020-01-01T00:00:00.000Z'));
});

test('it returns a moment when given `now`', () => {
const result = parseScheduleDates('now');

expect(result).not.toBeNull();
expect(moment.isMoment(result)).toBeTruthy();
});

test('it returns a moment when given `now-x`', () => {
const result = parseScheduleDates('now-6m');

expect(result).not.toBeNull();
expect(moment.isMoment(result)).toBeTruthy();
});

test('it returns null when given a string that is not an ISO string, `now` or `now-x`', () => {
const result = parseScheduleDates('invalid');

expect(result).toBeNull();
});
});

describe('getDriftTolerance', () => {
test('it returns a drift tolerance in milliseconds of 1 minute when "from" overlaps "to" by 1 minute and the interval is 5 minutes', () => {
const drift = getDriftTolerance({
Expand Down

0 comments on commit 9c5f3a2

Please sign in to comment.