295 lines
8.3 KiB
Dart
295 lines
8.3 KiB
Dart
import 'package:budget_app/models/category.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:budget_app/models/prefilled_transaction.dart';
|
|
import 'package:budget_app/models/ai_rule.dart';
|
|
import 'package:budget_app/models/ai_settings.dart';
|
|
|
|
/// Фабрика для создания тестовых объектов
|
|
|
|
class TestObjects {
|
|
// Тестовые категории
|
|
static Category createTestCategory({
|
|
String? id,
|
|
String name = 'Test Category',
|
|
String color = '#FF0000',
|
|
String icon = 'shopping_cart',
|
|
bool isIncome = false,
|
|
}) {
|
|
return Category(
|
|
id: id ?? 'test_category_id',
|
|
name: name,
|
|
color: Color(int.parse(color.replaceFirst('#', '0xFF'))),
|
|
icon: const IconData(0xe59c, fontFamily: 'MaterialIcons'), // shopping_cart icon
|
|
isIncome: isIncome,
|
|
);
|
|
}
|
|
|
|
static final Category shoppingCategory = createTestCategory(
|
|
id: 'shopping_cat',
|
|
name: 'Покупки',
|
|
color: '#4CAF50',
|
|
isIncome: false,
|
|
);
|
|
|
|
static final Category transportCategory = createTestCategory(
|
|
id: 'transport_cat',
|
|
name: 'Транспорт',
|
|
color: '#2196F3',
|
|
isIncome: false,
|
|
);
|
|
|
|
static final Category cashCategory = createTestCategory(
|
|
id: 'cash_cat',
|
|
name: 'Наличные',
|
|
color: '#FF9800',
|
|
isIncome: false,
|
|
);
|
|
|
|
static final Category salaryCategory = createTestCategory(
|
|
id: 'salary_cat',
|
|
name: 'Зарплата',
|
|
color: '#8BC34A',
|
|
isIncome: true,
|
|
);
|
|
|
|
static final Category foodCategory = createTestCategory(
|
|
id: 'food_cat',
|
|
name: 'Еда',
|
|
color: '#FF5722',
|
|
isIncome: false,
|
|
);
|
|
|
|
// Категории с английскими названиями для AI тестов
|
|
static final Category shoppingEnCategory = createTestCategory(
|
|
id: 'shopping_en_cat',
|
|
name: 'Shopping',
|
|
color: '#4CAF50',
|
|
isIncome: false,
|
|
);
|
|
|
|
static final Category transportEnCategory = createTestCategory(
|
|
id: 'transport_en_cat',
|
|
name: 'Transport',
|
|
color: '#2196F3',
|
|
isIncome: false,
|
|
);
|
|
|
|
static final Category foodEnCategory = createTestCategory(
|
|
id: 'food_en_cat',
|
|
name: 'Food',
|
|
color: '#FF5722',
|
|
isIncome: false,
|
|
);
|
|
|
|
// Тестовые PrefilledTransaction
|
|
static PrefilledTransaction createTransactionPrefilled({
|
|
String? smsMessageId,
|
|
String? transactionId,
|
|
double? amount,
|
|
String? salesPoint,
|
|
Category? calculatedCategory,
|
|
double confidence = 90.0,
|
|
String? exclusionRegex,
|
|
}) {
|
|
return PrefilledTransaction(
|
|
smsMessageId: smsMessageId ?? 'test_sms_${DateTime.now().millisecondsSinceEpoch}',
|
|
transactionId: transactionId,
|
|
amount: amount ?? -1250.0,
|
|
salesPoint: salesPoint ?? 'METRO CASH & CARRY',
|
|
calculatedCategory: calculatedCategory ?? shoppingCategory,
|
|
confidence: confidence,
|
|
exclusionRegex: exclusionRegex,
|
|
);
|
|
}
|
|
|
|
static PrefilledTransaction createNonTransactionPrefilled({
|
|
String? smsMessageId,
|
|
double confidence = 85.0,
|
|
String? exclusionRegex,
|
|
}) {
|
|
return PrefilledTransaction(
|
|
smsMessageId: smsMessageId ?? 'test_non_trans_${DateTime.now().millisecondsSinceEpoch}',
|
|
transactionId: null,
|
|
amount: null,
|
|
salesPoint: null,
|
|
calculatedCategory: null,
|
|
confidence: confidence,
|
|
exclusionRegex: exclusionRegex ?? '.*Специальное предложение.*кредит.*',
|
|
);
|
|
}
|
|
|
|
// Конкретные примеры PrefilledTransaction
|
|
static final PrefilledTransaction metroTransaction = createTransactionPrefilled(
|
|
smsMessageId: 'metro_sms_001',
|
|
amount: -1250.0,
|
|
salesPoint: 'METRO CASH & CARRY',
|
|
calculatedCategory: shoppingCategory,
|
|
confidence: 95.0,
|
|
);
|
|
|
|
static final PrefilledTransaction yandexTaxiTransaction = createTransactionPrefilled(
|
|
smsMessageId: 'taxi_sms_001',
|
|
amount: -890.5,
|
|
salesPoint: 'Яндекс.Такси',
|
|
calculatedCategory: transportCategory,
|
|
confidence: 98.0,
|
|
);
|
|
|
|
static final PrefilledTransaction salaryIncome = createTransactionPrefilled(
|
|
smsMessageId: 'salary_sms_001',
|
|
amount: 50000.0,
|
|
salesPoint: 'РАБОТОДАТЕЛЬ ООО',
|
|
calculatedCategory: salaryCategory,
|
|
confidence: 99.0,
|
|
);
|
|
|
|
static final PrefilledTransaction bankAdvertising = createNonTransactionPrefilled(
|
|
smsMessageId: 'bank_ad_001',
|
|
confidence: 85.0,
|
|
exclusionRegex: '.*Специальное предложение.*кредит.*\\d+.*годовых.*',
|
|
);
|
|
|
|
static final PrefilledTransaction megafonPromo = createNonTransactionPrefilled(
|
|
smsMessageId: 'megafon_promo_001',
|
|
confidence: 90.0,
|
|
exclusionRegex: '.*МЕГАФОН.*подарок.*БЕСПЛАТНО.*',
|
|
);
|
|
|
|
// Тестовые AiRule
|
|
static AiRule createPointOfSaleRule({
|
|
String? id,
|
|
String? name,
|
|
String? merchantPattern,
|
|
String? categoryId,
|
|
int confidence = 80,
|
|
bool isActive = true,
|
|
}) {
|
|
return AiRule(
|
|
id: id,
|
|
name: name ?? 'Автоправило для METRO',
|
|
type: AiRuleType.pointOfSale,
|
|
merchantPattern: merchantPattern ?? '.*METRO.*',
|
|
categoryId: categoryId ?? shoppingCategory.id,
|
|
confidencePercentage: confidence,
|
|
isActive: isActive,
|
|
);
|
|
}
|
|
|
|
static AiRule createSkipRule({
|
|
String? id,
|
|
String? name,
|
|
String? skipRegex,
|
|
int confidence = 80,
|
|
bool isActive = true,
|
|
}) {
|
|
return AiRule(
|
|
id: id,
|
|
name: name ?? 'Пропуск рекламы банка',
|
|
type: AiRuleType.skipTemplate,
|
|
skipRegex: skipRegex ?? '.*Специальное предложение.*кредит.*',
|
|
confidencePercentage: confidence,
|
|
isActive: isActive,
|
|
);
|
|
}
|
|
|
|
// Конкретные примеры AiRule
|
|
static final AiRule metroRule = createPointOfSaleRule(
|
|
id: 'metro_rule_001',
|
|
name: 'Автоправило для METRO CASH & CARRY',
|
|
merchantPattern: '.*METRO CASH & CARRY.*',
|
|
categoryId: shoppingCategory.id,
|
|
confidence: 95,
|
|
);
|
|
|
|
static final AiRule taxiRule = createPointOfSaleRule(
|
|
id: 'taxi_rule_001',
|
|
name: 'Автоправило для Яндекс.Такси',
|
|
merchantPattern: '.*Яндекс\\.Такси.*',
|
|
categoryId: transportCategory.id,
|
|
confidence: 98,
|
|
);
|
|
|
|
static final AiRule bankAdSkipRule = createSkipRule(
|
|
id: 'bank_ad_skip_001',
|
|
name: 'Пропуск рекламы кредитов',
|
|
skipRegex: '.*Специальное предложение.*кредит.*\\d+.*годовых.*',
|
|
confidence: 85,
|
|
);
|
|
|
|
static final AiRule promoSkipRule = createSkipRule(
|
|
id: 'promo_skip_001',
|
|
name: 'Пропуск промо от МЕГАФОН',
|
|
skipRegex: '.*МЕГАФОН.*подарок.*БЕСПЛАТНО.*',
|
|
confidence: 90,
|
|
);
|
|
|
|
// Тестовые настройки AI
|
|
static AiSettings createTestAiSettings({
|
|
String? apiKey,
|
|
String baseUrl = 'https://openrouter.ai/api/v1',
|
|
String defaultModel = 'openai/gpt-3.5-turbo',
|
|
int timeoutSeconds = 30,
|
|
double temperature = 0.1,
|
|
int maxTokens = 500,
|
|
bool isEnabled = true,
|
|
}) {
|
|
return AiSettings(
|
|
apiKey: apiKey ?? 'test_api_key_12345',
|
|
baseUrl: baseUrl,
|
|
defaultModel: defaultModel,
|
|
timeoutSeconds: timeoutSeconds,
|
|
temperature: temperature,
|
|
maxTokens: maxTokens,
|
|
isEnabled: isEnabled,
|
|
);
|
|
}
|
|
|
|
static final AiSettings defaultTestAiSettings = createTestAiSettings();
|
|
|
|
static final AiSettings disabledAiSettings = createTestAiSettings(
|
|
isEnabled: false,
|
|
);
|
|
|
|
static final AiSettings unconfiguredAiSettings = createTestAiSettings(
|
|
apiKey: null,
|
|
isEnabled: false,
|
|
);
|
|
|
|
// Списки объектов для массовых тестов
|
|
static final List<Category> testCategories = [
|
|
shoppingCategory,
|
|
transportCategory,
|
|
cashCategory,
|
|
salaryCategory,
|
|
foodCategory,
|
|
shoppingEnCategory,
|
|
transportEnCategory,
|
|
foodEnCategory,
|
|
];
|
|
|
|
static final List<PrefilledTransaction> testTransactionPrefilledList = [
|
|
metroTransaction,
|
|
yandexTaxiTransaction,
|
|
salaryIncome,
|
|
];
|
|
|
|
static final List<PrefilledTransaction> testNonTransactionPrefilledList = [
|
|
bankAdvertising,
|
|
megafonPromo,
|
|
];
|
|
|
|
static final List<AiRule> testPointOfSaleRules = [
|
|
metroRule,
|
|
taxiRule,
|
|
];
|
|
|
|
static final List<AiRule> testSkipRules = [
|
|
bankAdSkipRule,
|
|
promoSkipRule,
|
|
];
|
|
|
|
static final List<AiRule> testAllRules = [
|
|
...testPointOfSaleRules,
|
|
...testSkipRules,
|
|
];
|
|
} |