forked from eatvio/eatvio_app
refactor(tests): update model instantiation to use const for improved performance
This commit is contained in:
85
test/features/my_finance/models/card_model_test.dart
Normal file
85
test/features/my_finance/models/card_model_test.dart
Normal file
@@ -0,0 +1,85 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
39
test/features/my_finance/models/payment_url_model_test.dart
Normal file
39
test/features/my_finance/models/payment_url_model_test.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:eatvio_app/features/my_finance/models/payment_url_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('PaymentUrlModel', () {
|
||||
test('fromJson - успешная десериализация', () {
|
||||
final json = {
|
||||
'paymentUrl': 'https://payment.example.com/checkout',
|
||||
};
|
||||
|
||||
final model = PaymentUrlModel.fromJson(json);
|
||||
|
||||
expect(model.paymentUrl, equals('https://payment.example.com/checkout'));
|
||||
});
|
||||
|
||||
test('toJson - успешная сериализация', () {
|
||||
final model = PaymentUrlModel(
|
||||
paymentUrl: 'https://payment.example.com/checkout',
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['paymentUrl'], equals('https://payment.example.com/checkout'));
|
||||
});
|
||||
|
||||
test('copyWith - создание копии с изменениями', () {
|
||||
final model = PaymentUrlModel(
|
||||
paymentUrl: 'https://payment.example.com/checkout',
|
||||
);
|
||||
|
||||
final updatedModel = model.copyWith(
|
||||
paymentUrl: 'https://payment.example.com/new',
|
||||
);
|
||||
|
||||
expect(updatedModel.paymentUrl, equals('https://payment.example.com/new'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user