tests/common/date-util.test.js   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 50
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 37
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 2
mnd 0
bc 0
fnc 2
bpm 0
cpm 1
noi 5
1
/* global describe test expect beforeAll afterAll */
0 ignored issues
show
Unused Code introduced by
'describe' is defined but never used.
Loading history...
Unused Code introduced by
'beforeAll' is defined but never used.
Loading history...
Unused Code introduced by
'afterAll' is defined but never used.
Loading history...
2
3
const util = require('../../src/common/date-util');
4
const moment = require('moment');
5
6
const datesObjects = [
7
  {
8
    param: { date1: moment('2012-04-03T22:33:00+09:00') },
9
    expected: { date1: '2012-04-03T22:33:00+09:00' },
10
    expected2: { date1: '2012-04-03T21:33:00+08:00' },
11
    expected3: { date1: '2012-04-03 21' },
12
  },
13
  {
14
    param: [moment('2012-04-03T22:33:00+09:00')],
15
    expected: ['2012-04-03T22:33:00+09:00'],
16
    expected2: ['2012-04-03T21:33:00+08:00'],
17
    expected3: ['2012-04-03 21'],
18
  },
19
  {
20
    param: 'string',
21
    expected: 'string',
22
    expected2: 'string',
23
    expected3: 'string',
24
  },
25
  {
26
    param: [
27
      { date1: moment('2016-03-23T10:00:00+08:00'), date2: [moment('2016-03-23T10:00:00+08:00')] },
28
      { date3: 'string', date4: [moment('2016-03-23T10:00:00+08:00')] },
29
    ],
30
    expected: [
31
      { date1: '2016-03-23T11:00:00+09:00', date2: ['2016-03-23T11:00:00+09:00'] },
32
      { date3: 'string', date4: ['2016-03-23T11:00:00+09:00'] },
33
    ],
34
    expected2: [
35
      { date1: '2016-03-23T10:00:00+08:00', date2: ['2016-03-23T10:00:00+08:00'] },
36
      { date3: 'string', date4: ['2016-03-23T10:00:00+08:00'] },
37
    ],
38
    expected3: [
39
      { date1: '2016-03-23 10', date2: ['2016-03-23 10'] },
40
      { date3: 'string', date4: ['2016-03-23 10'] },
41
    ],
42
  },
43
];
44
45
test('formatDates', () => {
0 ignored issues
show
introduced by
Unexpected block statement surrounding arrow body; move the returned value immediately after the =>.
Loading history...
46
  return Promise.all(datesObjects.map((obj) => {
47
    expect(util.formatDates(obj.param)).toEqual(obj.expected);
48
    expect(util.formatDates(obj.param, undefined, 8)).toEqual(obj.expected2);
49
    expect(util.formatDates(obj.param, 'YYYY-MM-DD HH', 8)).toEqual(obj.expected3);
50
    return Promise.resolve();
51
  }));
52
});
53
0 ignored issues
show
introduced by
Too many blank lines at the end of file. Max of 0 allowed.
Loading history...
54