forked from eatvio/eatvio_app
31 lines
836 B
Dart
31 lines
836 B
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:path/path.dart' as p;
|
|
|
|
/// Utility that reads JSON fixtures from `test/fixtures`.
|
|
///
|
|
/// Using files instead of inline maps makes it explicit which payloads
|
|
/// are exchanged with the backend.
|
|
class FixtureReader {
|
|
const FixtureReader._();
|
|
|
|
static String readAsString(String relativePath) {
|
|
final file = File(_resolve(relativePath));
|
|
return file.readAsStringSync();
|
|
}
|
|
|
|
static Map<String, dynamic> readAsMap(String relativePath) {
|
|
return jsonDecode(readAsString(relativePath)) as Map<String, dynamic>;
|
|
}
|
|
|
|
static List<dynamic> readAsList(String relativePath) {
|
|
return jsonDecode(readAsString(relativePath)) as List<dynamic>;
|
|
}
|
|
|
|
static String _resolve(String relativePath) {
|
|
return p.normalize(p.join('test', 'fixtures', relativePath));
|
|
}
|
|
}
|
|
|