Files
tm_app/test/model/feedback_response_test.dart
2025-10-06 16:26:53 +03:30

125 lines
4.5 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:tm_app/data/services/model/feedback_response/feedback_response.dart';
void main() {
group('FeedbackResponse Model Test', () {
final mockJson = {
'meta': {'limit': 10, 'offset': 0, 'page': 1, 'pages': 5, 'total': 50},
'data': {
'company_id': 'cmp123',
'created_at': 1710000000,
'customer_id': 'cus456',
'feedback_type': 'positive',
'id': 'fb789',
'tender_id': 'tnd111',
'tender': {
'success': true,
'message': 'ok',
'id': 'tnd111',
'tender_id': 'T-001',
'notice_publication_id': 'NP-99',
'publication_date': 1710001111,
'title': 'Sample Tender',
'description': 'A description of the tender',
'procurement_type_code': 'PROC1',
'procedure_code': 'PC-01',
'estimated_value': 50000,
'currency': 'USD',
'duration': '6 months',
'tender_deadline': 1710100000,
'submission_deadline': 1710200000,
'application_deadline': 1710300000,
'submission_url': 'https://example.com/submit',
'country_code': 'US',
'duration_unit': 'months',
'buyer_organization': {'name': 'Acme Corp'},
'status': 'open',
},
'updated_at': 1710050000,
},
'error': {'message': null, 'code': null, 'details': null},
'message': 'Success',
'success': true,
};
test('fromJson creates valid FeedbackResponse instance', () {
final response = FeedbackResponse.fromJson(mockJson);
expect(response.success, true);
expect(response.message, 'Success');
expect(response.meta?.limit, 10);
expect(response.data?.feedbackType, 'positive');
expect(response.data?.tender?.buyerOrganization?.name, 'Acme Corp');
});
test('toJson converts model back to JSON correctly', () {
final response = FeedbackResponse.fromJson({
'success': true,
'message': 'Feedback retrieved successfully',
'data': {
'id': '458749877892354573',
'feedback_type': 'like',
'updated_at': 1759746927,
'created_at': 1759734023,
'tender_id': '8885737887b51b484',
'customer_id': '68d12cb1885171088a4baff5',
'company_id': '68c7fea825ff3fc682529856',
'tender': {
'id': '8885737887b51b484',
'notice_publication_id': '00532574-2025',
'publication_date': 1755122400000,
'title':
'Rámcová dohoda na výkon dozoru stavebníka na stavbách PK středního a menšího rozsahu 2025',
'description': 'Předmětem plnění veřejné zakázky ',
'procurement_type_code': 'services',
'procedure_code': 'open',
'estimated_value': 1200000000,
'currency': 'CZK',
'duration': '',
'duration_unit': '',
'tender_deadline': 1755727200000,
'submission_deadline': 1755468000000,
'country_code': 'CZE',
'buyer_organization': {'name': 'Ředitelství silnic a dálnic s. p.'},
'status': 'active',
},
'company': {'id': '68c7fea825ff3fc682529856', 'name': 'Opplens'},
},
});
final json = Map<String, dynamic>.from(response.toJson());
final data =
(json['data'] is Map)
? Map<String, dynamic>.from(json['data'])
: (response.data?.toJson() ?? {});
final tender =
(data['tender'] is Map)
? Map<String, dynamic>.from(data['tender'])
: (response.data?.tender?.toJson() ?? {});
final buyerOrg =
(tender['buyer_organization'] is Map)
? tender['buyer_organization'] as Map<String, dynamic>
: (response.data?.tender?.buyerOrganization?.toJson() ?? {});
expect(json['success'], true);
expect(json['message'], 'Feedback retrieved successfully');
expect(
tender['title'],
'Rámcová dohoda na výkon dozoru stavebníka na stavbách PK středního a menšího rozsahu 2025',
);
expect(buyerOrg['name'], 'Ředitelství silnic a dálnic s. p.');
});
test('equality and copyWith work as expected', () {
final response = FeedbackResponse.fromJson(mockJson);
final updated = response.copyWith(message: 'Updated');
expect(updated.message, 'Updated');
expect(updated != response, true);
});
});
}