Files
sync_replay_project/apps/desktop/test/settings_schema_test.dart
T
foxyzandClaude Opus 5.5 51c1c5ab78
ci / core (push) Successful in 31s
ci / server (push) Successful in 1m3s
ci / updater-windows (push) Successful in 6m6s
Restructure step R: the app is Starsync (dev.foxyz.starsync)
- Linux app id dev.foxyz.starsync, binary starsync; Windows starsync.exe,
  company foxyz; server starsync-server; Dart package starsync; archives
  starsync-<ver>-*.
- 1.2.x compatibility: watch_together and watch-together-server
  launchers (Linux) / copies (Windows) in the archive; the updater
  accepts both names and relaunches the new binary; update.sh/.bat use
  whichever server exists.
- First start copies (never moves) the old support folder and this
  app's Hive boxes out of ~/Documents into <support>/hive; a marker
  makes it run once; AppDirs is a port; settings schema version with
  ordered migrations.
- Launcher entry dev.foxyz.starsync.desktop; the old one removed.
- Repository name and URLs unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 20:21:20 +03:00

58 lines
1.9 KiB
Dart

import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:hive_ce/hive.dart';
import 'package:starsync/src/state/settings_schema.dart';
void main() {
group('settings schema', () {
late Directory dir;
setUp(() async {
dir = await Directory.systemTemp.createTemp('starsync-schema');
Hive.init(dir.path);
});
tearDown(() async {
await Hive.close();
await dir.delete(recursive: true);
});
test('a box without a version is at 1 and gets stamped', () async {
final box = await Hive.openBox('settings');
expect(await migrateSettings(box), isEmpty);
expect(box.get(settingsSchemaKey), settingsSchemaVersion);
});
test('steps run in order, only past the stored version', () async {
final box = await Hive.openBox('settings');
await box.put(settingsSchemaKey, 1);
await box.put('old', 'x');
final order = <int>[];
final steps = [
SettingsMigration(3, 'c', (b) async {
order.add(3);
await b.put('c', b.get('new'));
}),
SettingsMigration(2, 'rename old to new', (b) async {
order.add(2);
await b.put('new', b.get('old'));
await b.delete('old');
}),
SettingsMigration(4, 'not yet', (b) async => order.add(4)),
];
final ran = await migrateSettings(box, steps: steps, current: 3);
expect(order, [2, 3]);
expect(ran, ['settings schema 2: rename old to new', 'settings schema 3: c']);
expect(box.get('c'), 'x');
expect(box.get(settingsSchemaKey), 3);
expect(await migrateSettings(box, steps: steps, current: 3), isEmpty);
});
test('a box from a newer build is left as it is', () async {
final box = await Hive.openBox('settings');
await box.put(settingsSchemaKey, 9);
expect(await migrateSettings(box), hasLength(1));
expect(box.get(settingsSchemaKey), 9);
});
});
}