feat(app): add template catalogue and create-only submit repository
Add the nonvisual templates data/domain slice: TemplateRepository over the shared ApiGateway for list_templates, validate and create-only submit, and TemplateEntry preserving every server field in a deeply read-only raw map. Re-include test/**/data/ in app/.gitignore so the mirroring tests are not silently dropped from a fresh checkout. Tests cover exact request shapes, source preservation, blank-name refusal, malformed replies, server refusals and immutability.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
|
||||
/// A recording gateway: it captures every request and answers from [replies].
|
||||
class RecordingGateway implements ApiGateway {
|
||||
RecordingGateway([List<JsonMap> replies = const []])
|
||||
: _replies = [...replies];
|
||||
|
||||
final List<JsonMap> _replies;
|
||||
final List<({String type, JsonMap fields})> calls = [];
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
calls.add((type: type, fields: Map<String, dynamic>.from(fields)));
|
||||
return _replies.removeAt(0);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
}
|
||||
|
||||
/// A gateway that refuses every request with the same server error object.
|
||||
class RefusingGateway implements ApiGateway {
|
||||
RefusingGateway(this.refusal);
|
||||
|
||||
final Object refusal;
|
||||
final List<String> calls = [];
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
calls.add(type);
|
||||
throw refusal;
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
}
|
||||
|
||||
class ServerRefusal implements Exception {
|
||||
const ServerRefusal(this.message);
|
||||
final String message;
|
||||
@override
|
||||
String toString() => message;
|
||||
}
|
||||
|
||||
/// A source with Unicode, tabs, newlines and significant leading/trailing
|
||||
/// whitespace: every request must carry it unchanged.
|
||||
const source = ' name: "café"\n\tstages:\n - key: "añadir" 😀 \n';
|
||||
Reference in New Issue
Block a user