Skip to content

Commit

Permalink
added recurring trns highlight, fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikev-cw committed May 7, 2024
1 parent ce0294d commit 314c4ce
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 124 deletions.
2 changes: 2 additions & 0 deletions lib/custom_widgets/transactions_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ class TransactionRow extends ConsumerWidget with Functions {
const SizedBox(height: 11),
Row(
children: [
if (transaction.recurring) // Check if the transaction is recurring
const Icon(Icons.repeat, color: Colors.blueAccent), // Add an icon for recurring transactions
if (transaction.note != null)
Text(
transaction.note!,
Expand Down
10 changes: 5 additions & 5 deletions lib/database/sossoldi_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class SossoldiDatabase {
(13, "Shopping", "shopping_cart", 3, '', null, '${DateTime.now()}', '${DateTime.now()}'),
(14, "Leisure", "subscriptions", 4, '', null, '${DateTime.now()}', '${DateTime.now()}'),
(15, "Salary", "work", 5, '', null, '${DateTime.now()}', '${DateTime.now()}'),
(16, "Transports", "directions_car", 6, '', null, '${DateTime.now()}', '${DateTime.now()}');
(16, "Transports", "directions_car_rounded", 6, '', null, '${DateTime.now()}', '${DateTime.now()}');
''');

// Add currencies
Expand All @@ -171,14 +171,14 @@ class SossoldiDatabase {
// Add fake budgets
await _database?.execute('''
INSERT INTO budget(idCategory, name, amountLimit, active, createdAt, updatedAt) VALUES
(13, "Grocery", 400.00, 1, '${DateTime.now()}', '${DateTime.now()}'),
(13, "Grocery", 900.00, 1, '${DateTime.now()}', '${DateTime.now()}'),
(11, "Home", 123.45, 0, '${DateTime.now()}', '${DateTime.now()}');
''');

// Add fake recurring transactions
await _database?.execute('''
INSERT INTO recurringTransaction(fromDate, toDate, amount, note, recurrency, idCategory, idBankAccount, createdAt, updatedAt) VALUES
("2024-02-23", null, 10.99, "Spotify", "MONTHLY", 14, 70, '${DateTime.now()}', '${DateTime.now()}'),
("2024-02-23", null, 10.99, "404 Books", "MONTHLY", 14, 70, '${DateTime.now()}', '${DateTime.now()}'),
("2023-12-13", null, 4.97, "ETF Consultant Parcel", "DAILY", 14, 70, '${DateTime.now()}', '${DateTime.now()}'),
("2023-02-11", "2028-02-11", 1193.40, "Car Loan", "QUARTERLY", 16, 72, '${DateTime.now()}', '${DateTime.now()}');
''');
Expand All @@ -187,7 +187,7 @@ class SossoldiDatabase {
// First initialize some config stuff
final rnd = Random();
var accounts = [70,71,72];
var outNotes = ['Grocery', 'Tolls', 'Toys', 'ETF Consultant Parcel', 'Concert', 'Clothing', 'Pizza', 'Drugs', 'Laundry', 'Taxes', 'Health insurance', 'Furniture', 'Car Fuel', 'Train', 'Amazon', 'Delivery', 'CHEK dividends', 'Babysitter', 'sono.pove.ro Fees', 'Quingentole trip'];
var outNotes = ['Grocery', 'Tolls', 'Toys', 'Boardgames', 'Concert', 'Clothing', 'Pizza', 'Drugs', 'Laundry', 'Taxes', 'Health insurance', 'Furniture', 'Car Fuel', 'Train', 'Amazon', 'Delivery', 'CHEK dividends', 'Babysitter', 'sono.pove.ro Fees', 'Quingentole trip'];
var categories = [10,11,12,13,14];
double maxAmountOfSingleTransaction = 250.00;
int dateInPastMaxRange = (countOfGeneratedTransaction / 90 ).round() * 30; // we want simulate about 90 transactions per month
Expand Down Expand Up @@ -282,7 +282,7 @@ class SossoldiDatabase {
await batch.commit();
});
} catch(error){
// throw Exception('DbBase.cleanDatabase: $error');
throw Exception('DbBase.cleanDatabase: $error');
}
}

Expand Down
5 changes: 2 additions & 3 deletions lib/model/recurring_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Map<String, dynamic> recurrenciesMap = {
'amount': 3
},
'SEMESTER': {
'label': 'Semester',
'label': 'Half Yearly',
'entity': 'months',
'amount': 6
},
Expand Down Expand Up @@ -350,8 +350,7 @@ class RecurringTransactionMethods extends SossoldiDatabase {
return;
}

if (transaction.toDate?.isAfter(lastTransactionDate) ?? true) {
// TODO no future dates
if ((transaction.toDate?.isAfter(lastTransactionDate) ?? true) && lastTransactionDate.isBefore(DateTime.now())) {
transactions2Add.add(lastTransactionDate);
}

Expand Down
6 changes: 3 additions & 3 deletions test/model/bank_account_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void main() {

sossoldiDatabase = SossoldiDatabase(dbName: 'test.db');
db = await sossoldiDatabase.database;
await sossoldiDatabase.clearDatabase();
await sossoldiDatabase.resetDatabase();
});

tearDown(() async => {
Expand All @@ -121,7 +121,7 @@ void main() {
var transactions = await db.rawQuery("SELECT * FROM `transaction`");
expect(0, transactions.length);

const insertDemoTransactionsQuery = '''INSERT INTO `transaction` (date, amount, type, note, idCategory, idBankAccount, idBankAccountTransfer, recurring, recurrencyType, recurrencyPayDay, recurrencyFrom, recurrencyTo, createdAt, updatedAt) VALUES ''';
const insertDemoTransactionsQuery = '''INSERT INTO `transaction` (date, amount, type, note, idCategory, idBankAccount, idBankAccountTransfer, recurring, idRecurringTransaction, createdAt, updatedAt) VALUES ''';
final List<String> demoTransactions = [];

final today = DateTime.now();
Expand Down Expand Up @@ -187,7 +187,7 @@ void main() {
var transactions = await db.rawQuery("SELECT * FROM `transaction`");
expect(0, transactions.length);

const insertDemoTransactionsQuery = '''INSERT INTO `transaction` (date, amount, type, note, idCategory, idBankAccount, idBankAccountTransfer, recurring, recurrencyType, recurrencyPayDay, recurrencyFrom, recurrencyTo, createdAt, updatedAt) VALUES ''';
const insertDemoTransactionsQuery = '''INSERT INTO `transaction` (date, amount, type, note, idCategory, idBankAccount, idBankAccountTransfer, recurring, idRecurringTransaction, createdAt, updatedAt) VALUES ''';
final List<String> demoTransactions = [];

final today = DateTime.now();
Expand Down
81 changes: 0 additions & 81 deletions test/model/recurring_transaction_amount_test.dart

This file was deleted.

89 changes: 89 additions & 0 deletions test/model/recurring_transaction_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import 'package:flutter_test/flutter_test.dart';

import 'package:sossoldi/model/recurring_transaction.dart';
import 'package:sossoldi/model/base_entity.dart';

void main() {
test('Test Copy Recurring Transaction Amount', () {
RecurringTransaction t = RecurringTransaction(
id: 2,
fromDate: DateTime.utc(2022),
toDate: DateTime.utc(2023),
amount: 14,
note: 'Test Transaction',
recurrency: 'MONTHLY',
idBankAccount: 34,
idCategory: 24,
createdAt: DateTime.utc(2022),
updatedAt: DateTime.utc(2022)
);

RecurringTransaction tCopy = t.copy(id: 10);

assert(tCopy.id == 10);
assert(tCopy.fromDate == t.fromDate);
assert(tCopy.toDate == t.toDate);
assert(tCopy.amount == t.amount);
assert(tCopy.note == t.note);
assert(tCopy.recurrency == t.recurrency);
assert(tCopy.idBankAccount == t.idBankAccount);
assert(tCopy.idCategory == t.idCategory);
assert(tCopy.createdAt == t.createdAt);
assert(tCopy.updatedAt == t.updatedAt);
});

test("Test fromJson Recurring Transaction Amount", () {
Map<String, Object?> json = {
BaseEntityFields.id: 0,
RecurringTransactionFields.fromDate: DateTime.utc(2022).toIso8601String(),
RecurringTransactionFields.toDate: DateTime.utc(2023).toIso8601String(),
RecurringTransactionFields.amount: 50,
RecurringTransactionFields.note: "Test Transaction",
RecurringTransactionFields.recurrency: "WEEKLY",
RecurringTransactionFields.idBankAccount: 44,
RecurringTransactionFields.idCategory: 4,
BaseEntityFields.createdAt: DateTime.utc(2022).toIso8601String(),
BaseEntityFields.updatedAt: DateTime.utc(2022).toIso8601String(),
};

RecurringTransaction t = RecurringTransaction.fromJson(json);

assert(t.id == json[BaseEntityFields.id]);
assert(t.fromDate.toUtc().toIso8601String() == json[RecurringTransactionFields.fromDate]);
assert(t.toDate?.toUtc().toIso8601String() == json[RecurringTransactionFields.toDate]);
assert(t.amount == json[RecurringTransactionFields.amount]);
assert(t.note == json[RecurringTransactionFields.note]);
assert(t.recurrency == json[RecurringTransactionFields.recurrency]);
assert(t.idBankAccount == json[RecurringTransactionFields.idBankAccount]);
assert(t.idCategory == json[RecurringTransactionFields.idCategory]);
assert(t.createdAt?.toUtc().toIso8601String() == json[BaseEntityFields.createdAt]);
assert(t.updatedAt?.toUtc().toIso8601String() == json[BaseEntityFields.updatedAt]);
});

test("Test toJson Recurring Transaction Amount", () {
RecurringTransaction t = RecurringTransaction(
id: 2,
fromDate: DateTime.utc(2022),
toDate: DateTime.utc(2023),
amount: 0,
note: "Test transaction",
recurrency: "MONTHLY",
idBankAccount: 4,
idCategory: 45,
createdAt: DateTime.utc(2022),
updatedAt: DateTime.utc(2022));

Map<String, Object?> json = t.toJson();

assert(t.id == json[BaseEntityFields.id]);
assert(t.fromDate.toUtc().toIso8601String() == json[RecurringTransactionFields.fromDate]);
assert(t.toDate?.toUtc().toIso8601String() == json[RecurringTransactionFields.toDate]);
assert(t.amount == json[RecurringTransactionFields.amount]);
assert(t.note == json[RecurringTransactionFields.note]);
assert(t.recurrency == json[RecurringTransactionFields.recurrency]);
assert(t.idBankAccount == json[RecurringTransactionFields.idBankAccount]);
assert(t.idCategory == json[RecurringTransactionFields.idCategory]);
assert(t.createdAt?.toUtc().toIso8601String() == json[BaseEntityFields.createdAt]);
assert(t.updatedAt?.toUtc().toIso8601String() == json[BaseEntityFields.updatedAt]);
});
}
43 changes: 13 additions & 30 deletions test/model/transaction_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,25 @@ void main() {
idBankAccount: 0,
idBankAccountTransfer: null,
recurring: false,
recurrencyType: null,
recurrencyPayDay: null,
recurrencyFrom: null,
recurrencyTo: null,
idRecurringTransaction: null,
idCategory: 1,
createdAt: DateTime.utc(2022),
updatedAt: DateTime.utc(2022));
updatedAt: DateTime.utc(2022)
);

Transaction tCopy = t.copy(id: 10);

assert(tCopy.id == 10);
assert(tCopy.date == t.date);
assert(tCopy.amount == t.amount);
assert(tCopy.date == t.date);
assert(tCopy.note == t.note);
assert(tCopy.type == t.type);
assert(tCopy.note == t.note);
assert(tCopy.idBankAccount == t.idBankAccount);
assert(tCopy.idCategory == t.idCategory);
assert(tCopy.idBankAccountTransfer == t.idBankAccountTransfer);
assert(tCopy.recurring == t.recurring);
assert(tCopy.recurrencyType == t.recurrencyType);
assert(tCopy.recurrencyPayDay == t.recurrencyPayDay);
assert(tCopy.recurrencyFrom == t.recurrencyFrom);
assert(tCopy.recurrencyTo == t.recurrencyTo);
assert(tCopy.idRecurringTransaction == t.idRecurringTransaction);
assert(tCopy.createdAt == t.createdAt);
assert(tCopy.updatedAt == t.updatedAt);
});
Expand All @@ -61,10 +56,7 @@ void main() {
TransactionFields.idCategory: 0,
TransactionFields.idBankAccountTransfer: null,
TransactionFields.recurring: false,
TransactionFields.recurrencyType: null,
TransactionFields.recurrencyPayDay: null,
TransactionFields.recurrencyFrom: null,
TransactionFields.recurrencyTo: null,
TransactionFields.idRecurringTransaction: null,
BaseEntityFields.createdAt: DateTime.utc(2022).toIso8601String(),
BaseEntityFields.updatedAt: DateTime.utc(2022).toIso8601String(),
};
Expand All @@ -79,10 +71,7 @@ void main() {
assert(t.idBankAccount == json[TransactionFields.idBankAccount]);
assert(t.idBankAccountTransfer == json[TransactionFields.idBankAccountTransfer]);
assert(t.recurring == json[TransactionFields.recurring]);
assert(t.recurrencyType == json[TransactionFields.recurrencyType]);
assert(t.recurrencyPayDay == json[TransactionFields.recurrencyPayDay]);
assert(t.recurrencyFrom == json[TransactionFields.recurrencyFrom]);
assert(t.recurrencyTo == json[TransactionFields.recurrencyTo]);
assert(t.idRecurringTransaction == json[TransactionFields.idRecurringTransaction]);
assert(t.idCategory == json[TransactionFields.idCategory]);
assert(t.createdAt?.toUtc().toIso8601String() ==
json[BaseEntityFields.createdAt]);
Expand All @@ -101,10 +90,7 @@ void main() {
idBankAccount: 0,
idBankAccountTransfer: null,
recurring: false,
recurrencyType: null,
recurrencyPayDay: null,
recurrencyFrom: null,
recurrencyTo: null
idRecurringTransaction: null
);

Map<String, Object?> json = t.toJson();
Expand All @@ -118,10 +104,7 @@ void main() {
assert(t.idBankAccount == json[TransactionFields.idBankAccount]);
assert(t.idBankAccountTransfer == json[TransactionFields.idBankAccountTransfer]);
assert((t.recurring ? 1 : 0) == json[TransactionFields.recurring]);
assert(t.recurrencyType == json[TransactionFields.recurrencyType]);
assert(t.recurrencyPayDay == json[TransactionFields.recurrencyPayDay]);
assert(t.recurrencyFrom == json[TransactionFields.recurrencyFrom]);
assert(t.recurrencyTo == json[TransactionFields.recurrencyTo]);
assert(t.idRecurringTransaction == json[TransactionFields.idRecurringTransaction]);
});

group("Transaction Methods", () {
Expand Down Expand Up @@ -158,7 +141,7 @@ void main() {
throw Exception('DbBase.cleanDatabase: $error');
}

const insertDemoTransactionsQuery = '''INSERT INTO `transaction` (date, amount, type, note, idCategory, idBankAccount, idBankAccountTransfer, recurring, recurrencyType, recurrencyPayDay, recurrencyFrom, recurrencyTo, createdAt, updatedAt) VALUES ''';
const insertDemoTransactionsQuery = '''INSERT INTO `transaction` (date, amount, type, note, idCategory, idBankAccount, idBankAccountTransfer, recurring, idRecurringTransaction, createdAt, updatedAt) VALUES ''';
final List<String> demoTransactions = [];

final today = DateTime.now();
Expand Down Expand Up @@ -211,7 +194,7 @@ void main() {
throw Exception('DbBase.cleanDatabase: $error');
}

const insertDemoTransactionsQuery = '''INSERT INTO `transaction` (date, amount, type, note, idCategory, idBankAccount, idBankAccountTransfer, recurring, recurrencyType, recurrencyPayDay, recurrencyFrom, recurrencyTo, createdAt, updatedAt) VALUES ''';
const insertDemoTransactionsQuery = '''INSERT INTO `transaction` (date, amount, type, note, idCategory, idBankAccount, idBankAccountTransfer, recurring, idRecurringTransaction, createdAt, updatedAt) VALUES ''';
final List<String> demoTransactions = [];

final today = DateTime.now();
Expand Down Expand Up @@ -264,7 +247,7 @@ void main() {
throw Exception('DbBase.cleanDatabase: $error');
}

const insertDemoTransactionsQuery = '''INSERT INTO `transaction` (date, amount, type, note, idCategory, idBankAccount, idBankAccountTransfer, recurring, recurrencyType, recurrencyPayDay, recurrencyFrom, recurrencyTo, createdAt, updatedAt) VALUES ''';
const insertDemoTransactionsQuery = '''INSERT INTO `transaction` (date, amount, type, note, idCategory, idBankAccount, idBankAccountTransfer, recurring, idRecurringTransaction, createdAt, updatedAt) VALUES ''';
final List<String> demoTransactions = [];

final today = DateTime.now();
Expand Down Expand Up @@ -322,7 +305,7 @@ void main() {
throw Exception('DbBase.cleanDatabase: $error');
}

const insertDemoTransactionsQuery = '''INSERT INTO `transaction` (date, amount, type, note, idCategory, idBankAccount, idBankAccountTransfer, recurring, recurrencyType, recurrencyPayDay, recurrencyFrom, recurrencyTo, createdAt, updatedAt) VALUES ''';
const insertDemoTransactionsQuery = '''INSERT INTO `transaction` (date, amount, type, note, idCategory, idBankAccount, idBankAccountTransfer, recurring, idRecurringTransaction, createdAt, updatedAt) VALUES ''';
final List<String> demoTransactions = [];

final today = DateTime.now();
Expand Down
Loading

0 comments on commit 314c4ce

Please sign in to comment.