test(8.0): get() resolves null for absent custom ids instead of throwing
Follow-up to accepting application-supplied ids (36b7216): get('not-a-uuid')
and long ids are now valid lookups that miss → null, not "Invalid UUID format"
throws. Empty / null / undefined still throw (structurally invalid input).
Aligns the unit suite with the accept-any-id behaviour; the v5.1.0 "stricter
UUID validation" rule these cases encoded is superseded.
This commit is contained in:
parent
36b7216929
commit
dc94af3a6a
1 changed files with 11 additions and 14 deletions
|
|
@ -159,19 +159,18 @@ describe('Brainy.get()', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle invalid ID formats gracefully', async () => {
|
it('should handle invalid ID formats gracefully', async () => {
|
||||||
// v5.1.0: Invalid formats now throw errors instead of returning null
|
// 8.0: any non-empty string is a valid custom id (sharding hashes it), so
|
||||||
const invalidIds = [
|
// a lookup that misses resolves to null — there is no "invalid format".
|
||||||
'', // Empty string
|
const missingIds = [
|
||||||
'not-a-uuid', // Invalid format
|
'not-a-uuid', // valid custom id, simply absent
|
||||||
'12345', // Too short
|
'12345' // valid custom id, simply absent
|
||||||
]
|
]
|
||||||
|
for (const id of missingIds) {
|
||||||
// Act & Assert - expect errors for invalid formats
|
await expect(brain.get(id)).resolves.toBeNull()
|
||||||
for (const invalidId of invalidIds) {
|
|
||||||
await expect(brain.get(invalidId)).rejects.toThrow()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Null/undefined should also throw
|
// Structurally-invalid input (empty / null / undefined) still throws.
|
||||||
|
await expect(brain.get('')).rejects.toThrow()
|
||||||
await expect(brain.get(null as any)).rejects.toThrow()
|
await expect(brain.get(null as any)).rejects.toThrow()
|
||||||
await expect(brain.get(undefined as any)).rejects.toThrow()
|
await expect(brain.get(undefined as any)).rejects.toThrow()
|
||||||
})
|
})
|
||||||
|
|
@ -215,11 +214,9 @@ describe('Brainy.get()', () => {
|
||||||
|
|
||||||
describe('edge cases', () => {
|
describe('edge cases', () => {
|
||||||
it('should handle very long IDs', async () => {
|
it('should handle very long IDs', async () => {
|
||||||
// v5.1.0: Stricter UUID validation - invalid IDs throw errors
|
// 8.0: a long string is a valid custom id; a miss resolves to null.
|
||||||
const longId = 'x'.repeat(1000)
|
const longId = 'x'.repeat(1000)
|
||||||
|
await expect(brain.get(longId)).resolves.toBeNull()
|
||||||
// Expect error for invalid UUID format
|
|
||||||
await expect(brain.get(longId)).rejects.toThrow('Invalid UUID format')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle special characters in IDs', async () => {
|
it('should handle special characters in IDs', async () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue