fix: prioritize realtime reminder archive with cold-start fallback

This commit is contained in:
qzl
2026-03-20 15:41:48 +08:00
parent f4c07287bc
commit 20f3285244
2 changed files with 57 additions and 11 deletions
@@ -30,6 +30,7 @@ void main() {
calendarService: calendarService,
notificationService: notificationService,
outboxStore: outboxStore,
isAppActive: () => true,
);
});
@@ -57,13 +58,50 @@ void main() {
expect(pending, isEmpty);
});
test('archive failure writes pending outbox item', () async {
test(
'archive action should send remote archive immediately when app active',
() async {
when(
() => notificationService.cancelEventReminder('evt_live'),
).thenAnswer((_) async {});
when(
() => calendarService.archiveEvent('evt_live'),
).thenAnswer((_) async => null);
executor = ReminderActionExecutor(
calendarService: calendarService,
notificationService: notificationService,
outboxStore: outboxStore,
isAppActive: () => true,
);
await executor.handleAction(
action: ReminderAction.archive,
payload: ReminderPayload(
eventId: 'evt_live',
title: 'sync',
startAt: DateTime.parse('2026-03-18T16:00:00+08:00'),
timezone: 'Asia/Shanghai',
),
);
verify(() => calendarService.archiveEvent('evt_live')).called(1);
final pending = await outboxStore.listPending();
expect(pending, isEmpty);
},
);
test('archive in inactive app writes pending outbox item', () async {
when(
() => notificationService.cancelEventReminder('evt_1'),
).thenAnswer((_) async {});
when(
() => calendarService.archiveEvent('evt_1'),
).thenThrow(Exception('offline'));
executor = ReminderActionExecutor(
calendarService: calendarService,
notificationService: notificationService,
outboxStore: outboxStore,
isAppActive: () => false,
);
await executor.handleAction(
action: ReminderAction.archive,