6d674a4a1b
- Updated `pubspec.lock` to reflect new versions for several packages, including `async`, `fake_async`, `leak_tracker`, and `vm_service`. - Modified `TenderApprovalStatus` enum to include a new status `approved`. - Updated routing for `YourTendersRouteData` to accept a status parameter and pass it to the `YourTendersScreen`. - Adjusted API calls and view models to utilize the new status handling, ensuring proper filtering and display of tender data based on approval status. - Enhanced filter dialog to support new status options and improved user feedback in the UI for submitted and approved tenders.
77 lines
2.1 KiB
Dart
77 lines
2.1 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:tm_app/data/services/model/error/error_model.dart';
|
|
|
|
void main() {
|
|
group('ErrorModel Tests', () {
|
|
test('fromJson should parse JSON correctly', () {
|
|
final json = {
|
|
'message': 'Invalid request',
|
|
'code': '400',
|
|
'details': 'Missing required field: email',
|
|
};
|
|
|
|
final error = ErrorModel.fromJson(json);
|
|
|
|
expect(error.message, 'Invalid request');
|
|
expect(error.code, '400');
|
|
expect(error.details, 'Missing required field: email');
|
|
});
|
|
|
|
test('toJson should return valid JSON map', () {
|
|
const error = ErrorModel(
|
|
message: 'Unauthorized',
|
|
code: '401',
|
|
details: 'Token expired',
|
|
);
|
|
|
|
final json = error.toJson();
|
|
|
|
expect(json, isA<Map<String, dynamic>>());
|
|
expect(json['message'], 'Unauthorized');
|
|
expect(json['code'], '401');
|
|
expect(json['details'], 'Token expired');
|
|
});
|
|
|
|
test(' copyWith should modify specific fields only', () {
|
|
const error = ErrorModel(
|
|
message: 'Something went wrong',
|
|
code: '500',
|
|
details: 'Server error',
|
|
);
|
|
|
|
final updated = error.copyWith(message: 'Timeout error');
|
|
|
|
expect(updated.message, 'Timeout error');
|
|
expect(updated.code, '500');
|
|
expect(updated.details, 'Server error');
|
|
});
|
|
|
|
test('fromJson handles null fields safely', () {
|
|
final json = {'message': null, 'code': null, 'details': null};
|
|
|
|
final error = ErrorModel.fromJson(json);
|
|
|
|
expect(error.message, isNull);
|
|
expect(error.code, isNull);
|
|
expect(error.details, isNull);
|
|
});
|
|
|
|
test('fromJson -> toJson round-trip should preserve data', () {
|
|
final json = {
|
|
'message': 'Not Found',
|
|
'code': '404',
|
|
'details': 'User not found',
|
|
};
|
|
|
|
final error = ErrorModel.fromJson(json);
|
|
final output = error.toJson();
|
|
|
|
expect(output['message'], 'Not Found');
|
|
expect(output['code'], '404');
|
|
expect(output['details'], 'User not found');
|
|
});
|
|
});
|
|
}
|
|
|
|
////////////////////////////
|