Files
tm_app/test/model/feedback_data_test.dart
T
AmirReza Jamali dde66521f6 Add Docker support and enhance data models for tender details
- Introduced a .dockerignore file to optimize Docker builds by excluding unnecessary files.
- Updated the Dockerfile to use a Flutter base image, enabling web builds for the application.
- Added new data models for `Lot` and `OrganizationAddress` to represent tender details more accurately.
- Enhanced the `Organization` model to include `companyId` and a nested `address` field.
- Updated the `TenderData` model to include new fields such as `noticeTypeCode`, `formType`, and `lots`, reflecting the API response structure.
- Regenerated necessary code for data models to ensure compatibility with the updated structures.
2026-06-03 13:32:42 +03:30

211 lines
6.6 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:tm_app/data/services/model/feedback_data/feedback_data.dart';
import 'package:tm_app/data/services/model/tender_data/tender_data.dart';
import 'package:tm_app/data/services/model/organization/organization.dart';
void main() {
group('FeedbackData Tests', () {
test('fromJson should parse JSON correctly', () {
final json = {
'company_id': 'COMP123',
'created_at': 1700000000,
'customer_id': 'CUST456',
'feedback_type': 'positive',
'id': 'FB001',
'tender_id': 'TND789',
'updated_at': 1750000000,
'tender': {
'success': true,
'message': 'ok',
'id': 'TND789',
'tender_id': 'TND789',
'notice_publication_id': 'NP123',
'publication_date': 1700000000,
'title': 'New Tender',
'description': 'Tender description',
'procurement_type_code': 'PT001',
'procedure_code': 'PRC001',
'estimated_value': 1000000,
'currency': 'USD',
'duration': '12',
'tender_deadline': 1710000000,
'submission_deadline': 1710000000,
'application_deadline': 1710000000,
'submission_url': 'https://example.com',
'country_code': 'IR',
'duration_unit': 'month',
'buyer_organization': {
'id': 'ORG001',
'name': 'Buyer Org',
},
'status': 'active',
},
};
final feedback = FeedbackData.fromJson(json);
expect(feedback.companyId, 'COMP123');
expect(feedback.feedbackType, 'positive');
expect(feedback.tender?.id, 'TND789');
expect(feedback.tender?.title, 'New Tender');
expect(feedback.tender?.buyerOrganization?.name, 'Buyer Org');
});
// AI-NOTE (for PR reviewer): These TenderData/Organization literals were
// updated only to satisfy the new required fields added to those models
// (notice_type_code, form_type, issue_date/time, lots, official_languages,
// company_id, address). Test assertions/behavior are unchanged.
test('toJson should return valid JSON map', () {
final tender = const TenderData(
success: true,
message: 'ok',
id: 'TND123',
tenderId: 'TND123',
noticePublicationId: 'NP123',
noticeTypeCode: 'cn-standard',
formType: 'competition',
noticeLanguageCode: 'ENG',
issueDate: 1700000000,
issueTime: 1700000000,
publicationDate: 1700000000,
title: 'Tender Title',
description: 'Some description',
procurementTypeCode: 'PROC001',
procedureCode: 'PROCEDURE1',
estimatedValue: 500000,
currency: 'USD',
duration: '6',
tenderDeadline: 1710000000,
submissionDeadline: 1715000000,
applicationDeadline: 1712000000,
submissionUrl: 'https://example.com',
countryCode: 'IR',
durationUnit: 'month',
buyerOrganization: Organization(
name: 'Test Organization',
companyId: 'ORG001',
address: null,
),
lots: null,
officialLanguages: null,
status: 'active',
);
final feedback = FeedbackData(
companyId: 'COMP001',
createdAt: 1700000000,
customerId: 'CUST001',
feedbackType: 'negative',
id: 'FB001',
tenderId: 'TND123',
tender: tender,
updatedAt: 1750000000,
);
final json = feedback.toJson();
expect(json['company_id'], 'COMP001');
expect(json['feedback_type'], 'negative');
final tenderJson = (json['tender'] as TenderData).toJson();
expect(tenderJson['id'], 'TND123');
expect(tenderJson['title'], 'Tender Title');
expect((tenderJson['buyer_organization'] as Organization).toJson()['name'], 'Test Organization');
});
test('copyWith should modify specific fields only', () {
final feedback = const FeedbackData(
companyId: 'COMP001',
createdAt: 1700000000,
customerId: 'CUST001',
feedbackType: 'neutral',
id: 'FB001',
tenderId: 'TND001',
tender: TenderData(
success: false,
message: 'fail',
id: 'TND001',
tenderId: 'TND001',
noticePublicationId: 'NP1',
noticeTypeCode: 'cn-standard',
formType: 'competition',
noticeLanguageCode: 'ENG',
issueDate: 1700000000,
issueTime: 1700000000,
publicationDate: 1700000000,
title: 'Old Tender',
description: 'Old desc',
procurementTypeCode: 'PT001',
procedureCode: 'PC001',
estimatedValue: 10000,
currency: 'USD',
duration: '3',
tenderDeadline: 1710000000,
submissionDeadline: 1715000000,
applicationDeadline: 1712000000,
submissionUrl: 'https://example.com',
countryCode: 'IR',
durationUnit: 'month',
buyerOrganization: Organization(
name: 'Old Org',
companyId: 'ORG001',
address: null,
),
lots: null,
officialLanguages: null,
status: 'inactive',
),
updatedAt: 1750000000,
);
final updated = feedback.copyWith(feedbackType: 'positive');
expect(updated.feedbackType, 'positive');
expect(updated.companyId, 'COMP001');
expect(updated.tender?.title, 'Old Tender');
});
test('fromJson handles null fields safely', () {
final json = {
'company_id': null,
'created_at': null,
'customer_id': null,
'feedback_type': null,
'id': null,
'tender_id': null,
'tender': null,
'updated_at': null,
};
final feedback = FeedbackData.fromJson(json);
expect(feedback.companyId, isNull);
expect(feedback.tender, isNull);
expect(feedback.feedbackType, isNull);
});
test('fromJson -> toJson round-trip should preserve data', () {
final json = {
'company_id': 'C1',
'feedback_type': 'positive',
'tender': {
'id': 'T1',
'title': 'Tender 1',
'success': true,
'buyer_organization': {
'id': 'O1',
'name': 'Org 1',
},
},
};
final feedback = FeedbackData.fromJson(json);
final output = feedback.toJson();
expect(output['company_id'], 'C1');
final tenderJson = (output['tender'] as TenderData).toJson();
expect(tenderJson['title'], 'Tender 1');
expect((tenderJson['buyer_organization'] as Organization).toJson() ['name'], 'Org 1');
});
});
}