43 lines
1.1 KiB
Dart
43 lines
1.1 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:kickkings_support/models/api_exception.dart';
|
|
|
|
void main() {
|
|
test('reads the error string', () {
|
|
final error = ApiException.fromBody(
|
|
statusCode: 401,
|
|
body: {'error': 'Invalid credentials'},
|
|
);
|
|
|
|
expect(error.statusCode, 401);
|
|
expect(error.message, 'Invalid credentials');
|
|
expect(error.isUnauthorized, isTrue);
|
|
});
|
|
|
|
test('appends retryAfterSeconds', () {
|
|
final error = ApiException.fromBody(
|
|
statusCode: 429,
|
|
body: {
|
|
'error': 'Too many failed login attempts. Try again later.',
|
|
'retryAfterSeconds': 900,
|
|
},
|
|
);
|
|
|
|
expect(error.retryAfterSeconds, 900);
|
|
expect(
|
|
error.message,
|
|
'Too many failed login attempts. Try again later. Retry after 900 seconds.',
|
|
);
|
|
});
|
|
|
|
test('uses the fallback when the body has no error', () {
|
|
final error = ApiException.fromBody(
|
|
statusCode: 503,
|
|
body: 'unavailable',
|
|
fallback: 'Could not reach the server.',
|
|
);
|
|
|
|
expect(error.message, 'Could not reach the server.');
|
|
expect(error.retryAfterSeconds, isNull);
|
|
});
|
|
}
|