fix(web): preserve saved writes across refresh failures
This commit is contained in:
41
apps/web_v1/scripts/mutation-refresh.test.mjs
Normal file
41
apps/web_v1/scripts/mutation-refresh.test.mjs
Normal file
@@ -0,0 +1,41 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import { executeSavedMutation } from '../src/app/mutation-refresh.ts'
|
||||
|
||||
test('a saved mutation stays successful when its refresh fails', async () => {
|
||||
const events = []
|
||||
const refreshFailure = new Error('refresh unavailable')
|
||||
|
||||
const outcome = await executeSavedMutation({
|
||||
mutate: async () => {
|
||||
events.push('mutate')
|
||||
return { id: 'created-1' }
|
||||
},
|
||||
onSaved: (value) => events.push(`saved:${value.id}`),
|
||||
refresh: async (value) => {
|
||||
events.push(`refresh:${value.id}`)
|
||||
throw refreshFailure
|
||||
},
|
||||
})
|
||||
|
||||
assert.deepEqual(events, ['mutate', 'saved:created-1', 'refresh:created-1'])
|
||||
assert.equal(outcome.value.id, 'created-1')
|
||||
assert.equal(outcome.refreshError, refreshFailure)
|
||||
})
|
||||
|
||||
test('a failed mutation does not close its draft or attempt a refresh', async () => {
|
||||
const events = []
|
||||
const mutationFailure = new Error('save rejected')
|
||||
|
||||
await assert.rejects(() => executeSavedMutation({
|
||||
mutate: async () => {
|
||||
events.push('mutate')
|
||||
throw mutationFailure
|
||||
},
|
||||
onSaved: () => events.push('saved'),
|
||||
refresh: async () => events.push('refresh'),
|
||||
}), mutationFailure)
|
||||
|
||||
assert.deepEqual(events, ['mutate'])
|
||||
})
|
||||
Reference in New Issue
Block a user