@api-client/core 0.17.4 → 0.17.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/modeling/Semantics.d.ts +1 -1
- package/build/src/modeling/Semantics.d.ts.map +1 -1
- package/build/src/modeling/Semantics.js +6 -6
- package/build/src/modeling/Semantics.js.map +1 -1
- package/build/src/modeling/definitions/{Price.d.ts → Currency.d.ts} +24 -24
- package/build/src/modeling/definitions/Currency.d.ts.map +1 -0
- package/build/src/modeling/definitions/{Price.js → Currency.js} +18 -18
- package/build/src/modeling/definitions/Currency.js.map +1 -0
- package/build/src/modeling/definitions/HTML.d.ts +17 -4
- package/build/src/modeling/definitions/HTML.d.ts.map +1 -1
- package/build/src/modeling/definitions/HTML.js +0 -1
- package/build/src/modeling/definitions/HTML.js.map +1 -1
- package/build/src/modeling/definitions/Markdown.d.ts +12 -4
- package/build/src/modeling/definitions/Markdown.d.ts.map +1 -1
- package/build/src/modeling/definitions/Markdown.js +0 -1
- package/build/src/modeling/definitions/Markdown.js.map +1 -1
- package/build/src/modeling/definitions/Status.d.ts +1 -1
- package/build/src/modeling/definitions/Status.d.ts.map +1 -1
- package/build/src/modeling/definitions/Status.js +1 -0
- package/build/src/modeling/definitions/Status.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/modeling/Semantics.ts +6 -6
- package/src/modeling/definitions/{Price.examples.md → Currency.examples.md} +12 -12
- package/src/modeling/definitions/{Price.ts → Currency.ts} +26 -26
- package/src/modeling/definitions/HTML.ts +17 -5
- package/src/modeling/definitions/Markdown.ts +12 -5
- package/src/modeling/definitions/Status.ts +2 -1
- package/tests/unit/modeling/definitions/{price.spec.ts → currency.spec.ts} +114 -114
- package/tests/unit/modeling/definitions/description.spec.ts +0 -2
- package/tests/unit/modeling/semantic-configs.spec.ts +44 -44
- package/tests/unit/modeling/semantics.spec.ts +10 -1
- package/build/src/modeling/definitions/Price.d.ts.map +0 -1
- package/build/src/modeling/definitions/Price.js.map +0 -1
|
@@ -1,183 +1,183 @@
|
|
|
1
1
|
import { test } from '@japa/runner'
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
} from '../../../../src/modeling/definitions/
|
|
3
|
+
createCurrencySemantic,
|
|
4
|
+
isCurrencySemantic,
|
|
5
|
+
validateCurrencyConfig,
|
|
6
|
+
DEFAULT_CURRENCY_CONFIG,
|
|
7
|
+
CURRENCY_PRESETS,
|
|
8
|
+
type CurrencyConfig,
|
|
9
|
+
} from '../../../../src/modeling/definitions/Currency.js'
|
|
10
10
|
import { SemanticType, type AppliedDataSemantic } from '../../../../src/modeling/Semantics.js'
|
|
11
11
|
|
|
12
|
-
test.group('
|
|
12
|
+
test.group('Currency Semantic Configuration', () => {
|
|
13
13
|
test('should create semantic with default config', ({ assert }) => {
|
|
14
|
-
const semantic =
|
|
15
|
-
assert.equal(semantic.id, SemanticType.
|
|
16
|
-
assert.deepEqual(semantic.config,
|
|
14
|
+
const semantic = createCurrencySemantic()
|
|
15
|
+
assert.equal(semantic.id, SemanticType.Currency)
|
|
16
|
+
assert.deepEqual(semantic.config, DEFAULT_CURRENCY_CONFIG)
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
test('should create semantic with custom config', ({ assert }) => {
|
|
20
|
-
const config:
|
|
20
|
+
const config: CurrencyConfig = {
|
|
21
21
|
storageFormat: 'complex_object',
|
|
22
22
|
allowedCurrencies: ['USD', 'EUR'],
|
|
23
23
|
decimalPlaces: 4,
|
|
24
24
|
allowNegative: true,
|
|
25
25
|
validateCurrencyCode: false,
|
|
26
26
|
}
|
|
27
|
-
const semantic =
|
|
28
|
-
assert.equal(semantic.id, SemanticType.
|
|
29
|
-
assert.deepEqual(semantic.config, { ...
|
|
27
|
+
const semantic = createCurrencySemantic(config)
|
|
28
|
+
assert.equal(semantic.id, SemanticType.Currency)
|
|
29
|
+
assert.deepEqual(semantic.config, { ...DEFAULT_CURRENCY_CONFIG, ...config })
|
|
30
30
|
})
|
|
31
31
|
|
|
32
32
|
test('should merge metadata properly', ({ assert }) => {
|
|
33
|
-
const config:
|
|
33
|
+
const config: CurrencyConfig = {
|
|
34
34
|
metadata: {
|
|
35
35
|
customField: 'value',
|
|
36
36
|
anotherField: 123,
|
|
37
37
|
},
|
|
38
38
|
}
|
|
39
|
-
const semantic =
|
|
40
|
-
assert.equal(semantic.id, SemanticType.
|
|
39
|
+
const semantic = createCurrencySemantic(config)
|
|
40
|
+
assert.equal(semantic.id, SemanticType.Currency)
|
|
41
41
|
assert.deepEqual(semantic.config?.metadata, config.metadata)
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
test('should identify
|
|
45
|
-
const semantic =
|
|
46
|
-
assert.isTrue(
|
|
44
|
+
test('should identify currency semantic', ({ assert }) => {
|
|
45
|
+
const semantic = createCurrencySemantic()
|
|
46
|
+
assert.isTrue(isCurrencySemantic(semantic))
|
|
47
47
|
})
|
|
48
48
|
|
|
49
|
-
test('should not identify non-
|
|
49
|
+
test('should not identify non-currency semantic', ({ assert }) => {
|
|
50
50
|
const fakeSemantic: AppliedDataSemantic = {
|
|
51
51
|
id: SemanticType.Email,
|
|
52
52
|
config: {},
|
|
53
53
|
}
|
|
54
|
-
assert.isFalse(
|
|
54
|
+
assert.isFalse(isCurrencySemantic(fakeSemantic))
|
|
55
55
|
})
|
|
56
56
|
|
|
57
|
-
test('
|
|
58
|
-
assert.equal(
|
|
59
|
-
assert.equal(
|
|
60
|
-
assert.equal(
|
|
61
|
-
assert.equal(
|
|
62
|
-
assert.equal(
|
|
57
|
+
test('DEFAULT_CURRENCY_CONFIG should have correct values', ({ assert }) => {
|
|
58
|
+
assert.equal(DEFAULT_CURRENCY_CONFIG.storageFormat, 'decimal')
|
|
59
|
+
assert.equal(DEFAULT_CURRENCY_CONFIG.defaultCurrency, 'USD')
|
|
60
|
+
assert.equal(DEFAULT_CURRENCY_CONFIG.decimalPlaces, 2)
|
|
61
|
+
assert.equal(DEFAULT_CURRENCY_CONFIG.allowNegative, false)
|
|
62
|
+
assert.equal(DEFAULT_CURRENCY_CONFIG.validateCurrencyCode, true)
|
|
63
63
|
})
|
|
64
64
|
})
|
|
65
65
|
|
|
66
|
-
test.group('
|
|
66
|
+
test.group('Currency Storage Formats', () => {
|
|
67
67
|
test('should support decimal storage format', ({ assert }) => {
|
|
68
|
-
const config:
|
|
68
|
+
const config: CurrencyConfig = {
|
|
69
69
|
storageFormat: 'decimal',
|
|
70
70
|
defaultCurrency: 'USD',
|
|
71
71
|
decimalPlaces: 2,
|
|
72
72
|
}
|
|
73
|
-
const semantic =
|
|
73
|
+
const semantic = createCurrencySemantic(config)
|
|
74
74
|
assert.equal(semantic.config?.storageFormat, 'decimal')
|
|
75
75
|
assert.equal(semantic.config?.defaultCurrency, 'USD')
|
|
76
76
|
assert.equal(semantic.config?.decimalPlaces, 2)
|
|
77
77
|
})
|
|
78
78
|
|
|
79
79
|
test('should support integer_cents storage format', ({ assert }) => {
|
|
80
|
-
const config:
|
|
80
|
+
const config: CurrencyConfig = {
|
|
81
81
|
storageFormat: 'integer_cents',
|
|
82
82
|
defaultCurrency: 'EUR',
|
|
83
83
|
decimalPlaces: 2,
|
|
84
84
|
}
|
|
85
|
-
const semantic =
|
|
85
|
+
const semantic = createCurrencySemantic(config)
|
|
86
86
|
assert.equal(semantic.config?.storageFormat, 'integer_cents')
|
|
87
87
|
assert.equal(semantic.config?.defaultCurrency, 'EUR')
|
|
88
88
|
})
|
|
89
89
|
|
|
90
90
|
test('should support complex_object storage format', ({ assert }) => {
|
|
91
|
-
const config:
|
|
91
|
+
const config: CurrencyConfig = {
|
|
92
92
|
storageFormat: 'complex_object',
|
|
93
93
|
allowedCurrencies: ['USD', 'EUR', 'GBP'],
|
|
94
94
|
decimalPlaces: 2,
|
|
95
95
|
}
|
|
96
|
-
const semantic =
|
|
96
|
+
const semantic = createCurrencySemantic(config)
|
|
97
97
|
assert.equal(semantic.config?.storageFormat, 'complex_object')
|
|
98
98
|
assert.deepEqual(semantic.config?.allowedCurrencies, ['USD', 'EUR', 'GBP'])
|
|
99
99
|
})
|
|
100
100
|
})
|
|
101
101
|
|
|
102
|
-
test.group('
|
|
102
|
+
test.group('Currency Configuration Validation', () => {
|
|
103
103
|
test('should validate that defaultCurrency is required for decimal format', ({ assert }) => {
|
|
104
|
-
const config:
|
|
104
|
+
const config: CurrencyConfig = {
|
|
105
105
|
storageFormat: 'decimal',
|
|
106
106
|
// Missing defaultCurrency
|
|
107
107
|
decimalPlaces: 2,
|
|
108
108
|
}
|
|
109
|
-
const errors =
|
|
109
|
+
const errors = validateCurrencyConfig(config)
|
|
110
110
|
assert.include(errors, 'defaultCurrency is required when storageFormat is not complex_object')
|
|
111
111
|
})
|
|
112
112
|
|
|
113
113
|
test('should validate that defaultCurrency is required for integer_cents format', ({ assert }) => {
|
|
114
|
-
const config:
|
|
114
|
+
const config: CurrencyConfig = {
|
|
115
115
|
storageFormat: 'integer_cents',
|
|
116
116
|
// Missing defaultCurrency
|
|
117
117
|
decimalPlaces: 2,
|
|
118
118
|
}
|
|
119
|
-
const errors =
|
|
119
|
+
const errors = validateCurrencyConfig(config)
|
|
120
120
|
assert.include(errors, 'defaultCurrency is required when storageFormat is not complex_object')
|
|
121
121
|
})
|
|
122
122
|
|
|
123
123
|
test('should not require defaultCurrency for complex_object format', ({ assert }) => {
|
|
124
|
-
const config:
|
|
124
|
+
const config: CurrencyConfig = {
|
|
125
125
|
storageFormat: 'complex_object',
|
|
126
126
|
// No defaultCurrency needed
|
|
127
127
|
allowedCurrencies: ['USD', 'EUR'],
|
|
128
128
|
}
|
|
129
|
-
const errors =
|
|
129
|
+
const errors = validateCurrencyConfig(config)
|
|
130
130
|
assert.notInclude(errors, 'defaultCurrency is required when storageFormat is not complex_object')
|
|
131
131
|
})
|
|
132
132
|
|
|
133
133
|
test('should validate that decimalPlaces is non-negative', ({ assert }) => {
|
|
134
|
-
const config:
|
|
134
|
+
const config: CurrencyConfig = {
|
|
135
135
|
storageFormat: 'decimal',
|
|
136
136
|
defaultCurrency: 'USD',
|
|
137
137
|
decimalPlaces: -1,
|
|
138
138
|
}
|
|
139
|
-
const errors =
|
|
139
|
+
const errors = validateCurrencyConfig(config)
|
|
140
140
|
assert.include(errors, 'decimalPlaces must be non-negative')
|
|
141
141
|
})
|
|
142
142
|
|
|
143
143
|
test('should accept zero decimal places', ({ assert }) => {
|
|
144
|
-
const config:
|
|
144
|
+
const config: CurrencyConfig = {
|
|
145
145
|
storageFormat: 'decimal',
|
|
146
146
|
defaultCurrency: 'JPY',
|
|
147
147
|
decimalPlaces: 0,
|
|
148
148
|
}
|
|
149
|
-
const errors =
|
|
149
|
+
const errors = validateCurrencyConfig(config)
|
|
150
150
|
assert.notInclude(errors, 'decimalPlaces must be non-negative')
|
|
151
151
|
})
|
|
152
152
|
|
|
153
153
|
test('should return empty array for valid config', ({ assert }) => {
|
|
154
|
-
const config:
|
|
154
|
+
const config: CurrencyConfig = {
|
|
155
155
|
storageFormat: 'decimal',
|
|
156
156
|
defaultCurrency: 'USD',
|
|
157
157
|
decimalPlaces: 2,
|
|
158
158
|
allowNegative: false,
|
|
159
159
|
}
|
|
160
|
-
const errors =
|
|
160
|
+
const errors = validateCurrencyConfig(config)
|
|
161
161
|
assert.lengthOf(errors, 0)
|
|
162
162
|
})
|
|
163
163
|
|
|
164
164
|
test('should accumulate multiple validation errors', ({ assert }) => {
|
|
165
|
-
const config:
|
|
165
|
+
const config: CurrencyConfig = {
|
|
166
166
|
storageFormat: 'decimal',
|
|
167
167
|
// Missing defaultCurrency
|
|
168
168
|
decimalPlaces: -2, // Invalid decimal places
|
|
169
169
|
}
|
|
170
|
-
const errors =
|
|
170
|
+
const errors = validateCurrencyConfig(config)
|
|
171
171
|
assert.lengthOf(errors, 2)
|
|
172
172
|
assert.include(errors, 'defaultCurrency is required when storageFormat is not complex_object')
|
|
173
173
|
assert.include(errors, 'decimalPlaces must be non-negative')
|
|
174
174
|
})
|
|
175
175
|
})
|
|
176
176
|
|
|
177
|
-
test.group('
|
|
177
|
+
test.group('Currency Presets', () => {
|
|
178
178
|
test('USD_DECIMAL preset should have correct configuration', ({ assert }) => {
|
|
179
|
-
const preset =
|
|
180
|
-
assert.equal(preset.id, SemanticType.
|
|
179
|
+
const preset = CURRENCY_PRESETS.USD_DECIMAL
|
|
180
|
+
assert.equal(preset.id, SemanticType.Currency)
|
|
181
181
|
assert.equal(preset.config?.storageFormat, 'decimal')
|
|
182
182
|
assert.equal(preset.config?.defaultCurrency, 'USD')
|
|
183
183
|
assert.equal(preset.config?.decimalPlaces, 2)
|
|
@@ -185,8 +185,8 @@ test.group('Price Presets', () => {
|
|
|
185
185
|
})
|
|
186
186
|
|
|
187
187
|
test('USD_CENTS preset should have correct configuration', ({ assert }) => {
|
|
188
|
-
const preset =
|
|
189
|
-
assert.equal(preset.id, SemanticType.
|
|
188
|
+
const preset = CURRENCY_PRESETS.USD_CENTS
|
|
189
|
+
assert.equal(preset.id, SemanticType.Currency)
|
|
190
190
|
assert.equal(preset.config?.storageFormat, 'integer_cents')
|
|
191
191
|
assert.equal(preset.config?.defaultCurrency, 'USD')
|
|
192
192
|
assert.equal(preset.config?.decimalPlaces, 2)
|
|
@@ -194,8 +194,8 @@ test.group('Price Presets', () => {
|
|
|
194
194
|
})
|
|
195
195
|
|
|
196
196
|
test('MULTI_CURRENCY preset should have correct configuration', ({ assert }) => {
|
|
197
|
-
const preset =
|
|
198
|
-
assert.equal(preset.id, SemanticType.
|
|
197
|
+
const preset = CURRENCY_PRESETS.MULTI_CURRENCY
|
|
198
|
+
assert.equal(preset.id, SemanticType.Currency)
|
|
199
199
|
assert.equal(preset.config?.storageFormat, 'complex_object')
|
|
200
200
|
assert.deepEqual(preset.config?.allowedCurrencies, ['USD', 'EUR', 'GBP', 'JPY', 'CAD'])
|
|
201
201
|
assert.equal(preset.config?.decimalPlaces, 2)
|
|
@@ -203,8 +203,8 @@ test.group('Price Presets', () => {
|
|
|
203
203
|
})
|
|
204
204
|
|
|
205
205
|
test('WITH_NEGATIVES preset should have correct configuration', ({ assert }) => {
|
|
206
|
-
const preset =
|
|
207
|
-
assert.equal(preset.id, SemanticType.
|
|
206
|
+
const preset = CURRENCY_PRESETS.WITH_NEGATIVES
|
|
207
|
+
assert.equal(preset.id, SemanticType.Currency)
|
|
208
208
|
assert.equal(preset.config?.storageFormat, 'decimal')
|
|
209
209
|
assert.equal(preset.config?.defaultCurrency, 'USD')
|
|
210
210
|
assert.equal(preset.config?.decimalPlaces, 2)
|
|
@@ -212,134 +212,134 @@ test.group('Price Presets', () => {
|
|
|
212
212
|
})
|
|
213
213
|
|
|
214
214
|
test('HIGH_PRECISION preset should have correct configuration', ({ assert }) => {
|
|
215
|
-
const preset =
|
|
216
|
-
assert.equal(preset.id, SemanticType.
|
|
215
|
+
const preset = CURRENCY_PRESETS.HIGH_PRECISION
|
|
216
|
+
assert.equal(preset.id, SemanticType.Currency)
|
|
217
217
|
assert.equal(preset.config?.storageFormat, 'decimal')
|
|
218
218
|
assert.equal(preset.config?.defaultCurrency, 'BTC')
|
|
219
219
|
assert.equal(preset.config?.decimalPlaces, 8)
|
|
220
220
|
assert.equal(preset.config?.allowNegative, false)
|
|
221
221
|
})
|
|
222
222
|
|
|
223
|
-
test('all presets should be valid
|
|
224
|
-
Object.values(
|
|
225
|
-
assert.isTrue(
|
|
223
|
+
test('all presets should be valid currency semantics', ({ assert }) => {
|
|
224
|
+
Object.values(CURRENCY_PRESETS).forEach((preset) => {
|
|
225
|
+
assert.isTrue(isCurrencySemantic(preset))
|
|
226
226
|
// Validate each preset config
|
|
227
227
|
if (preset.config) {
|
|
228
|
-
const errors =
|
|
228
|
+
const errors = validateCurrencyConfig(preset.config)
|
|
229
229
|
assert.lengthOf(errors, 0, `Preset ${preset.config.storageFormat} should have valid config`)
|
|
230
230
|
}
|
|
231
231
|
})
|
|
232
232
|
})
|
|
233
233
|
})
|
|
234
234
|
|
|
235
|
-
test.group('
|
|
235
|
+
test.group('Currency Currency Configuration', () => {
|
|
236
236
|
test('should support single currency with defaultCurrency', ({ assert }) => {
|
|
237
|
-
const config:
|
|
237
|
+
const config: CurrencyConfig = {
|
|
238
238
|
storageFormat: 'decimal',
|
|
239
239
|
defaultCurrency: 'EUR',
|
|
240
240
|
decimalPlaces: 2,
|
|
241
241
|
}
|
|
242
|
-
const semantic =
|
|
242
|
+
const semantic = createCurrencySemantic(config)
|
|
243
243
|
assert.equal(semantic.config?.defaultCurrency, 'EUR')
|
|
244
244
|
assert.isUndefined(semantic.config?.allowedCurrencies)
|
|
245
245
|
})
|
|
246
246
|
|
|
247
247
|
test('should support multiple currencies with allowedCurrencies', ({ assert }) => {
|
|
248
248
|
const currencies = ['USD', 'EUR', 'GBP', 'JPY', 'CAD', 'AUD']
|
|
249
|
-
const config:
|
|
249
|
+
const config: CurrencyConfig = {
|
|
250
250
|
storageFormat: 'complex_object',
|
|
251
251
|
allowedCurrencies: currencies,
|
|
252
252
|
decimalPlaces: 2,
|
|
253
253
|
}
|
|
254
|
-
const semantic =
|
|
254
|
+
const semantic = createCurrencySemantic(config)
|
|
255
255
|
assert.deepEqual(semantic.config?.allowedCurrencies, currencies)
|
|
256
256
|
})
|
|
257
257
|
|
|
258
258
|
test('should support currency validation toggle', ({ assert }) => {
|
|
259
|
-
const configWithValidation:
|
|
259
|
+
const configWithValidation: CurrencyConfig = {
|
|
260
260
|
storageFormat: 'decimal',
|
|
261
261
|
defaultCurrency: 'USD',
|
|
262
262
|
validateCurrencyCode: true,
|
|
263
263
|
}
|
|
264
|
-
const configWithoutValidation:
|
|
264
|
+
const configWithoutValidation: CurrencyConfig = {
|
|
265
265
|
storageFormat: 'decimal',
|
|
266
266
|
defaultCurrency: 'USD',
|
|
267
267
|
validateCurrencyCode: false,
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
const semanticWithValidation =
|
|
271
|
-
const semanticWithoutValidation =
|
|
270
|
+
const semanticWithValidation = createCurrencySemantic(configWithValidation)
|
|
271
|
+
const semanticWithoutValidation = createCurrencySemantic(configWithoutValidation)
|
|
272
272
|
|
|
273
273
|
assert.isTrue(semanticWithValidation.config?.validateCurrencyCode)
|
|
274
274
|
assert.isFalse(semanticWithoutValidation.config?.validateCurrencyCode)
|
|
275
275
|
})
|
|
276
276
|
})
|
|
277
277
|
|
|
278
|
-
test.group('
|
|
278
|
+
test.group('Currency Precision Configuration', () => {
|
|
279
279
|
test('should support standard 2 decimal places (USD, EUR)', ({ assert }) => {
|
|
280
|
-
const config:
|
|
280
|
+
const config: CurrencyConfig = {
|
|
281
281
|
storageFormat: 'decimal',
|
|
282
282
|
defaultCurrency: 'USD',
|
|
283
283
|
decimalPlaces: 2,
|
|
284
284
|
}
|
|
285
|
-
const semantic =
|
|
285
|
+
const semantic = createCurrencySemantic(config)
|
|
286
286
|
assert.equal(semantic.config?.decimalPlaces, 2)
|
|
287
287
|
})
|
|
288
288
|
|
|
289
289
|
test('should support zero decimal places (JPY, KRW)', ({ assert }) => {
|
|
290
|
-
const config:
|
|
290
|
+
const config: CurrencyConfig = {
|
|
291
291
|
storageFormat: 'decimal',
|
|
292
292
|
defaultCurrency: 'JPY',
|
|
293
293
|
decimalPlaces: 0,
|
|
294
294
|
}
|
|
295
|
-
const semantic =
|
|
295
|
+
const semantic = createCurrencySemantic(config)
|
|
296
296
|
assert.equal(semantic.config?.decimalPlaces, 0)
|
|
297
297
|
})
|
|
298
298
|
|
|
299
299
|
test('should support high precision (3 decimal places for BHD, KWD)', ({ assert }) => {
|
|
300
|
-
const config:
|
|
300
|
+
const config: CurrencyConfig = {
|
|
301
301
|
storageFormat: 'decimal',
|
|
302
302
|
defaultCurrency: 'BHD',
|
|
303
303
|
decimalPlaces: 3,
|
|
304
304
|
}
|
|
305
|
-
const semantic =
|
|
305
|
+
const semantic = createCurrencySemantic(config)
|
|
306
306
|
assert.equal(semantic.config?.decimalPlaces, 3)
|
|
307
307
|
})
|
|
308
308
|
|
|
309
309
|
test('should support very high precision (cryptocurrencies)', ({ assert }) => {
|
|
310
|
-
const config:
|
|
310
|
+
const config: CurrencyConfig = {
|
|
311
311
|
storageFormat: 'decimal',
|
|
312
312
|
defaultCurrency: 'BTC',
|
|
313
313
|
decimalPlaces: 8,
|
|
314
314
|
}
|
|
315
|
-
const semantic =
|
|
315
|
+
const semantic = createCurrencySemantic(config)
|
|
316
316
|
assert.equal(semantic.config?.decimalPlaces, 8)
|
|
317
317
|
})
|
|
318
318
|
})
|
|
319
319
|
|
|
320
|
-
test.group('
|
|
320
|
+
test.group('Currency Negative Values Configuration', () => {
|
|
321
321
|
test('should support disallowing negative values (default)', ({ assert }) => {
|
|
322
|
-
const config:
|
|
322
|
+
const config: CurrencyConfig = {
|
|
323
323
|
storageFormat: 'decimal',
|
|
324
324
|
defaultCurrency: 'USD',
|
|
325
325
|
allowNegative: false,
|
|
326
326
|
}
|
|
327
|
-
const semantic =
|
|
327
|
+
const semantic = createCurrencySemantic(config)
|
|
328
328
|
assert.isFalse(semantic.config?.allowNegative)
|
|
329
329
|
})
|
|
330
330
|
|
|
331
331
|
test('should support allowing negative values (refunds, discounts)', ({ assert }) => {
|
|
332
|
-
const config:
|
|
332
|
+
const config: CurrencyConfig = {
|
|
333
333
|
storageFormat: 'decimal',
|
|
334
334
|
defaultCurrency: 'USD',
|
|
335
335
|
allowNegative: true,
|
|
336
336
|
}
|
|
337
|
-
const semantic =
|
|
337
|
+
const semantic = createCurrencySemantic(config)
|
|
338
338
|
assert.isTrue(semantic.config?.allowNegative)
|
|
339
339
|
})
|
|
340
340
|
})
|
|
341
341
|
|
|
342
|
-
test.group('
|
|
342
|
+
test.group('Currency Metadata Configuration', () => {
|
|
343
343
|
test('should support custom metadata', ({ assert }) => {
|
|
344
344
|
const metadata = {
|
|
345
345
|
displayFormat: 'currency',
|
|
@@ -347,17 +347,17 @@ test.group('Price Metadata Configuration', () => {
|
|
|
347
347
|
rounding: 'standard',
|
|
348
348
|
customField: 'value',
|
|
349
349
|
}
|
|
350
|
-
const config:
|
|
350
|
+
const config: CurrencyConfig = {
|
|
351
351
|
storageFormat: 'decimal',
|
|
352
352
|
defaultCurrency: 'USD',
|
|
353
353
|
metadata,
|
|
354
354
|
}
|
|
355
|
-
const semantic =
|
|
355
|
+
const semantic = createCurrencySemantic(config)
|
|
356
356
|
assert.deepEqual(semantic.config?.metadata, metadata)
|
|
357
357
|
})
|
|
358
358
|
|
|
359
359
|
test('should merge metadata with other config', ({ assert }) => {
|
|
360
|
-
const config:
|
|
360
|
+
const config: CurrencyConfig = {
|
|
361
361
|
storageFormat: 'complex_object',
|
|
362
362
|
allowedCurrencies: ['USD', 'EUR'],
|
|
363
363
|
decimalPlaces: 2,
|
|
@@ -366,7 +366,7 @@ test.group('Price Metadata Configuration', () => {
|
|
|
366
366
|
lastUpdated: '2023-01-01',
|
|
367
367
|
},
|
|
368
368
|
}
|
|
369
|
-
const semantic =
|
|
369
|
+
const semantic = createCurrencySemantic(config)
|
|
370
370
|
assert.equal(semantic.config?.storageFormat, 'complex_object')
|
|
371
371
|
assert.deepEqual(semantic.config?.allowedCurrencies, ['USD', 'EUR'])
|
|
372
372
|
assert.equal(semantic.config?.decimalPlaces, 2)
|
|
@@ -377,34 +377,34 @@ test.group('Price Metadata Configuration', () => {
|
|
|
377
377
|
})
|
|
378
378
|
})
|
|
379
379
|
|
|
380
|
-
test.group('
|
|
380
|
+
test.group('Currency Cross-semantic Type Guards', () => {
|
|
381
381
|
test('should correctly identify different semantic types', ({ assert }) => {
|
|
382
|
-
const
|
|
382
|
+
const currencySemantic = createCurrencySemantic()
|
|
383
383
|
|
|
384
384
|
// Mock other semantics for comparison
|
|
385
385
|
const emailSemantic: AppliedDataSemantic = { id: SemanticType.Email }
|
|
386
386
|
const statusSemantic: AppliedDataSemantic = { id: SemanticType.Status }
|
|
387
387
|
const userSemantic: AppliedDataSemantic = { id: SemanticType.User }
|
|
388
388
|
|
|
389
|
-
//
|
|
390
|
-
assert.isTrue(
|
|
391
|
-
assert.isFalse(
|
|
392
|
-
assert.isFalse(
|
|
393
|
-
assert.isFalse(
|
|
389
|
+
// Currency semantic should only be identified as Currency
|
|
390
|
+
assert.isTrue(isCurrencySemantic(currencySemantic))
|
|
391
|
+
assert.isFalse(isCurrencySemantic(emailSemantic))
|
|
392
|
+
assert.isFalse(isCurrencySemantic(statusSemantic))
|
|
393
|
+
assert.isFalse(isCurrencySemantic(userSemantic))
|
|
394
394
|
})
|
|
395
395
|
})
|
|
396
396
|
|
|
397
|
-
test.group('
|
|
397
|
+
test.group('Currency Real-world Use Cases', () => {
|
|
398
398
|
test('should configure for simple e-commerce store', ({ assert }) => {
|
|
399
|
-
const config:
|
|
399
|
+
const config: CurrencyConfig = {
|
|
400
400
|
storageFormat: 'decimal',
|
|
401
401
|
defaultCurrency: 'USD',
|
|
402
402
|
decimalPlaces: 2,
|
|
403
403
|
allowNegative: false,
|
|
404
404
|
validateCurrencyCode: true,
|
|
405
405
|
}
|
|
406
|
-
const semantic =
|
|
407
|
-
const errors =
|
|
406
|
+
const semantic = createCurrencySemantic(config)
|
|
407
|
+
const errors = validateCurrencyConfig(config)
|
|
408
408
|
|
|
409
409
|
assert.lengthOf(errors, 0)
|
|
410
410
|
assert.equal(semantic.config?.storageFormat, 'decimal')
|
|
@@ -413,15 +413,15 @@ test.group('Price Real-world Use Cases', () => {
|
|
|
413
413
|
})
|
|
414
414
|
|
|
415
415
|
test('should configure for international marketplace', ({ assert }) => {
|
|
416
|
-
const config:
|
|
416
|
+
const config: CurrencyConfig = {
|
|
417
417
|
storageFormat: 'complex_object',
|
|
418
418
|
allowedCurrencies: ['USD', 'EUR', 'GBP', 'JPY', 'CAD', 'AUD'],
|
|
419
419
|
decimalPlaces: 2,
|
|
420
420
|
allowNegative: false,
|
|
421
421
|
validateCurrencyCode: true,
|
|
422
422
|
}
|
|
423
|
-
const semantic =
|
|
424
|
-
const errors =
|
|
423
|
+
const semantic = createCurrencySemantic(config)
|
|
424
|
+
const errors = validateCurrencyConfig(config)
|
|
425
425
|
|
|
426
426
|
assert.lengthOf(errors, 0)
|
|
427
427
|
assert.equal(semantic.config?.storageFormat, 'complex_object')
|
|
@@ -430,15 +430,15 @@ test.group('Price Real-world Use Cases', () => {
|
|
|
430
430
|
})
|
|
431
431
|
|
|
432
432
|
test('should configure for financial system with precision', ({ assert }) => {
|
|
433
|
-
const config:
|
|
433
|
+
const config: CurrencyConfig = {
|
|
434
434
|
storageFormat: 'integer_cents',
|
|
435
435
|
defaultCurrency: 'USD',
|
|
436
436
|
decimalPlaces: 4,
|
|
437
437
|
allowNegative: true,
|
|
438
438
|
validateCurrencyCode: true,
|
|
439
439
|
}
|
|
440
|
-
const semantic =
|
|
441
|
-
const errors =
|
|
440
|
+
const semantic = createCurrencySemantic(config)
|
|
441
|
+
const errors = validateCurrencyConfig(config)
|
|
442
442
|
|
|
443
443
|
assert.lengthOf(errors, 0)
|
|
444
444
|
assert.equal(semantic.config?.storageFormat, 'integer_cents')
|
|
@@ -447,15 +447,15 @@ test.group('Price Real-world Use Cases', () => {
|
|
|
447
447
|
})
|
|
448
448
|
|
|
449
449
|
test('should configure for cryptocurrency trading', ({ assert }) => {
|
|
450
|
-
const config:
|
|
450
|
+
const config: CurrencyConfig = {
|
|
451
451
|
storageFormat: 'decimal',
|
|
452
452
|
defaultCurrency: 'BTC',
|
|
453
453
|
decimalPlaces: 8,
|
|
454
454
|
allowNegative: false,
|
|
455
455
|
validateCurrencyCode: false, // Custom crypto currency
|
|
456
456
|
}
|
|
457
|
-
const semantic =
|
|
458
|
-
const errors =
|
|
457
|
+
const semantic = createCurrencySemantic(config)
|
|
458
|
+
const errors = validateCurrencyConfig(config)
|
|
459
459
|
|
|
460
460
|
assert.lengthOf(errors, 0)
|
|
461
461
|
assert.equal(semantic.config?.defaultCurrency, 'BTC')
|
|
@@ -16,8 +16,6 @@ test.group('Description Semantic Configuration', () => {
|
|
|
16
16
|
|
|
17
17
|
test('should create semantic with custom config', ({ assert }) => {
|
|
18
18
|
const config: DescriptionConfig = {
|
|
19
|
-
minLength: 10,
|
|
20
|
-
maxLength: 1000,
|
|
21
19
|
allowMarkdown: true,
|
|
22
20
|
}
|
|
23
21
|
const semantic = createDescriptionSemantic(config)
|