buckets/frontend/src/lib/iri.test.ts

25 lines
912 B
TypeScript

import { describe, expect, it } from 'vitest'
import { iriToId } from './iri'
describe('iriToId', () => {
it('extracts the trailing uuid from an API Platform IRI', () => {
expect(iriToId('/api/scenarios/11111111-1111-1111-1111-111111111111')).toBe(
'11111111-1111-1111-1111-111111111111',
)
})
it('works for any resource IRI, not just scenarios', () => {
expect(iriToId('/api/buckets/abc-123')).toBe('abc-123')
})
it('returns the whole string when there is no slash', () => {
expect(iriToId('bare-id')).toBe('bare-id')
})
// Pinned as a known boundary: a trailing-slash IRI yields an empty id. The
// API never emits one (API Platform IRIs always end in the resource id), so
// this documents the limitation rather than guarding a reachable case.
it('returns an empty string for a trailing-slash IRI', () => {
expect(iriToId('/api/scenarios/')).toBe('')
})
})