diff --git a/src/routes/stats/npm/-utils.ts b/src/routes/stats/npm/-utils.ts index 1f31d27e0..1603e22f9 100644 --- a/src/routes/stats/npm/-utils.ts +++ b/src/routes/stats/npm/-utils.ts @@ -1,13 +1,8 @@ import * as v from 'valibot' import { MAX_NPM_STATS_GROUPS } from '~/utils/npm-stats-limits' -// Re-export shared types from chart utils -export { - binTypeSchema, - type BinType, - binningOptions, - getBinFunction, -} from '~/utils/chart' +// Re-export shared types and schema without importing chart utilities. +export { binTypeSchema, type BinType } from '~/components/npm-stats/shared' export { chartTypeSchema, type ChartType, diff --git a/tests/chart-route-validation.test.ts b/tests/chart-route-validation.test.ts new file mode 100644 index 000000000..927049730 --- /dev/null +++ b/tests/chart-route-validation.test.ts @@ -0,0 +1,27 @@ +/// + +import assert from 'node:assert/strict' +import test from 'node:test' +import { Route } from '../src/routes/stats/npm/$packages' + +const schema = Route.options.validateSearch +assert.ok(schema && typeof schema === 'object' && '~standard' in schema) +const standardSchema = schema['~standard'] + +test('npm comparison route preserves binType search validation', async () => { + const defaultResult = await standardSchema.validate({}) + assert.equal(defaultResult.issues, undefined) + assert.equal(defaultResult.value.binType, 'weekly') + + for (const binType of ['yearly', 'monthly', 'weekly', 'daily']) { + const result = await standardSchema.validate({ binType }) + assert.equal(result.issues, undefined) + assert.equal(result.value.binType, binType) + } +}) + +test('npm comparison route defaults invalid binType search values', async () => { + const result = await standardSchema.validate({ binType: 'hourly' }) + assert.equal(result.issues, undefined) + assert.equal(result.value.binType, 'weekly') +})