mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-24 11:26:24 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Waiting to run
Tests / test (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
46 lines
1.5 KiB
Dart
46 lines
1.5 KiB
Dart
/// The catering login's error messages.
|
|
///
|
|
/// A 401 is a wrong password, and on the phone the only place to fix that is
|
|
/// Settings -- so only a 401 points there. Any other status is the panel's
|
|
/// problem; sending the user to re-type a correct password would mislead.
|
|
library;
|
|
|
|
import 'package:diet_guard_app/services/kuchnia_client.dart';
|
|
import 'package:diet_guard_app/services/kuchnia_errors.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:http/testing.dart';
|
|
|
|
const _settingsHint = 'check the password in Settings';
|
|
|
|
/// Logs in against a panel that answers the login with [status].
|
|
Future<KuchniaError> _loginError(int status) async {
|
|
final session = KuchniaSession(
|
|
username: 'me@example.com',
|
|
password: 'pw',
|
|
client: MockClient((_) async => http.Response('', status)),
|
|
);
|
|
try {
|
|
await session.login();
|
|
} on KuchniaError catch (error) {
|
|
return error;
|
|
}
|
|
fail('a $status login must throw KuchniaError');
|
|
}
|
|
|
|
void main() {
|
|
group('a rejected login', () {
|
|
test('401 points the user at the password in Settings', () async {
|
|
final error = await _loginError(401);
|
|
expect(error.message, contains('HTTP 401'));
|
|
expect(error.message, contains(_settingsHint));
|
|
});
|
|
|
|
test('500 is the panel\'s fault, not the password\'s', () async {
|
|
final error = await _loginError(500);
|
|
expect(error.message, contains('HTTP 500'));
|
|
expect(error.message, isNot(contains(_settingsHint)));
|
|
});
|
|
});
|
|
}
|