Add rejected mutation requeue flow in sync UI

This commit is contained in:
Rijad Zuzo
2026-02-15 23:06:48 +01:00
parent 831c217e29
commit c4b86c18da
5 changed files with 205 additions and 7 deletions
@@ -67,6 +67,7 @@ void main() {
expect(state.pending, isEmpty);
expect(state.cursor, 'cursor-2');
expect(state.rejected.length, 1);
expect(state.rejectedChanges.length, 1);
expect(state.lastError, contains('Push rejected'));
},
);
@@ -104,9 +105,52 @@ void main() {
await notifier.clearRejections();
final SyncStateData state = await _readState(container);
expect(state.rejected, isEmpty);
expect(state.rejectedChanges, isEmpty);
expect(state.lastError, isNull);
},
);
test(
'requeueRejectedChanges adds rejected envelopes back to pending',
() async {
final ProviderContainer container = ProviderContainer(
overrides: [
syncStateStoreProvider.overrideWithValue(InMemorySyncStateStore()),
],
);
addTearDown(container.dispose);
final SyncQueueRepository notifier = container.read(
syncQueueRepositoryProvider.notifier,
);
await notifier.enqueue(_change(id: 'p-9', mutationId: 'cm-x'));
await notifier.applyPushResult(
SyncPushResult(
cursor: 'cursor-10',
accepted: const <MutationAck>[],
rejected: const <MutationRejection>[
MutationRejection(
clientMutationId: 'cm-x',
code: 'VALIDATION_FAILED',
message: 'invalid payload',
),
],
),
);
SyncStateData state = await _readState(container);
expect(state.pending, isEmpty);
expect(state.rejectedChanges.length, 1);
await notifier.requeueRejectedChanges();
state = await _readState(container);
expect(state.pending.length, 1);
expect(state.pending.first.clientMutationId, 'cm-x');
expect(state.rejected, isEmpty);
expect(state.rejectedChanges, isEmpty);
},
);
}
class SyncStateData {
@@ -114,12 +158,14 @@ class SyncStateData {
required this.cursor,
required this.pending,
required this.rejected,
required this.rejectedChanges,
required this.lastError,
});
final String? cursor;
final List<ChangeEnvelope> pending;
final List<MutationRejection> rejected;
final List<ChangeEnvelope> rejectedChanges;
final String? lastError;
}
@@ -129,6 +175,7 @@ Future<SyncStateData> _readState(ProviderContainer container) async {
cursor: state.cursor,
pending: state.pendingChanges,
rejected: state.lastRejected,
rejectedChanges: state.lastRejectedChanges,
lastError: state.lastError,
);
}