- Updated API to support structured list entry inputs, allowing for nested list references. - Improved error handling for list operations to prevent cyclic references. - Refactored UI components to ensure consistent labeling and navigation for IP lists. - Enhanced list detail and catalog pages with better filtering and entry management features. Co-authored-by: Cursor <[email protected]>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
listEntriesBodySchema,
|
|
listEntryKindSchema,
|
|
listNestedChildIds,
|
|
parseListEntry,
|
|
} from '../src/list-entries.js'
|
|
|
|
describe('list entry kinds', () => {
|
|
it('includes list kind', () => {
|
|
expect(listEntryKindSchema.parse('list')).toBe('list')
|
|
})
|
|
|
|
it('parses ip/cidr/hostname but not list ids from plaintext', () => {
|
|
expect(parseListEntry('8.8.8.8').kind).toBe('ip')
|
|
expect(parseListEntry('10.0.0.0/8').kind).toBe('cidr')
|
|
expect(parseListEntry('bad.example.com').kind).toBe('hostname')
|
|
expect(() => parseListEntry('not-a-valid-token')).toThrow()
|
|
})
|
|
|
|
it('accepts values or items in body', () => {
|
|
expect(
|
|
listEntriesBodySchema.parse({ values: ['8.8.8.8'] }).values,
|
|
).toEqual(['8.8.8.8'])
|
|
expect(
|
|
listEntriesBodySchema.parse({
|
|
items: [{ kind: 'list', value: 'abc' }],
|
|
}).items,
|
|
).toEqual([{ kind: 'list', value: 'abc' }])
|
|
expect(() => listEntriesBodySchema.parse({})).toThrow()
|
|
})
|
|
|
|
it('reads nested child ids from config', () => {
|
|
const ids = listNestedChildIds(
|
|
JSON.stringify({
|
|
items: [
|
|
{ kind: 'ip', value: '1.1.1.1' },
|
|
{ kind: 'list', value: 'child-1' },
|
|
{ kind: 'list', value: 'child-2' },
|
|
],
|
|
}),
|
|
)
|
|
expect(ids).toEqual(['child-1', 'child-2'])
|
|
})
|
|
})
|