This repository has been archived on 2026-10-23. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
halkyon_shared/packages/halkyon_app/test/person/person_folders_test.dart

48 lines
1.3 KiB
Dart
Raw Permalink Normal View History

import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:halkyon_app/halkyon_app.dart';
void main() {
late Directory root;
late PersonFolders folders;
setUp(() async {
root = await Directory.systemTemp.createTemp('people_');
folders = PersonFolders(root);
});
tearDown(() => root.delete(recursive: true));
Future<void> write(String person) async {
final folder = await Directory('${root.path}/$person').create();
await File('${folder.path}/sync.sqlite').writeAsString(person);
}
Future<List<String>> people() async => [
for (final entry in root.listSync())
entry.uri.pathSegments.lastWhere((segment) => segment.isNotEmpty),
]..sort();
test("opening a person's folder wipes everyone else's", () async {
await write('anonymous-1');
await write('github-1');
final folder = await folders.openOnly('github-1');
expect(await people(), ['github-1']);
expect(
await File('${folder.path}/sync.sqlite').readAsString(),
'github-1',
reason: "the person's own data stays",
);
});
test('creates the folder of a person new to this device', () async {
await write('anonymous-1');
final folder = await folders.openOnly('anonymous-2');
expect(folder.existsSync(), isTrue);
expect(await people(), ['anonymous-2']);
});
}