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);
|
||
|
|
});
|
||
|
|
}
|