forked from eatvio/eatvio_app
feat(tests): add fixtures
This commit is contained in:
30
test/fixtures/fixture_reader.dart
vendored
Normal file
30
test/fixtures/fixture_reader.dart
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user