platform/packages/file_service/test/all_test.dart

72 lines
1.6 KiB
Dart
Raw Normal View History

2021-06-10 08:47:05 +00:00
import 'package:angel3_file_service/angel3_file_service.dart';
2018-07-12 20:29:16 +00:00
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:test/test.dart';
2021-06-10 08:47:05 +00:00
void main() {
2018-07-12 20:29:16 +00:00
MemoryFileSystem fs;
File dbFile;
2021-06-10 08:47:05 +00:00
late JsonFileService service;
2018-07-12 20:29:16 +00:00
setUp(() async {
2021-06-26 12:06:30 +00:00
fs = MemoryFileSystem();
2018-07-12 20:29:16 +00:00
dbFile = fs.file('db.json');
2021-06-26 12:06:30 +00:00
service = JsonFileService(dbFile);
2018-07-12 20:29:16 +00:00
await dbFile.writeAsString('''
[
{"id": "0", "foo": "bar"},
{"id": "1", "foo": "baz"},
{"id": "2", "foo": "quux"}
]
''');
});
tearDown(() => service.close());
test('index no params', () async {
expect(await service.index(), [
2021-06-26 12:06:30 +00:00
{'id': '0', 'foo': 'bar'},
{'id': '1', 'foo': 'baz'},
{'id': '2', 'foo': 'quux'}
2018-07-12 20:29:16 +00:00
]);
});
test('index with query', () async {
expect(
await service.index({
'query': {'foo': 'bar'}
}),
[
2021-06-26 12:06:30 +00:00
{'id': '0', 'foo': 'bar'}
2018-07-12 20:29:16 +00:00
],
);
});
test('read', () async {
expect(
await service.read('2'),
2021-06-26 12:06:30 +00:00
{'id': '2', 'foo': 'quux'},
2018-07-12 20:29:16 +00:00
);
});
test('modify', () async {
await service.modify('2', {'baz': 'quux'});
expect(await service.read('2'), containsPair('baz', 'quux'));
});
test('update', () async {
await service.update('2', {'baz': 'quux'});
expect(await service.read('2'), containsPair('baz', 'quux'));
expect(await service.read('2'), isNot(containsPair('foo', 'quux')));
});
test('delete', () async {
await service.remove('2');
expect(await service.index(), [
2021-06-26 12:06:30 +00:00
{'id': '0', 'foo': 'bar'},
{'id': '1', 'foo': 'baz'}
2018-07-12 20:29:16 +00:00
]);
});
}