refactor(tests): update model instantiation to use const for improved performance

This commit is contained in:
mso7nueh
2025-12-03 06:16:34 +03:00
parent d0becb9e11
commit f3d4478c65
15 changed files with 1840 additions and 27 deletions

View 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);
});
});
}

View 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'));
});
});
}