-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformatEventDate.test.js
More file actions
73 lines (65 loc) · 2.27 KB
/
formatEventDate.test.js
File metadata and controls
73 lines (65 loc) · 2.27 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { assert } from './test-utils/deps-node.js';
import { formatEventDate, HDSSettings } from '../ts/index.ts';
// Mock connection
function createMockConnection (settingsEvents = []) {
return {
async api (calls) {
return calls.map(call => {
if (call.method === 'events.get') {
if (call.params.streams[0] === 'test-stream') {
return { events: settingsEvents };
}
return { events: [] };
}
return {};
});
},
async apiOne (method, params, key) {
const result = await this.api([{ method, params }]);
return key ? result[0][key] : result[0];
}
};
}
describe('[FED] formatEventDate', function () {
afterEach(() => {
HDSSettings.unhook();
});
// 2024-01-15T12:00:00Z = 1705320000
const timestamp = 1705320000;
it('[FED1] returns ISO date when not hooked', () => {
const result = formatEventDate(timestamp);
assert.strictEqual(result, '2024-01-15');
});
it('[FED2] uses DD.MM.YYYY format', async () => {
const conn = createMockConnection([
{ id: 'ev1', type: 'settings/date-format', content: 'DD.MM.YYYY' }
]);
await HDSSettings.hookToConnection(conn, 'test-stream');
const result = formatEventDate(timestamp);
assert.strictEqual(result, '15.01.2024');
});
it('[FED3] uses DD/MM/YYYY format', async () => {
const conn = createMockConnection([
{ id: 'ev1', type: 'settings/date-format', content: 'DD/MM/YYYY' }
]);
await HDSSettings.hookToConnection(conn, 'test-stream');
const result = formatEventDate(timestamp);
assert.strictEqual(result, '15/01/2024');
});
it('[FED4] uses MM/DD/YYYY format', async () => {
const conn = createMockConnection([
{ id: 'ev1', type: 'settings/date-format', content: 'MM/DD/YYYY' }
]);
await HDSSettings.hookToConnection(conn, 'test-stream');
const result = formatEventDate(timestamp);
assert.strictEqual(result, '01/15/2024');
});
it('[FED5] uses YYYY-MM-DD format', async () => {
const conn = createMockConnection([
{ id: 'ev1', type: 'settings/date-format', content: 'YYYY-MM-DD' }
]);
await HDSSettings.hookToConnection(conn, 'test-stream');
const result = formatEventDate(timestamp);
assert.strictEqual(result, '2024-01-15');
});
});