Added Google Drive storage location
This commit is contained in:
parent
e630f2a3ec
commit
73a7c93e64
22 changed files with 1690 additions and 205 deletions
54
test/merge_utils_test.dart
Normal file
54
test/merge_utils_test.dart
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fuel_tax_tracker/services/merge_utils.dart';
|
||||
|
||||
class _Record {
|
||||
final String id;
|
||||
final String value;
|
||||
final DateTime updatedAt;
|
||||
|
||||
_Record(this.id, this.value, this.updatedAt);
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('mergeById', () {
|
||||
test('unions records that only exist on one side', () {
|
||||
final remote = [_Record('a', 'remote-a', DateTime(2024, 1, 1))];
|
||||
final local = [_Record('b', 'local-b', DateTime(2024, 1, 1))];
|
||||
|
||||
final result = mergeById(remote, local, (r) => r.id, (r) => r.updatedAt);
|
||||
|
||||
expect(result.map((r) => r.id), containsAll(['a', 'b']));
|
||||
expect(result.length, 2);
|
||||
});
|
||||
|
||||
test('keeps the newer updatedAt when a record exists on both sides', () {
|
||||
final remote = [_Record('a', 'remote-old', DateTime(2024, 1, 1))];
|
||||
final local = [_Record('a', 'local-new', DateTime(2024, 6, 1))];
|
||||
|
||||
final result = mergeById(remote, local, (r) => r.id, (r) => r.updatedAt);
|
||||
|
||||
expect(result.length, 1);
|
||||
expect(result.first.value, 'local-new');
|
||||
});
|
||||
|
||||
test('keeps the remote copy when it is newer than local', () {
|
||||
final remote = [_Record('a', 'remote-new', DateTime(2024, 6, 1))];
|
||||
final local = [_Record('a', 'local-old', DateTime(2024, 1, 1))];
|
||||
|
||||
final result = mergeById(remote, local, (r) => r.id, (r) => r.updatedAt);
|
||||
|
||||
expect(result.length, 1);
|
||||
expect(result.first.value, 'remote-new');
|
||||
});
|
||||
|
||||
test('local wins ties', () {
|
||||
final sameTime = DateTime(2024, 1, 1);
|
||||
final remote = [_Record('a', 'remote', sameTime)];
|
||||
final local = [_Record('a', 'local', sameTime)];
|
||||
|
||||
final result = mergeById(remote, local, (r) => r.id, (r) => r.updatedAt);
|
||||
|
||||
expect(result.first.value, 'local');
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue