73 lines
1.9 KiB
Dart
73 lines
1.9 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:lanebow/models/participant_model.dart';
|
|
|
|
void main() {
|
|
group('Participant.fromJson', () {
|
|
test('maps flat fields including isPaid true via paymentStatus', () {
|
|
final json = {
|
|
'id': 1,
|
|
'eventId': 10,
|
|
'memberId': 55,
|
|
'name': '홍길동',
|
|
'email': 'hong@example.com',
|
|
'phoneNumber': '010-1234-5678',
|
|
'status': 'confirmed',
|
|
'paymentStatus': 'paid',
|
|
'paidAmount': '15000',
|
|
'notes': '',
|
|
};
|
|
|
|
final p = Participant.fromJson(json);
|
|
expect(p.id, '1');
|
|
expect(p.eventId, '10');
|
|
expect(p.memberId, '55');
|
|
expect(p.name, '홍길동');
|
|
expect(p.email, 'hong@example.com');
|
|
expect(p.phoneNumber, '010-1234-5678');
|
|
expect(p.status, 'confirmed');
|
|
expect(p.isPaid, isTrue);
|
|
expect(p.paidAmount, 15000);
|
|
expect(p.notes, '');
|
|
});
|
|
|
|
test('maps nested Member fields and unpaid status', () {
|
|
final json = {
|
|
'id': '2',
|
|
'eventId': '11',
|
|
'memberId': '99',
|
|
'status': 'registered',
|
|
'paymentStatus': 'unpaid',
|
|
'Member': {
|
|
'name': '이순신',
|
|
'email': 'lee@example.com',
|
|
'phone': '010-0000-0000',
|
|
},
|
|
};
|
|
|
|
final p = Participant.fromJson(json);
|
|
expect(p.name, '이순신');
|
|
expect(p.email, 'lee@example.com');
|
|
expect(p.phoneNumber, '010-0000-0000');
|
|
expect(p.isPaid, isFalse);
|
|
});
|
|
|
|
test('keeps nulls when empty strings provided for optional fields', () {
|
|
final json = {
|
|
'id': '3',
|
|
'eventId': '12',
|
|
'memberId': '100',
|
|
'name': null,
|
|
'email': null,
|
|
'phone': null,
|
|
'status': null,
|
|
};
|
|
|
|
final p = Participant.fromJson(json);
|
|
expect(p.name, isNull);
|
|
expect(p.email, isNull);
|
|
expect(p.phoneNumber, isNull);
|
|
expect(p.status, isNull);
|
|
});
|
|
});
|
|
}
|