What every Halkyon app's shell needs, taken from Halkyon Learn's and set on halkyon_base's client: the instances a device keeps an account on, the first start's tiles and where an instance keeps people's data, the account switcher; signing in anonymously, with GitHub or an email code, switching person and the start screen; the gates that build an app's dependencies per instance and per person; and the sync service with its status, Settings card and banner. Texts of its own in English and German take the app's name; what only the app can say, it passes in. Fakes for apps' tests are in testing.dart. An instance's basics now name the app it serves (`app`, set by the host's configuration), and an app accepts only an instance of its own. SerialQueue and CoalescingRunner move into halkyon_core. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
67 lines
2.2 KiB
Dart
67 lines
2.2 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:halkyon_app/halkyon_app.dart';
|
|
import 'package:halkyon_base_client/halkyon_base_client.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:http/testing.dart';
|
|
|
|
void main() {
|
|
final halkyon = Instance.parse('learn.example.org')!;
|
|
final todo = Instance.parse('todo.example.org')!;
|
|
final elsewhere = Instance.parse('www.example.org')!;
|
|
|
|
/// Basics as an instance of [app] tells them.
|
|
http.Response basicsOf(String app) => http.Response(
|
|
jsonEncode(
|
|
InstanceBasics(
|
|
app: app,
|
|
emailSignIn: false,
|
|
sourceCodeUrl: 'https://code.example.org/$app',
|
|
minimumAppBuild: 1,
|
|
dataLocation: 'EU',
|
|
backupLocation: 'CH',
|
|
).toJson(),
|
|
),
|
|
200,
|
|
);
|
|
|
|
/// A checker of the app `learn` reaching instances through a fake network,
|
|
/// where learn.example.org answers as an instance of it, todo.example.org
|
|
/// as an instance of another app, and nothing else answers.
|
|
ServerpodInstanceChecker checker() => ServerpodInstanceChecker(
|
|
app: 'learn',
|
|
httpClient: () => MockClient(
|
|
(request) async => switch ((request.url.host, request.url.path)) {
|
|
('learn.example.org', '/halkyon_base.instance/basics') => basicsOf(
|
|
'learn',
|
|
),
|
|
('todo.example.org', '/halkyon_base.instance/basics') => basicsOf(
|
|
'todo',
|
|
),
|
|
_ => http.Response('<html>Not found</html>', 404),
|
|
},
|
|
),
|
|
);
|
|
|
|
test('an instance answers when its halkyon_base tells its basics; any '
|
|
'other site does not', () async {
|
|
expect(await checker().answers(halkyon), isTrue);
|
|
expect(await checker().answers(elsewhere), isFalse);
|
|
});
|
|
|
|
test("another app's instance does not answer, so its address is refused "
|
|
'before the app moves there', () async {
|
|
expect(await checker().answers(todo), isFalse);
|
|
expect(await checker().locationsOf(todo), isNull);
|
|
});
|
|
|
|
test("says where an instance keeps people's data and its backups, and "
|
|
'nothing for a site that is no instance', () async {
|
|
expect(
|
|
await checker().locationsOf(halkyon),
|
|
const InstanceLocations(data: 'EU', backups: 'CH'),
|
|
);
|
|
expect(await checker().locationsOf(elsewhere), isNull);
|
|
});
|
|
}
|