chore: Refactor server tests to use jest
This commit is contained in:
committed by
mrugesh mohapatra
parent
4a9d22cee0
commit
438bd94895
@ -1,75 +1,83 @@
|
||||
/* global describe expect it */
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
import { dayCount } from './date-utils';
|
||||
import test from 'tape';
|
||||
|
||||
const PST = 'America/Los_Angeles';
|
||||
|
||||
test('Day count between two epochs (inclusive) calculation', function(t) {
|
||||
t.plan(7);
|
||||
describe('date utils', () => {
|
||||
describe('dayCount', () => {
|
||||
it('should return 1 day given epochs of the same day', () => {
|
||||
expect(
|
||||
dayCount([
|
||||
moment.utc('8/3/2015 3:00', 'M/D/YYYY H:mm').valueOf(),
|
||||
moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf()
|
||||
])
|
||||
).toEqual(1);
|
||||
});
|
||||
|
||||
t.equal(
|
||||
dayCount([
|
||||
moment.utc('8/3/2015 3:00', 'M/D/YYYY H:mm').valueOf(),
|
||||
moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf()
|
||||
]),
|
||||
1,
|
||||
'should return 1 day given epochs of the same day'
|
||||
);
|
||||
it('should return 1 day given same epochs', () => {
|
||||
expect(
|
||||
dayCount([
|
||||
moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf(),
|
||||
moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf()
|
||||
])
|
||||
).toEqual(1);
|
||||
});
|
||||
|
||||
t.equal(
|
||||
dayCount([
|
||||
moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf(),
|
||||
moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf()
|
||||
]),
|
||||
1,
|
||||
'should return 1 day given same epochs'
|
||||
);
|
||||
it('should return 2 days when there is a 24 hours difference', () => {});
|
||||
expect(
|
||||
dayCount([
|
||||
moment.utc('8/4/2015 2:00', 'M/D/YYYY H:mm').valueOf(),
|
||||
moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf()
|
||||
])
|
||||
).toEqual(2);
|
||||
|
||||
t.equal(
|
||||
dayCount([
|
||||
moment.utc('8/4/2015 2:00', 'M/D/YYYY H:mm').valueOf(),
|
||||
moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf()
|
||||
]),
|
||||
2,
|
||||
'should return 2 days when there is a 24 hours difference'
|
||||
);
|
||||
it(
|
||||
'should return 2 days when the diff is less than 24h but ' +
|
||||
'different in UTC',
|
||||
() => {}
|
||||
);
|
||||
expect(
|
||||
dayCount([
|
||||
moment.utc('8/4/2015 1:00', 'M/D/YYYY H:mm').valueOf(),
|
||||
moment.utc('8/3/2015 23:00', 'M/D/YYYY H:mm').valueOf()
|
||||
])
|
||||
).toEqual(2);
|
||||
|
||||
t.equal(
|
||||
dayCount([
|
||||
moment.utc('8/4/2015 1:00', 'M/D/YYYY H:mm').valueOf(),
|
||||
moment.utc('8/3/2015 23:00', 'M/D/YYYY H:mm').valueOf()
|
||||
]),
|
||||
2,
|
||||
'should return 2 days when the diff is less than 24h but different in UTC'
|
||||
);
|
||||
it(
|
||||
'should return 1 day when the diff is less than 24h ' +
|
||||
'and days are different in UTC, but given PST',
|
||||
() => {}
|
||||
);
|
||||
expect(
|
||||
dayCount(
|
||||
[
|
||||
moment.utc('8/4/2015 1:00', 'M/D/YYYY H:mm').valueOf(),
|
||||
moment.utc('8/3/2015 23:00', 'M/D/YYYY H:mm').valueOf()
|
||||
],
|
||||
PST
|
||||
)
|
||||
).toEqual(1);
|
||||
|
||||
t.equal(
|
||||
dayCount([
|
||||
moment.utc('8/4/2015 1:00', 'M/D/YYYY H:mm').valueOf(),
|
||||
moment.utc('8/3/2015 23:00', 'M/D/YYYY H:mm').valueOf()
|
||||
], PST),
|
||||
1,
|
||||
'should return 1 day when the diff is less than 24h ' +
|
||||
'and days are different in UTC, but given PST'
|
||||
);
|
||||
it('should return correct count when there is very big period', () => {});
|
||||
expect(
|
||||
dayCount([
|
||||
moment.utc('10/27/2015 1:00', 'M/D/YYYY H:mm').valueOf(),
|
||||
moment.utc('5/12/1982 1:00', 'M/D/YYYY H:mm').valueOf()
|
||||
])
|
||||
).toEqual(12222);
|
||||
|
||||
t.equal(
|
||||
dayCount([
|
||||
moment.utc('10/27/2015 1:00', 'M/D/YYYY H:mm').valueOf(),
|
||||
moment.utc('5/12/1982 1:00', 'M/D/YYYY H:mm').valueOf()
|
||||
]),
|
||||
12222,
|
||||
'should return correct count when there is very big period'
|
||||
);
|
||||
|
||||
t.equal(
|
||||
dayCount([
|
||||
moment.utc('8/4/2015 2:00', 'M/D/YYYY H:mm').valueOf(),
|
||||
moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf()
|
||||
]),
|
||||
2,
|
||||
'should return 2 days when there is a 24 hours difference ' +
|
||||
'between dates given `undefined` timezone'
|
||||
);
|
||||
it(
|
||||
'should return 2 days when there is a 24 hours difference ' +
|
||||
'between dates given `undefined` timezone',
|
||||
() => {}
|
||||
);
|
||||
expect(
|
||||
dayCount([
|
||||
moment.utc('8/4/2015 2:00', 'M/D/YYYY H:mm').valueOf(),
|
||||
moment.utc('8/3/2015 2:00', 'M/D/YYYY H:mm').valueOf()
|
||||
])
|
||||
).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user