Skip to content

Commit 659ae08

Browse files
committed
test: update test data to use branded type constructors
**Test Data Standardization:** - Replace direct string assignments with proper branded type constructors - Use createModelName() for all Claude model references in tests - Use createActivityDate() for lastActivity fields (YYYY-MM-DD format) - Use createDailyDate(), createSessionId(), createProjectPath() in test scenarios **Type Safety in Tests:** - Ensure all test data validates through branded type schemas - Update test expectations to work with branded types - Maintain test coverage while enforcing type constraints **Model Updates:** - Update test models to use current Claude 4 naming (claude-sonnet-4-20250514, claude-opus-4-20250514) - Ensure backward compatibility testing with various model name formats This ensures tests validate the same type constraints as production code.
1 parent 44f5d66 commit 659ae08

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

‎src/calculate-cost.ts‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
import type { DailyUsage, MonthlyUsage, SessionUsage } from './data-loader.ts';
2+
import {
3+
createActivityDate,
4+
createDailyDate,
5+
createModelName,
6+
createProjectPath,
7+
createSessionId,
8+
createVersion,
9+
} from './types.internal.ts';
210

311
/**
412
* Token usage data structure containing input, output, and cache token counts
@@ -85,23 +93,23 @@ if (import.meta.vitest != null) {
8593
it('calculateTotals should aggregate daily usage data', () => {
8694
const dailyData: DailyUsage[] = [
8795
{
88-
date: '2024-01-01',
96+
date: createDailyDate('2024-01-01'),
8997
inputTokens: 100,
9098
outputTokens: 50,
9199
cacheCreationTokens: 25,
92100
cacheReadTokens: 10,
93101
totalCost: 0.01,
94-
modelsUsed: ['claude-sonnet-4-20250514'],
102+
modelsUsed: [createModelName('claude-sonnet-4-20250514')],
95103
modelBreakdowns: [],
96104
},
97105
{
98-
date: '2024-01-02',
106+
date: createDailyDate('2024-01-02'),
99107
inputTokens: 200,
100108
outputTokens: 100,
101109
cacheCreationTokens: 50,
102110
cacheReadTokens: 20,
103111
totalCost: 0.02,
104-
modelsUsed: ['claude-opus-4-20250514'],
112+
modelsUsed: [createModelName('claude-opus-4-20250514')],
105113
modelBreakdowns: [],
106114
},
107115
];
@@ -117,29 +125,29 @@ if (import.meta.vitest != null) {
117125
it('calculateTotals should aggregate session usage data', () => {
118126
const sessionData: SessionUsage[] = [
119127
{
120-
sessionId: 'session-1',
121-
projectPath: 'project/path',
128+
sessionId: createSessionId('session-1'),
129+
projectPath: createProjectPath('project/path'),
122130
inputTokens: 100,
123131
outputTokens: 50,
124132
cacheCreationTokens: 25,
125133
cacheReadTokens: 10,
126134
totalCost: 0.01,
127-
lastActivity: '2024-01-01',
128-
versions: ['1.0.3'],
129-
modelsUsed: ['claude-sonnet-4-20250514'],
135+
lastActivity: createActivityDate('2024-01-01'),
136+
versions: [createVersion('1.0.3')],
137+
modelsUsed: [createModelName('claude-sonnet-4-20250514')],
130138
modelBreakdowns: [],
131139
},
132140
{
133-
sessionId: 'session-2',
134-
projectPath: 'project/path',
141+
sessionId: createSessionId('session-2'),
142+
projectPath: createProjectPath('project/path'),
135143
inputTokens: 200,
136144
outputTokens: 100,
137145
cacheCreationTokens: 50,
138146
cacheReadTokens: 20,
139147
totalCost: 0.02,
140-
lastActivity: '2024-01-02',
141-
versions: ['1.0.3', '1.0.4'],
142-
modelsUsed: ['claude-opus-4-20250514'],
148+
lastActivity: createActivityDate('2024-01-02'),
149+
versions: [createVersion('1.0.3'), createVersion('1.0.4')],
150+
modelsUsed: [createModelName('claude-opus-4-20250514')],
143151
modelBreakdowns: [],
144152
},
145153
];

0 commit comments

Comments
 (0)