-
Notifications
You must be signed in to change notification settings - Fork 188
/
Copy pathutils.test.js
26 lines (22 loc) · 989 Bytes
/
utils.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const { parseDuration } = require('./src/utils');
describe('parseDuration', () => {
it('should parse valid duration', () => {
expect(parseDuration('2d').toString()).toEqual('P2D');
expect(parseDuration('2day').toString()).toEqual('P2D');
expect(parseDuration('2days').toString()).toEqual('P2D');
expect(parseDuration('365d').toString()).toEqual('P365D');
});
it('should throw on invalid duration', () => {
expect(() => parseDuration('foo')).toThrowError();
});
it('should auto-fix 24h durations to 25h', () => {
expect(parseDuration(24).toString()).toEqual('PT25H');
expect(parseDuration('1day').toString()).toEqual('PT25H');
expect(parseDuration('1d').toString()).toEqual('PT25H');
expect(parseDuration('24h').toString()).toEqual('PT25H');
expect(parseDuration('1440m').toString()).toEqual('PT25H');
});
it('should auto-fix 1y durations to 365 days', () => {
expect(parseDuration('1y').toString()).toEqual('P365D');
});
});