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 () => {
|
||||
// v5.1.0: Invalid formats now throw errors instead of returning null
|
||||
const invalidIds = [
|
||||
'', // Empty string
|
||||
'not-a-uuid', // Invalid format
|
||||
'12345', // Too short
|
||||
// 8.0: any non-empty string is a valid custom id (sharding hashes it), so
|
||||
// a lookup that misses resolves to null — there is no "invalid format".
|
||||
const missingIds = [
|
||||
'not-a-uuid', // valid custom id, simply absent
|
||||
'12345' // valid custom id, simply absent
|
||||
]
|
||||
|
||||
// Act & Assert - expect errors for invalid formats
|
||||
for (const invalidId of invalidIds) {
|
||||
await expect(brain.get(invalidId)).rejects.toThrow()
|
||||
for (const id of missingIds) {
|
||||
await expect(brain.get(id)).resolves.toBeNull()
|
||||
}
|
||||
|
||||
// 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(undefined as any)).rejects.toThrow()
|
||||
})
|
||||
|
|
@ -215,11 +214,9 @@ describe('Brainy.get()', () => {
|
|||
|
||||
describe('edge cases', () => {
|
||||
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)
|
||||
|
||||
// Expect error for invalid UUID format
|
||||
await expect(brain.get(longId)).rejects.toThrow('Invalid UUID format')
|
||||
await expect(brain.get(longId)).resolves.toBeNull()
|
||||
})
|
||||
|
||||
it('should handle special characters in IDs', async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue