plan-import-date-value.test.mjs
2.15 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const {
PLAN_IMPORT_DATE_FIELD_KEY,
wrapPlanImportDate,
unwrapPlanImportDate,
hasPlanImportDateMarker,
clearPlanImportDateMarker,
maybeRestorePlanImportDateMarker
} = require('../form-engine/plan-import-date-value.js')
function tomorrowYmd() {
const d = new Date()
d.setDate(d.getDate() + 1)
const y = d.getFullYear()
const m = `${d.getMonth() + 1}`.padStart(2, '0')
const day = `${d.getDate()}`.padStart(2, '0')
return `${y}-${m}-${day}`
}
describe('plan-import-date-value', () => {
it('IT-PLAN-DATE-001: wrap and unwrap round-trip', () => {
const wrapped = wrapPlanImportDate('2026-12-31')
assert.equal(wrapped.value, '2026-12-31')
assert.equal(wrapped.partialFromPlanImport, true)
assert.equal(unwrapPlanImportDate(wrapped), '2026-12-31')
assert.equal(hasPlanImportDateMarker(wrapped), true)
})
it('IT-PLAN-DATE-002: clearPlanImportDateMarker returns plain string', () => {
const wrapped = wrapPlanImportDate('2026-12-31')
assert.equal(clearPlanImportDateMarker(wrapped), '2026-12-31')
assert.equal(hasPlanImportDateMarker(clearPlanImportDateMarker(wrapped)), false)
})
it('IT-PLAN-DATE-003: maybeRestore only for F3-4-1 future dates', () => {
const future = tomorrowYmd()
const restored = maybeRestorePlanImportDateMarker(PLAN_IMPORT_DATE_FIELD_KEY, future)
assert.equal(hasPlanImportDateMarker(restored), true)
assert.equal(unwrapPlanImportDate(restored), future)
assert.equal(maybeRestorePlanImportDateMarker('F3-2-1', future), future)
})
it('IT-PLAN-DATE-004: maybeRestore skips past dates', () => {
const past = '2000-01-01'
assert.equal(maybeRestorePlanImportDateMarker(PLAN_IMPORT_DATE_FIELD_KEY, past), past)
})
it('IT-PLAN-DATE-005: wrap uses literal partialFromPlanImport key', () => {
const wrapped = wrapPlanImportDate('2026-12-31')
assert.ok(Object.prototype.hasOwnProperty.call(wrapped, 'partialFromPlanImport'))
assert.equal(wrapped.partialFromPlanImport, true)
assert.equal(Object.keys(wrapped).filter(k => k === 'undefined').length, 0)
})
})