mirror of
https://github.com/supabase/supabase.git
synced 2026-06-20 03:27:24 +08:00
fix: revert changes when the value is the same as old (#44196)
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Revert changes when the value is the same as the old value --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
This commit is contained in:
@@ -491,6 +491,120 @@ describe('upsertOperation', () => {
|
||||
expect((updated.payload as any).newValue).toBe('final value')
|
||||
})
|
||||
|
||||
test('should remove operation when value is reverted to original', () => {
|
||||
const existingOp: QueuedOperation = {
|
||||
id: 'edit_cell_content:1:name:id:1',
|
||||
type: QueuedOperationType.EDIT_CELL_CONTENT,
|
||||
tableId: 1,
|
||||
timestamp: Date.now() - 1000,
|
||||
payload: {
|
||||
rowIdentifiers: { id: 1 },
|
||||
columnName: 'name',
|
||||
oldValue: 'original',
|
||||
newValue: 'changed',
|
||||
table: mockTable,
|
||||
},
|
||||
}
|
||||
|
||||
const otherOp: QueuedOperation = {
|
||||
id: 'edit_cell_content:1:email:id:1',
|
||||
type: QueuedOperationType.EDIT_CELL_CONTENT,
|
||||
tableId: 1,
|
||||
timestamp: Date.now(),
|
||||
payload: {
|
||||
rowIdentifiers: { id: 1 },
|
||||
columnName: 'email',
|
||||
oldValue: 'old@test.com',
|
||||
newValue: 'new@test.com',
|
||||
table: mockTable,
|
||||
},
|
||||
}
|
||||
|
||||
const operations = [existingOp, otherOp]
|
||||
const newOperation: NewEditCellContentOperation = {
|
||||
type: QueuedOperationType.EDIT_CELL_CONTENT,
|
||||
tableId: 1,
|
||||
payload: {
|
||||
rowIdentifiers: { id: 1 },
|
||||
columnName: 'name',
|
||||
oldValue: 'changed',
|
||||
newValue: 'original',
|
||||
table: mockTable,
|
||||
},
|
||||
}
|
||||
|
||||
const result = upsertOperation(operations, newOperation)
|
||||
|
||||
expect(result.operations).toHaveLength(1)
|
||||
expect(result.operations[0]).toEqual(otherOp)
|
||||
})
|
||||
|
||||
test('should remove operation when number oldValue matches string newValue', () => {
|
||||
const existingOp: QueuedOperation = {
|
||||
id: 'edit_cell_content:1:age:id:1',
|
||||
type: QueuedOperationType.EDIT_CELL_CONTENT,
|
||||
tableId: 1,
|
||||
timestamp: Date.now() - 1000,
|
||||
payload: {
|
||||
rowIdentifiers: { id: 1 },
|
||||
columnName: 'age',
|
||||
oldValue: 42,
|
||||
newValue: 'changed',
|
||||
table: mockTable,
|
||||
},
|
||||
}
|
||||
|
||||
const operations = [existingOp]
|
||||
const newOperation: NewEditCellContentOperation = {
|
||||
type: QueuedOperationType.EDIT_CELL_CONTENT,
|
||||
tableId: 1,
|
||||
payload: {
|
||||
rowIdentifiers: { id: 1 },
|
||||
columnName: 'age',
|
||||
oldValue: 'changed',
|
||||
newValue: '42',
|
||||
table: mockTable,
|
||||
},
|
||||
}
|
||||
|
||||
const result = upsertOperation(operations, newOperation)
|
||||
|
||||
expect(result.operations).toHaveLength(0)
|
||||
})
|
||||
|
||||
test('should remove operation when string oldValue matches JSON object newValue', () => {
|
||||
const existingOp: QueuedOperation = {
|
||||
id: 'edit_cell_content:1:metadata:id:1',
|
||||
type: QueuedOperationType.EDIT_CELL_CONTENT,
|
||||
tableId: 1,
|
||||
timestamp: Date.now() - 1000,
|
||||
payload: {
|
||||
rowIdentifiers: { id: 1 },
|
||||
columnName: 'metadata',
|
||||
oldValue: '{"key":"value","count":3}',
|
||||
newValue: 'changed',
|
||||
table: mockTable,
|
||||
},
|
||||
}
|
||||
|
||||
const operations = [existingOp]
|
||||
const newOperation: NewEditCellContentOperation = {
|
||||
type: QueuedOperationType.EDIT_CELL_CONTENT,
|
||||
tableId: 1,
|
||||
payload: {
|
||||
rowIdentifiers: { id: 1 },
|
||||
columnName: 'metadata',
|
||||
oldValue: 'changed',
|
||||
newValue: { key: 'value', count: 3 },
|
||||
table: mockTable,
|
||||
},
|
||||
}
|
||||
|
||||
const result = upsertOperation(operations, newOperation)
|
||||
|
||||
expect(result.operations).toHaveLength(0)
|
||||
})
|
||||
|
||||
test('should update existing DELETE_ROW operation', () => {
|
||||
const existingOp: QueuedOperation = {
|
||||
id: 'delete_row:1:id:1',
|
||||
|
||||
Reference in New Issue
Block a user