Skip to content

Commit

Permalink
Shared - Blank Account Methods + Some Account Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Feb 15, 2024
1 parent 621077b commit c14abe9
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 7 deletions.
1 change: 1 addition & 0 deletions libdenaro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ endif()

if (BUILD_TESTING)
add_executable(libdenaro_test
"tests/accounttests.cpp"
"tests/colortests.cpp"
"tests/currencyconversiontests.cpp"
"tests/datetests.cpp"
Expand Down
10 changes: 3 additions & 7 deletions libdenaro/include/models/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ namespace Nickvision::Money::Shared::Models
* @param exportMode ExportMode
* @param filetedIds The list of transaction ids to use for ExportMode::CurrentView
*/
bool exportToCSV(const std::filesystem::path& path, ExportMode exportMode = ExportMode::All, std::vector<unsigned int> filteredIds = {});
bool exportToCSV(const std::filesystem::path& path, ExportMode exportMode = ExportMode::All, const std::vector<unsigned int>& filteredIds = {}) const;
/**
* @brief Exports the account to a PDF file.
* @param path The path to the PDF file
* @param password The password to use to lock the PDF file. Empty string for no password on the PDF file
* @param exportMode ExportMode
* @param filetedIds The list of transaction ids to use for ExportMode::CurrentView
*/
bool exportToCSV(const std::filesystem::path& path, const std::string& password, ExportMode exportMode = ExportMode::All, std::vector<unsigned int> filteredIds = {});
bool exportToPDF(const std::filesystem::path& path, const std::string& password, ExportMode exportMode = ExportMode::All, const std::vector<unsigned int>& filteredIds = {}) const;
/**
* @brief Generates a graph.
* @param type GraphType
Expand All @@ -236,18 +236,14 @@ namespace Nickvision::Money::Shared::Models
* @param showLegend Whether or not to show the graph's legend
* @return The byte vector of the graph image
*/
std::vector<std::uint8_t> generateGraph(GraphType type, bool darkMode, std::vector<unsigned int> filteredIds, int width = -1, int height = -1, bool showLegend = true);
std::vector<std::uint8_t> generateGraph(GraphType type, bool darkMode, const std::vector<unsigned int>& filteredIds, int width = -1, int height = -1, bool showLegend = true) const;
/**
* @brief Gets whether or not the object is valid or not.
* @return True if valid (m_loggedIn), else false
*/
operator bool() const;

private:
/**
* Populates the m_transactionReminders list.
*/
void calculateTransactionReminders();
/**
* @brief Imports transactions from a CSV file.
* @param path The path to the file to import
Expand Down
115 changes: 115 additions & 0 deletions libdenaro/src/models/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,86 @@ namespace Nickvision::Money::Shared::Models
m_database.changePassword(password);
}

double Account::getIncome(const std::vector<unsigned int>& transactionIds) const
{
return 0.0;
}

double Account::getExpense(const std::vector<unsigned int>& transactionIds) const
{
return 0.0;
}

double Account::getTotal(const std::vector<unsigned int>& transactionIds) const
{
return 0.0;
}

double Account::getGroupIncome(const Group& group, const std::vector<unsigned int>& transactionIds) const
{
return 0.0;
}

double Account::getGroupExpense(const Group& group, const std::vector<unsigned int>& transactionIds) const
{
return 0.0;
}

double Account::getGroupTotal(const Group& group, const std::vector<unsigned int>& transactionIds) const
{
return 0.0;
}

bool Account::addGroup(const Group& group)
{
return false;
}

bool Account::updateGroup(const Group& group)
{
return false;
}

std::pair<bool, std::vector<unsigned int>> Account::deleteGroup(unsigned int id)
{
return { false, {} };
}

std::pair<bool, std::vector<std::string>> Account::addTransaction(const Transaction& transaction)
{
return { false, {} };
}

std::pair<bool, std::vector<std::string>> Account::updateTransaction(const Transaction& transaction)
{
return { false, {} };
}

std::pair<bool, std::vector<std::string>> Account::updateSourceTransaction(const Transaction& transaction, bool updateGenerated)
{
return { false, {} };
}

bool Account::deleteTransaction(unsigned int id)
{
return false;
}

bool Account::deleteSourceTransaction(unsigned int id, bool deleteGenerated)
{
return false;
}

bool Account::deleteGeneratedTransactions(unsigned int sourceId)
{
return false;
}

bool Account::syncRepeatTransactions()
{
return false;
}

std::optional<Transaction> Account::sendTransfer(const Transfer& transfer, const Color& color)
{
if(!m_loggedIn || transfer.getSourceAccountPath() != m_path)
Expand Down Expand Up @@ -274,6 +354,41 @@ namespace Nickvision::Money::Shared::Models
return income;
}

ImportResult Account::importFromFile(const std::filesystem::path& path, const Color& defaultTransactionColor, const Color& defaultGroupColor)
{
return {};
}

bool Account::exportToCSV(const std::filesystem::path& path, ExportMode exportMode, const std::vector<unsigned int>& filteredIds) const
{
return false;
}

bool Account::exportToPDF(const std::filesystem::path& path, const std::string& password, ExportMode exportMode, const std::vector<unsigned int>& filteredIds) const
{
return false;
}

std::vector<std::uint8_t> Account::generateGraph(GraphType type, bool darkMode, const std::vector<unsigned int>& filteredIds, int width, int height, bool showLegend) const
{
return {};
}

ImportResult Account::importFromCSV(const std::filesystem::path& path, const Color& defaultTransactionColor, const Color& defaultGroupColor)
{
return {};
}

ImportResult Account::importFromOFX(const std::filesystem::path& path, const Color& defaultTransactionColor)
{
return {};
}

ImportResult Account::importFromQIF(const std::filesystem::path& path, const Color& defaultTransactionColor, const Color& defaultGroupColor)
{
return {};
}

Account::operator bool() const
{
return m_loggedIn;
Expand Down
33 changes: 33 additions & 0 deletions libdenaro/tests/accounttests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <gtest/gtest.h>
#include <filesystem>
#include <memory>
#include "models/account.h"

using namespace Nickvision::Money::Shared::Models;

class AccountTest : public testing::Test
{
public:
static std::filesystem::path m_accountPath;
static std::unique_ptr<Account> m_account;

static void SetUpTestSuite()
{
m_account = std::make_unique<Account>(m_accountPath);
}

static void TearDownTestSuite()
{
m_account.reset();
std::filesystem::remove(m_accountPath);
}
};

TEST_F(AccountTest, Login)
{
ASSERT_FALSE(m_account->isEncrypted());
ASSERT_TRUE(m_account->login(""));
}

std::filesystem::path AccountTest::m_accountPath = "account.nmoney";
std::unique_ptr<Account> AccountTest::m_account = nullptr;

0 comments on commit c14abe9

Please sign in to comment.