fixed guardian login edge cases and misleading placeholders on failed loads
This commit is contained in:
@@ -220,6 +220,45 @@ void main() {
|
||||
expect(signedIn.single.isDemo, isTrue);
|
||||
});
|
||||
|
||||
test('a failing demo sign-in reports instead of throwing', () async {
|
||||
final c = GuardianLoginController(
|
||||
request: request,
|
||||
verify: verify,
|
||||
store: store,
|
||||
signIn: (_) async => throw Exception('keystore unavailable'),
|
||||
tokenName: () async => 'test',
|
||||
now: () => now,
|
||||
);
|
||||
expect(await c.requestCode(DemoMode.guardianEmail), isFalse);
|
||||
expect(c.errorMessage, isNotNull);
|
||||
expect(c.loading, isFalse);
|
||||
});
|
||||
|
||||
test('a code without a running request reports instead of failing '
|
||||
'silently', () async {
|
||||
final c = controller();
|
||||
expect(await c.submitCode('123456'), isFalse);
|
||||
expect(c.errorMessage, isNotNull);
|
||||
expect(c.step, GuardianLoginStep.enterEmail);
|
||||
expect(verify.lastCall, isNull);
|
||||
});
|
||||
|
||||
test('a link of another server is named as such', () {
|
||||
final c = controller();
|
||||
c.rejectForeignLink();
|
||||
expect(c.errorMessage, contains('anderen Server'));
|
||||
});
|
||||
|
||||
test('the resend cooldown runs on the injected clock', () async {
|
||||
final c = controller();
|
||||
await c.requestCode('e@x.de');
|
||||
expect(c.resendCooldown(), const Duration(seconds: 60));
|
||||
expect(c.canResend(), isFalse);
|
||||
now = now.add(const Duration(seconds: 61));
|
||||
expect(c.resendCooldown(), Duration.zero);
|
||||
expect(c.canResend(), isTrue);
|
||||
});
|
||||
|
||||
group('GuardianLoginException.fromDio', () {
|
||||
DioException failure(int status, Object? body) => DioException(
|
||||
requestOptions: RequestOptions(),
|
||||
@@ -291,6 +330,17 @@ void main() {
|
||||
expect(e.error, GuardianLoginError.accountDisabled);
|
||||
});
|
||||
|
||||
test('a bare 401 on the e-mail step is not a wrong code', () {
|
||||
expect(
|
||||
GuardianLoginException.fromDio(failure(401, null), verifying: false),
|
||||
isNot(isA<GuardianLoginException>()),
|
||||
);
|
||||
final verifying =
|
||||
GuardianLoginException.fromDio(failure(401, null))
|
||||
as GuardianLoginException;
|
||||
expect(verifying.error, GuardianLoginError.invalidCode);
|
||||
});
|
||||
|
||||
test('server errors keep the generic mapping', () {
|
||||
expect(
|
||||
GuardianLoginException.fromDio(failure(500, 'boom')),
|
||||
|
||||
@@ -75,13 +75,22 @@ void main() {
|
||||
expect(policy.mode, ParentLetterFormMode.done);
|
||||
});
|
||||
|
||||
test('unknown optional fields are skipped', () {
|
||||
test('unknown optional fields are skipped but flagged', () {
|
||||
final policy = ParentLetterFormPolicy.resolve(
|
||||
request: const ParentLetterRequest(fields: [_choice, _unknownOptional]),
|
||||
child: _child(),
|
||||
)!;
|
||||
expect(policy.mode, ParentLetterFormMode.open);
|
||||
expect(policy.fields, [_choice]);
|
||||
expect(policy.hasUnsupportedFields, isTrue);
|
||||
});
|
||||
|
||||
test('a fully supported request is not flagged', () {
|
||||
final policy = ParentLetterFormPolicy.resolve(
|
||||
request: const ParentLetterRequest(fields: [_choice, _optionalChoice]),
|
||||
child: _child(),
|
||||
)!;
|
||||
expect(policy.hasUnsupportedFields, isFalse);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user