calendarDateBounds.helpers.test.mjs
2.71 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
74
75
76
77
78
79
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { existsSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import * as equityDateBounds from '../packageEquity/services/calendarDateBounds.helpers.js'
import * as workOrderDateBounds from '../tabWorkOrder/services/calendarDateBounds.helpers.js'
const sharedImplementations = [
['packageEquity', equityDateBounds],
['tabWorkOrder', workOrderDateBounds]
]
it('keeps subpackage-only calendar code out of the main package', () => {
const formerMainPackagePath = fileURLToPath(
new URL('../utils/calendarDateBounds.helpers.js', import.meta.url)
)
assert.equal(existsSync(formerMainPackagePath), false)
})
describe('coalesceYmd', () => {
for (const [packageName, { coalesceYmd }] of sharedImplementations) {
it(`${packageName}: returns bound when set`, () => {
assert.equal(coalesceYmd('2026-07-05', '2026-07-06'), '2026-07-05')
})
it(`${packageName}: falls back when bound empty`, () => {
assert.equal(coalesceYmd('', '2026-07-06'), '2026-07-06')
assert.equal(coalesceYmd(' ', '2026-07-06'), '2026-07-06')
})
}
})
describe('formatDayStartForSubmit', () => {
const { formatDayStartForSubmit } = workOrderDateBounds
it('tabWorkOrder: appends 00:00:00', () => {
assert.equal(formatDayStartForSubmit('2026-07-06'), '2026-07-06 00:00:00')
})
it('tabWorkOrder: does not double-append', () => {
assert.equal(
formatDayStartForSubmit('2026-07-06 00:00:00'),
'2026-07-06 00:00:00'
)
})
})
describe('isDateOnOrAfterToday', () => {
const today = '2026-07-06'
const { isDateOnOrAfterToday } = workOrderDateBounds
it('tabWorkOrder: true for today and future', () => {
assert.equal(isDateOnOrAfterToday('2026-07-06', today), true)
assert.equal(isDateOnOrAfterToday('2026-07-07', today), true)
})
it('tabWorkOrder: false for past and missing values', () => {
assert.equal(isDateOnOrAfterToday('2026-07-05', today), false)
assert.equal(isDateOnOrAfterToday('', today), false)
assert.equal(isDateOnOrAfterToday(today, ''), false)
})
})
describe('isDateOnOrBeforeToday', () => {
const today = '2026-07-06'
for (const [packageName, { isDateOnOrBeforeToday }] of sharedImplementations) {
it(`${packageName}: true for today and past`, () => {
assert.equal(isDateOnOrBeforeToday('2026-07-06', today), true)
assert.equal(isDateOnOrBeforeToday('2026-07-05', today), true)
})
it(`${packageName}: false for future and missing values`, () => {
assert.equal(isDateOnOrBeforeToday('2026-07-07', today), false)
assert.equal(isDateOnOrBeforeToday('', today), false)
assert.equal(isDateOnOrBeforeToday(today, ''), false)
})
}
})