d25d482dc2
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
146 lines
4.8 KiB
TypeScript
146 lines
4.8 KiB
TypeScript
/**
|
|
* @vitest-environment node
|
|
*/
|
|
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
listKnowledgeDocumentsQuerySchema,
|
|
parseDocumentTagFiltersParam,
|
|
} from '@/lib/api/contracts/knowledge/documents'
|
|
|
|
describe('listKnowledgeDocumentsQuerySchema.tagFilters', () => {
|
|
it('keeps tagFilters a raw string (must NOT transform to an array)', () => {
|
|
// A transform-to-array here breaks requestJson outbound serialization
|
|
// (the array serializes as "[object Object]"). The wire type must stay a
|
|
// string; decoding happens server-side via parseDocumentTagFiltersParam.
|
|
const tagFilters = JSON.stringify([
|
|
{ tagSlot: 'tag1', fieldType: 'text', operator: 'contains', value: 'x' },
|
|
])
|
|
const parsed = listKnowledgeDocumentsQuerySchema.parse({ tagFilters })
|
|
expect(parsed.tagFilters).toBe(tagFilters)
|
|
expect(typeof parsed.tagFilters).toBe('string')
|
|
})
|
|
})
|
|
|
|
describe('parseDocumentTagFiltersParam', () => {
|
|
it('returns undefined for an absent param', () => {
|
|
expect(parseDocumentTagFiltersParam(undefined)).toBeUndefined()
|
|
expect(parseDocumentTagFiltersParam('')).toBeUndefined()
|
|
})
|
|
|
|
it('decodes a valid JSON array of filters', () => {
|
|
const filters = [
|
|
{ tagSlot: 'tag1', fieldType: 'text', operator: 'contains', value: 'x' },
|
|
{ tagSlot: 'date1', fieldType: 'date', operator: 'eq', value: '2026-04-21' },
|
|
]
|
|
expect(parseDocumentTagFiltersParam(JSON.stringify(filters))).toEqual(filters)
|
|
})
|
|
|
|
it('throws on malformed JSON', () => {
|
|
expect(() => parseDocumentTagFiltersParam('[object Object]')).toThrow()
|
|
expect(() => parseDocumentTagFiltersParam('{not json')).toThrow()
|
|
})
|
|
|
|
it('throws when the shape is wrong', () => {
|
|
expect(() => parseDocumentTagFiltersParam(JSON.stringify([{ tagSlot: '' }]))).toThrow()
|
|
})
|
|
|
|
it('rejects an operator that is not valid for the field type', () => {
|
|
// unknown operator
|
|
expect(() =>
|
|
parseDocumentTagFiltersParam(
|
|
JSON.stringify([{ tagSlot: 'tag1', fieldType: 'text', operator: 'bogus', value: 'x' }])
|
|
)
|
|
).toThrow()
|
|
// valid operator name, wrong field type (contains is text-only)
|
|
expect(() =>
|
|
parseDocumentTagFiltersParam(
|
|
JSON.stringify([
|
|
{ tagSlot: 'number1', fieldType: 'number', operator: 'contains', value: '1' },
|
|
])
|
|
)
|
|
).toThrow()
|
|
})
|
|
|
|
it('rejects a fieldType that does not match the tag slot', () => {
|
|
// number1 is a numeric column; claiming it is text must fail
|
|
expect(() =>
|
|
parseDocumentTagFiltersParam(
|
|
JSON.stringify([
|
|
{ tagSlot: 'number1', fieldType: 'text', operator: 'contains', value: 'x' },
|
|
])
|
|
)
|
|
).toThrow()
|
|
})
|
|
|
|
it('rejects an unknown tag slot', () => {
|
|
expect(() =>
|
|
parseDocumentTagFiltersParam(
|
|
JSON.stringify([{ tagSlot: 'tag99', fieldType: 'text', operator: 'eq', value: 'x' }])
|
|
)
|
|
).toThrow()
|
|
})
|
|
|
|
it('rejects values that are unusable for the field type', () => {
|
|
// non-numeric value on a number field
|
|
expect(() =>
|
|
parseDocumentTagFiltersParam(
|
|
JSON.stringify([{ tagSlot: 'number1', fieldType: 'number', operator: 'eq', value: 'abc' }])
|
|
)
|
|
).toThrow()
|
|
// non-date value on a date field
|
|
expect(() =>
|
|
parseDocumentTagFiltersParam(
|
|
JSON.stringify([{ tagSlot: 'date1', fieldType: 'date', operator: 'eq', value: 'nope' }])
|
|
)
|
|
).toThrow()
|
|
// well-formed but impossible calendar dates (would 500 on ::date)
|
|
for (const value of ['2026-02-30', '2026-99-99', '2026-13-01', '2026-00-10']) {
|
|
expect(() =>
|
|
parseDocumentTagFiltersParam(
|
|
JSON.stringify([{ tagSlot: 'date1', fieldType: 'date', operator: 'eq', value }])
|
|
)
|
|
).toThrow()
|
|
}
|
|
// non-boolean value on a boolean field
|
|
expect(() =>
|
|
parseDocumentTagFiltersParam(
|
|
JSON.stringify([
|
|
{ tagSlot: 'boolean1', fieldType: 'boolean', operator: 'eq', value: 'maybe' },
|
|
])
|
|
)
|
|
).toThrow()
|
|
})
|
|
|
|
it('rejects a between filter missing a usable upper bound', () => {
|
|
expect(() =>
|
|
parseDocumentTagFiltersParam(
|
|
JSON.stringify([
|
|
{
|
|
tagSlot: 'number1',
|
|
fieldType: 'number',
|
|
operator: 'between',
|
|
value: '1',
|
|
valueTo: 'x',
|
|
},
|
|
])
|
|
)
|
|
).toThrow()
|
|
})
|
|
|
|
it('accepts a valid number, date, boolean, and between filter', () => {
|
|
const filters = [
|
|
{ tagSlot: 'number1', fieldType: 'number', operator: 'gte', value: '42' },
|
|
{ tagSlot: 'date1', fieldType: 'date', operator: 'eq', value: '2026-04-21' },
|
|
{ tagSlot: 'boolean1', fieldType: 'boolean', operator: 'eq', value: 'true' },
|
|
{
|
|
tagSlot: 'number2',
|
|
fieldType: 'number',
|
|
operator: 'between',
|
|
value: '1',
|
|
valueTo: '10',
|
|
},
|
|
]
|
|
expect(parseDocumentTagFiltersParam(JSON.stringify(filters))).toEqual(filters)
|
|
})
|
|
})
|