Files
pipelines/app/test/features/schedules/data/schedules_protocol_bounds_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

82 lines
2.3 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/schedules/data/schedules_repository.dart';
import 'schedule_test_support.dart';
void main() {
test(
'list rejects non-positive and unsafe pipeline IDs before sending',
() async {
final gateway = RecordingGateway();
final repository = SchedulesRepository(gateway);
for (final id in [0, -1, 9007199254740992]) {
await expectLater(
repository.listSchedules(pipelineId: id),
throwsA(
isA<SchedulesRepositoryException>().having(
(error) => error.message,
'message',
'A positive pipeline ID is required.',
),
),
);
}
expect(gateway.calls, isEmpty);
},
);
test(
'delete rejects an inexact identity or revision before sending',
() async {
final gateway = RecordingGateway();
final repository = SchedulesRepository(gateway);
for (final pair in [
(0, 1),
(-1, 1),
(8, 0),
(8, -1),
(8, 9007199254740992),
]) {
await expectLater(
repository.deleteSchedule(pair.$1, pair.$2),
throwsA(
isA<SchedulesRepositoryException>().having(
(error) => error.message,
'message',
'An exact schedule ID and revision are required.',
),
),
);
}
expect(gateway.calls, isEmpty);
},
);
test(
'request keys are bounded at 128 characters like the web client',
() async {
final gateway = RecordingGateway();
final repository = SchedulesRepository(gateway);
await expectLater(
repository.saveSchedule(createRecord(), requestKey: 'x' * 129),
throwsA(
isA<SchedulesRepositoryException>().having(
(error) => error.message,
'message',
'Schedule request keys must be strings of at most 128 characters.',
),
),
);
expect(gateway.calls, isEmpty);
final key = 'x' * 128;
gateway.replies.add({'type': 'schedule', 'schedule': savedRecord()});
await repository.saveSchedule(createRecord(), requestKey: key);
expect(gateway.calls.single.fields['request_key'], key);
},
);
}