92 lines
2.5 KiB
Dart
92 lines
2.5 KiB
Dart
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:travel_mate/models/expense.dart';
|
|
import 'package:travel_mate/models/expense_split.dart';
|
|
|
|
void main() {
|
|
group('Expense Model Tests', () {
|
|
const id = 'expense1';
|
|
const groupId = 'group1';
|
|
const description = 'Lunch';
|
|
const amount = 50.0;
|
|
const currency = ExpenseCurrency.eur;
|
|
const amountInEur = 50.0;
|
|
const category = ExpenseCategory.restaurant;
|
|
const paidById = 'user1';
|
|
const paidByName = 'Alice';
|
|
final date = DateTime(2023, 6, 1);
|
|
final createdAt = DateTime(2023, 6, 1);
|
|
const split = ExpenseSplit(
|
|
userId: 'user1',
|
|
userName: 'Alice',
|
|
amount: 25.0,
|
|
);
|
|
const splits = [
|
|
split,
|
|
ExpenseSplit(userId: 'user2', userName: 'Bob', amount: 25.0),
|
|
];
|
|
|
|
final expense = Expense(
|
|
id: id,
|
|
groupId: groupId,
|
|
description: description,
|
|
amount: amount,
|
|
currency: currency,
|
|
amountInEur: amountInEur,
|
|
category: category,
|
|
paidById: paidById,
|
|
paidByName: paidByName,
|
|
date: date,
|
|
createdAt: createdAt,
|
|
splits: splits,
|
|
);
|
|
|
|
test('supports value equality', () {
|
|
final expense2 = Expense(
|
|
id: id,
|
|
groupId: groupId,
|
|
description: description,
|
|
amount: amount,
|
|
currency: currency,
|
|
amountInEur: amountInEur,
|
|
category: category,
|
|
paidById: paidById,
|
|
paidByName: paidByName,
|
|
date: date,
|
|
createdAt: createdAt,
|
|
splits: splits,
|
|
);
|
|
expect(expense, equals(expense2));
|
|
});
|
|
|
|
group('fromMap', () {
|
|
test('parses correctly', () {
|
|
final map = {
|
|
'groupId': groupId,
|
|
'description': description,
|
|
'amount': amount,
|
|
'currency': 'EUR',
|
|
'amountInEur': amountInEur,
|
|
'category': 'restaurant', // matching category name
|
|
'paidById': paidById,
|
|
'paidByName': paidByName,
|
|
'date': Timestamp.fromDate(date),
|
|
'createdAt': Timestamp.fromDate(createdAt),
|
|
'splits': splits.map((s) => s.toMap()).toList(),
|
|
};
|
|
|
|
final fromMapExpense = Expense.fromMap(map, id);
|
|
expect(fromMapExpense, equals(expense));
|
|
});
|
|
});
|
|
|
|
group('copyWith', () {
|
|
test('updates fields correctly', () {
|
|
final updated = expense.copyWith(amount: 100.0);
|
|
expect(updated.amount, 100.0);
|
|
expect(updated.description, description);
|
|
});
|
|
});
|
|
});
|
|
}
|