-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvspHelpers.spec.ts
More file actions
173 lines (145 loc) · 6.43 KB
/
Copy pathvspHelpers.spec.ts
File metadata and controls
173 lines (145 loc) · 6.43 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import {
constructVSPUrl,
constructVSPId,
parseIGCanonical,
validateVSPVersion,
generateVSPName,
generateVSPTitle
} from './vspHelpers'
import { VSPMetadata } from '@/types/vspTypes'
describe('vspHelpers', () => {
describe('constructVSPUrl', () => {
const baseMetadata: VSPMetadata = {
igCanonical: 'http://hl7.org/fhir/us/core/ImplementationGuide/hl7.fhir.us.core|6.1.0',
igUrl: 'http://hl7.org/fhir/us/core/ImplementationGuide/hl7.fhir.us.core',
igVersion: '6.1.0',
igPackageId: 'hl7.fhir.us.core',
igName: 'USCore',
igTitle: 'US Core',
vspVersion: '2026-01',
status: 'draft'
}
it('should build the correct URL for a standard IG', () => {
const result = constructVSPUrl(baseMetadata)
expect(result).toBe('http://hl7.org/fhir/us/core-vsp/6.1.0/Library/hl7.fhir.us.core-vsp-2026-01')
})
it('should strip /ImplementationGuide/... from the IG URL', () => {
const result = constructVSPUrl(baseMetadata)
expect(result).not.toContain('ImplementationGuide')
})
it('should handle different IG URLs', () => {
const metadata: VSPMetadata = {
...baseMetadata,
igUrl: 'http://hl7.org/fhir/us/ecr/ImplementationGuide/hl7.fhir.us.ecr',
igVersion: '2.1.0',
igPackageId: 'hl7.fhir.us.ecr',
vspVersion: '2025-06'
}
const result = constructVSPUrl(metadata)
expect(result).toBe('http://hl7.org/fhir/us/ecr-vsp/2.1.0/Library/hl7.fhir.us.ecr-vsp-2025-06')
})
it('should handle VSP version with different months', () => {
const metadata: VSPMetadata = { ...baseMetadata, vspVersion: '2026-12' }
const result = constructVSPUrl(metadata)
expect(result).toContain('hl7.fhir.us.core-vsp-2026-12')
})
})
describe('constructVSPId', () => {
it('should build a correct VSP ID including the IG version', () => {
expect(constructVSPId('hl7.fhir.us.core', '6.1.0', '2026-01')).toBe('hl7.fhir.us.core.6.1.0-2026-01')
})
it('should handle different package IDs and versions', () => {
expect(constructVSPId('hl7.fhir.us.ecr', '2.1.0', '2025-06')).toBe('hl7.fhir.us.ecr.2.1.0-2025-06')
})
it('should include the full version string', () => {
const id = constructVSPId('some.package', '1.0.0', '2030-12')
expect(id).toBe('some.package.1.0.0-2030-12')
})
it('should produce distinct IDs for different IG versions with the same VSP version (issue #700)', () => {
expect(constructVSPId('hl7.fhir.us.core', '6.1.0', '2026-06'))
.not.toBe(constructVSPId('hl7.fhir.us.core', '6.2.0', '2026-06'))
})
})
describe('parseIGCanonical', () => {
it('should split canonical into URL and version', () => {
const result = parseIGCanonical('http://hl7.org/fhir/us/core/ImplementationGuide/hl7.fhir.us.core|6.1.0')
expect(result.url).toBe('http://hl7.org/fhir/us/core/ImplementationGuide/hl7.fhir.us.core')
expect(result.version).toBe('6.1.0')
})
it('should handle canonical without version', () => {
const result = parseIGCanonical('http://hl7.org/fhir/us/core/ImplementationGuide/hl7.fhir.us.core')
expect(result.url).toBe('http://hl7.org/fhir/us/core/ImplementationGuide/hl7.fhir.us.core')
expect(result.version).toBeUndefined()
})
it('should handle canonical with complex version', () => {
const result = parseIGCanonical('http://example.org/ig|1.2.3-beta')
expect(result.url).toBe('http://example.org/ig')
expect(result.version).toBe('1.2.3-beta')
})
})
describe('validateVSPVersion', () => {
it('should accept valid YYYY-MM formats', () => {
expect(validateVSPVersion('2026-01')).toBe(true)
expect(validateVSPVersion('2026-06')).toBe(true)
expect(validateVSPVersion('2026-12')).toBe(true)
expect(validateVSPVersion('2000-01')).toBe(true)
expect(validateVSPVersion('9999-09')).toBe(true)
})
it('should reject invalid month 00', () => {
expect(validateVSPVersion('2026-00')).toBe(false)
})
it('should reject invalid month > 12', () => {
expect(validateVSPVersion('2026-13')).toBe(false)
expect(validateVSPVersion('2026-99')).toBe(false)
})
it('should reject short year', () => {
expect(validateVSPVersion('26-01')).toBe(false)
expect(validateVSPVersion('202-01')).toBe(false)
})
it('should reject month without leading zero', () => {
expect(validateVSPVersion('2026-1')).toBe(false)
expect(validateVSPVersion('2026-9')).toBe(false)
})
it('should reject empty string', () => {
expect(validateVSPVersion('')).toBe(false)
})
it('should reject non-date formats', () => {
expect(validateVSPVersion('not-a-date')).toBe(false)
expect(validateVSPVersion('2026/01')).toBe(false)
expect(validateVSPVersion('2026.01')).toBe(false)
expect(validateVSPVersion('20260-01')).toBe(false)
})
it('should reject formats with extra parts', () => {
expect(validateVSPVersion('2026-01-01')).toBe(false)
expect(validateVSPVersion('2026-01-')).toBe(false)
})
})
describe('generateVSPName', () => {
it('should create a clean identifier from IG name and version', () => {
expect(generateVSPName('USCore', '6.1.0')).toBe('USCore610ValueSetPackageDefinition')
})
it('should strip spaces from IG name', () => {
expect(generateVSPName('US Core', '6.1.0')).toBe('USCore610ValueSetPackageDefinition')
})
it('should strip dots and hyphens from IG name', () => {
expect(generateVSPName('hl7.fhir.us-core', '6.1.0')).toBe('hl7fhiruscore610ValueSetPackageDefinition')
})
it('should strip non-numeric chars from version', () => {
expect(generateVSPName('Test', '1.2.3-beta')).toBe('Test123ValueSetPackageDefinition')
})
it('should handle simple names and versions', () => {
expect(generateVSPName('ECR', '2.0.0')).toBe('ECR200ValueSetPackageDefinition')
})
})
describe('generateVSPTitle', () => {
it('should create a human-readable title', () => {
expect(generateVSPTitle('US Core', '6.1.0')).toBe('US Core 6.1.0 Value Set Package Definition')
})
it('should preserve spaces in the IG title', () => {
expect(generateVSPTitle('Electronic Case Reporting', '2.1.0')).toBe('Electronic Case Reporting 2.1.0 Value Set Package Definition')
})
it('should handle single-word titles', () => {
expect(generateVSPTitle('ECR', '1.0.0')).toBe('ECR 1.0.0 Value Set Package Definition')
})
})
})