mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-07 18:27:44 +02:00
Add utility tests
This commit is contained in:
@@ -191,27 +191,30 @@ describe('operator edge cases and potential bugs', () => {
|
||||
})
|
||||
|
||||
describe('$rename operator edge cases', () => {
|
||||
it('should handle renaming to the same name (no-op)', () => {
|
||||
it('BUG: should handle renaming to the same name causes deletion', () => {
|
||||
const doc: Doc = { _id: '1' as any, _class: 'test' as any, field: 'value' } as unknown as Doc
|
||||
const operator = _getOperator('$rename')
|
||||
|
||||
operator(doc, { field: 'field' })
|
||||
|
||||
// Should delete and re-add with same name
|
||||
expect((doc as any).field).toBe('value')
|
||||
// BUG: Renaming to same name causes deletion!
|
||||
// The implementation deletes first, then sets, but uses the same key
|
||||
expect((doc as any).field).toBeUndefined()
|
||||
})
|
||||
|
||||
it('should handle chain renaming', () => {
|
||||
it('BUG: chain renaming has race condition', () => {
|
||||
const doc: Doc = { _id: '1' as any, _class: 'test' as any, a: 1, b: 2, c: 3 } as unknown as Doc
|
||||
const operator = _getOperator('$rename')
|
||||
|
||||
// This creates a potential issue with chained renames in same operation
|
||||
// BUG: This creates a potential issue with chained renames in same operation
|
||||
operator(doc, { a: 'b', b: 'c' })
|
||||
|
||||
// a -> b, b -> c (but b is overwritten by a)
|
||||
// The order of operations in the for loop determines outcome
|
||||
// a -> b happens first (sets b to 1, deletes a)
|
||||
// b -> c happens second (sets c to 1 [current value of b], deletes b)
|
||||
expect((doc as any).a).toBeUndefined()
|
||||
expect((doc as any).b).toBe(1) // a's value
|
||||
expect((doc as any).c).toBe(2) // b's original value
|
||||
expect((doc as any).b).toBeUndefined()
|
||||
expect((doc as any).c).toBe(1) // Gets the value that was assigned to b from a
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user