Files
eatvio_app/test/features/my_finance/models/card_model_test.dart

86 lines
2.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:eatvio_app/features/my_finance/models/card_model.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('CardModel', () {
test('fromJson - успешная десериализация', () {
final json = {
'id': 1,
'bank_pan': '1234567890123456',
'is_default': true,
};
final card = CardModel.fromJson(json);
expect(card.id, equals(1));
expect(card.cardNumber, equals('1234567890123456'));
expect(card.isDefault, isTrue);
});
test('fromJson - is_default как int', () {
final json = {
'id': 1,
'bank_pan': '1234567890123456',
'is_default': 1,
};
final card = CardModel.fromJson(json);
expect(card.isDefault, isTrue);
});
test('fromJson - is_default как строка "1"', () {
final json = {
'id': 1,
'bank_pan': '1234567890123456',
'is_default': '1',
};
final card = CardModel.fromJson(json);
expect(card.isDefault, isTrue);
});
test('fromJson - is_default как false', () {
final json = {
'id': 1,
'bank_pan': '1234567890123456',
'is_default': false,
};
final card = CardModel.fromJson(json);
expect(card.isDefault, isFalse);
});
test('toJson - успешная сериализация', () {
final card = CardModel(
id: 1,
cardNumber: '1234567890123456',
isDefault: true,
);
final json = card.toJson();
expect(json['id'], equals(1));
expect(json['bank_pan'], equals('1234567890123456'));
expect(json['is_default'], isTrue);
});
test('copyWith - создание копии с изменениями', () {
final card = CardModel(
id: 1,
cardNumber: '1234567890123456',
isDefault: false,
);
final updatedCard = card.copyWith(isDefault: true);
expect(updatedCard.id, equals(1));
expect(updatedCard.cardNumber, equals('1234567890123456'));
expect(updatedCard.isDefault, isTrue);
});
});
}