import 'package:halkyon_base_server/base.dart'; import 'package:serverpod/serverpod.dart'; import 'package:test/test.dart'; import '../support/fixtures.dart'; import '../test_tools/serverpod_test_tools.dart'; /// Keeps nothing; there to say the instance can mail codes. final class _NoMail implements CodeMailer { @override Future send( Session session, { required String to, required String code, required EmailCodePurpose purpose, required String language, }) async {} @override Future sendResetNotice( Session session, { required String to, required AccountResetKind kind, required DateTime takesEffectAt, required String language, }) async {} @override Future sendCodesWaitNotice( Session session, { required String to, required DateTime until, required String language, }) async {} @override Future sendInvitation( Session session, { required String to, required String inviter, required String app, required Uri link, required DateTime lapsesAt, required String language, }) async {} } void main() { withServerpod('What every instance tells its apps', ( sessionBuilder, endpoints, ) { late InstanceBasics basics; setUp(() async { useBase(sessionBuilder); basics = await endpoints.instance.basics( sessionBuilder.copyWith( authentication: AuthenticationOverride.unauthenticated(), ), ); }); test('names the app it serves, so an app recognises its own instances', () { expect(basics.app, testApp); }); test("names where the host's project publishes its source when the " 'operator set nothing', () { // The tests run without SOURCE_URL. expect(basics.sourceCodeUrl, testUpstreamSourceCodeUrl); }); test('names the oldest app build the host works with, to anyone, so an ' 'older app can say it needs an update', () { expect(basics.minimumAppBuild, testMinimumAppBuild); }); test('says nothing of where its data and backups are where the ' 'operator said nothing', () { // The tests run without DATA_LOCATION and BACKUP_LOCATION. expect(basics.dataLocation, isNull); expect(basics.backupLocation, isNull); }); test('serves no GitHub sign-in: GitHub signs nobody in any more (ADR ' '0020, D36)', () { final pod = sessionBuilder.build().serverpod; expect(pod.server.endpoints.getConnectorByName('gitHubSignIn'), isNull); }); test('offers email sign-in only where it can mail codes', () async { final codes = EmailCodes.of(sessionBuilder.build().serverpod); final unauthenticated = sessionBuilder.copyWith( authentication: AuthenticationOverride.unauthenticated(), ); addTearDown(() => codes.mailer = null); codes.mailer = null; expect( (await endpoints.instance.basics(unauthenticated)).emailSignIn, isFalse, ); codes.mailer = _NoMail(); expect( (await endpoints.instance.basics(unauthenticated)).emailSignIn, isTrue, ); }); }); }