Skip to content

Commit 80b98fb

Browse files
committed
test(service-analytics): a measure currency over a fixed field may only restate its code — the two chain pins move to the dynamic field
Claude-Session: https://claude.ai/code/session_01Utp6Ca8jzC2P7EAQvqjNBb Co-authored-by: Claude <noreply@anthropic.com>
1 parent 699ed05 commit 80b98fb

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

‎packages/services/service-analytics/src/__tests__/currency-mode-relay.test.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ const DATASET = DatasetSchema.parse({
9898
{ name: 'm_nomode', aggregate: 'sum', field: 'amt_nomode' },
9999
{ name: 'm_emptycfg', aggregate: 'sum', field: 'amt_emptycfg' },
100100
{ name: 'm_bare', aggregate: 'sum', field: 'amt_bare' },
101-
// An explicit measure `currency` wins over every field-side answer,
102-
// the field's FIXED currency included.
101+
// An explicit measure `currency` wins over a dynamic field's tenant
102+
// default. [ADR-0144 M0-3] Over a FIXED field it may only restate the
103+
// field's code: a contradicting one is refused at compile
104+
// (`measure-currency-coherence.ts`, record-currency-analytics.test.ts).
103105
{ name: 'm_explicit_dynamic', aggregate: 'sum', field: 'amt_dynamic', currency: 'JPY' },
104-
{ name: 'm_explicit_fixed', aggregate: 'sum', field: 'amt_fixed', currency: 'JPY' },
106+
{ name: 'm_explicit_fixed', aggregate: 'sum', field: 'amt_fixed', currency: 'EUR' },
105107
{ name: 'm_units', aggregate: 'sum', field: 'units' },
106108
],
107109
});
@@ -220,11 +222,11 @@ describe.each<Shape>(['raw', 'parsed'])('[#20091] result-column currency honours
220222
expect(preview.m_bare).toBe('USD');
221223
});
222224

223-
it('an explicit measure currency wins, over a dynamic field and over a fixed one', () => {
225+
it("an explicit measure currency wins over a dynamic field, and restates a fixed one's code", () => {
224226
expect(live.m_explicit_dynamic).toBe('JPY');
225227
expect(preview.m_explicit_dynamic).toBe('JPY');
226-
expect(live.m_explicit_fixed).toBe('JPY');
227-
expect(preview.m_explicit_fixed).toBe('JPY');
228+
expect(live.m_explicit_fixed).toBe('EUR');
229+
expect(preview.m_explicit_fixed).toBe('EUR');
228230
});
229231

230232
it('CONTROL: a non-monetary measure carries no currency', () => {

‎packages/services/service-analytics/src/__tests__/query-dataset.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,11 @@ describe('AnalyticsService.queryDataset', () => {
153153
expect(r.fields.find((f: any) => f.name === 'revenue')?.currency).toBe('GBP');
154154
});
155155

156-
it('chain: an explicit measure currency wins over the field default and the tenant ctx', async () => {
157-
const svc = pricedSvc([{ stage: 'Won', revenue: 1000 }], (_o, f) => f === 'amount' ? { type: 'currency', defaultCurrency: 'EUR' } : undefined);
156+
// [ADR-0144 M0-3] Over a FIXED field a measure currency may only restate the
157+
// field's code — a contradicting one is refused at compile
158+
// (`measure-currency-coherence.ts`, pinned in record-currency-analytics.test.ts).
159+
it('chain: an explicit measure currency wins over the tenant ctx on a dynamic field', async () => {
160+
const svc = pricedSvc([{ stage: 'Won', revenue: 1000 }], (_o, f) => f === 'amount' ? { type: 'currency' } : undefined);
158161
const r = await svc.queryDataset(moneyDataset({ currency: 'JPY' }), { dimensions: ['stage'], measures: ['revenue'] }, { tenantId: 'o', currency: 'GBP' } as ExecutionContext) as any;
159162
expect(r.fields.find((f: any) => f.name === 'revenue')?.currency).toBe('JPY');
160163
});

0 commit comments

Comments
 (0)