Files
pipelines/app/test/features/schedules/data/schedules_delete_test.dart
T
alan b9639650e5 feat(app): add saved-schedule repository and domain record
Port the web client's list/save/delete schedule request shapes and reply checks, with a typed record that preserves the whole server payload including unknown fields. Revision stays the CAS token; server refusals propagate unchanged.
2026-10-21 15:15:47 +01:00

132 lines
4.0 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/transport/connection_state.dart';
import 'package:pipelines_app/features/schedules/data/schedules_repository.dart';
import 'schedule_test_support.dart';
void main() {
test('delete sends the exact ID and expected revision', () async {
final gateway = RecordingGateway()
..replies.add({'type': 'schedule_deleted', 'schedule_id': 8});
final repository = SchedulesRepository(gateway);
await repository.deleteSchedule(8, 3);
expect(gateway.calls.single.type, 'delete_schedule');
expect(gateway.calls.single.fields, {
'schedule_id': 8,
'expected_revision': 3,
});
});
test('delete refuses a confirmation for anything else', () async {
final gateway = RecordingGateway();
final repository = SchedulesRepository(gateway);
for (final reply in [
<String, dynamic>{},
{'type': 'pong'},
{'type': 'schedule_deleted'},
{'type': 'schedule_deleted', 'schedule_id': 9},
]) {
gateway.replies.add(reply);
await expectLater(
repository.deleteSchedule(8, 3),
throwsA(
isA<SchedulesRepositoryException>().having(
(error) => error.message,
'message',
'The server did not confirm deletion of this schedule.',
),
),
);
}
});
test('server refusals and conflicts propagate verbatim', () async {
final conflict = const ProtocolError(
'schedule revision conflict; reload before editing',
);
final recording = RecordingGateway()..failure = conflict;
final conflicting = SchedulesRepository(recording);
await expectLater(
conflicting.saveSchedule(createRecord()),
throwsA(same(conflict)),
);
await expectLater(
conflicting.deleteSchedule(8, 3),
throwsA(same(conflict)),
);
final unsupported = const ProtocolError(
'unknown message type: list_schedules',
);
recording.failure = unsupported;
await expectLater(
conflicting.listSchedules(pipelineId: 4),
throwsA(same(unsupported)),
);
});
test('missing and empty list replies are different facts', () async {
final gateway = RecordingGateway();
final repository = SchedulesRepository(gateway);
gateway.replies.add({'type': 'schedules'});
expect(await repository.listSchedules(), isEmpty);
gateway.replies.add({'type': 'schedules', 'schedules': null});
expect(await repository.listSchedules(), isEmpty);
for (final reply in [
<String, dynamic>{},
{'type': 'pong'},
{'type': 'schedules', 'schedules': <String, dynamic>{}},
{
'type': 'schedules',
'schedules': ['not a record'],
},
]) {
gateway.replies.add(reply);
await expectLater(
repository.listSchedules(),
throwsA(isA<SchedulesRepositoryException>()),
);
}
});
test('save requires a saved schedule in the reply', () async {
final gateway = RecordingGateway();
final repository = SchedulesRepository(gateway);
for (final reply in [
<String, dynamic>{},
{'type': 'schedule'},
{'type': 'schedule', 'schedule': null},
{'type': 'schedule', 'schedule': 'record'},
]) {
gateway.replies.add(reply);
await expectLater(
repository.saveSchedule(createRecord()),
throwsA(
isA<SchedulesRepositoryException>().having(
(error) => error.message,
'message',
'The server returned no saved schedule.',
),
),
);
}
});
test('an empty schedule object is not turned into a fake identity', () async {
final gateway = RecordingGateway()
..replies.add({'type': 'schedule', 'schedule': <String, dynamic>{}});
final repository = SchedulesRepository(gateway);
final saved = await repository.saveSchedule(createRecord());
expect(saved.id, isNull);
expect(saved.revision, isNull);
expect(saved.toJson(), isEmpty);
});
}