diff --git a/src/Accounts/Account.h b/src/Accounts/Account.h index 1a977f1..9dca5cd 100644 --- a/src/Accounts/Account.h +++ b/src/Accounts/Account.h @@ -1,7 +1,7 @@ #ifndef ACCOUNT_H #define ACCOUNT_H #include -#include +#include class Account { protected: diff --git a/src/Accounts/AccountFactory.cpp b/src/Accounts/AccountFactory.cpp index 31019b2..607cb4b 100644 --- a/src/Accounts/AccountFactory.cpp +++ b/src/Accounts/AccountFactory.cpp @@ -1,4 +1,5 @@ #include +#include #include #include diff --git a/src/Accounts/AccountFactory.h b/src/Accounts/AccountFactory.h index 71f6099..91d166a 100644 --- a/src/Accounts/AccountFactory.h +++ b/src/Accounts/AccountFactory.h @@ -5,6 +5,7 @@ #include #include +#include class AccountFactory { public: diff --git a/src/Accounts/BankAccount.cpp b/src/Accounts/BankAccount.cpp index 5ec356d..5a804b6 100644 --- a/src/Accounts/BankAccount.cpp +++ b/src/Accounts/BankAccount.cpp @@ -1,3 +1,4 @@ +#include #include #include diff --git a/src/Accounts/BankAccount.h b/src/Accounts/BankAccount.h index c15e4ac..166efb1 100644 --- a/src/Accounts/BankAccount.h +++ b/src/Accounts/BankAccount.h @@ -1,7 +1,7 @@ #ifndef BANKACCOUNT_H #define BANKACCOUNT_H #include - +#include class BankAccount final : public Account { std::string IBAN; diff --git a/src/Accounts/EmailAccount.cpp b/src/Accounts/EmailAccount.cpp index 8d38682..1716f0b 100644 --- a/src/Accounts/EmailAccount.cpp +++ b/src/Accounts/EmailAccount.cpp @@ -1,3 +1,4 @@ +#include #include #include diff --git a/src/Accounts/EmailAccount.h b/src/Accounts/EmailAccount.h index 5fce37e..76af7d8 100644 --- a/src/Accounts/EmailAccount.h +++ b/src/Accounts/EmailAccount.h @@ -1,7 +1,7 @@ #ifndef EMAILACCOUNT_H #define EMAILACCOUNT_H #include - +#include class EmailAccount final : public Account { std::string emailAddress; diff --git a/src/Accounts/SocialMediaAccount.cpp b/src/Accounts/SocialMediaAccount.cpp index dfb0eba..441b1db 100644 --- a/src/Accounts/SocialMediaAccount.cpp +++ b/src/Accounts/SocialMediaAccount.cpp @@ -1,3 +1,4 @@ +#include #include #include diff --git a/src/Accounts/SocialMediaAccount.h b/src/Accounts/SocialMediaAccount.h index f4ca574..502260c 100644 --- a/src/Accounts/SocialMediaAccount.h +++ b/src/Accounts/SocialMediaAccount.h @@ -1,7 +1,7 @@ #ifndef SOCIALMEDIAACCOUNT_H #define SOCIALMEDIAACCOUNT_H #include - +#include class SocialMediaAccount final : public Account { std::string platform; std::string profileUrl; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cef2eb1..d08e8c0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,10 +19,7 @@ add_library(${PROJECT_NAME}_lib Accounts/SocialMediaAccount.cpp Accounts/AccountFactory.cpp Accounts/AccountFactory.h - Utils/VectorPlusTemplate.cpp - Utils/AccountType.cpp Utils/AddAccountCommandTemplate.cpp - Utils/ShowAccountsCommand.cpp ) target_include_directories(${PROJECT_NAME}_lib SYSTEM PRIVATE diff --git a/src/Database/Database.cpp b/src/Database/Database.cpp index 3da9b49..796e80e 100644 --- a/src/Database/Database.cpp +++ b/src/Database/Database.cpp @@ -1,13 +1,14 @@ -#include "Database.h" +#include #include -#include #include #include +#include #include +#include #include #include -#include "../Utils/VectorPlusTemplate.cpp" +#include std::string Database::connString; diff --git a/src/Utils/AccountType.cpp b/src/Utils/AccountType.h similarity index 71% rename from src/Utils/AccountType.cpp rename to src/Utils/AccountType.h index ac166dc..bd70020 100644 --- a/src/Utils/AccountType.cpp +++ b/src/Utils/AccountType.h @@ -1,4 +1,7 @@ -#include +#ifndef ACCOUNTTYPE_H +#define ACCOUNTTYPE_H + +#include enum class AccountType { BankAccountType, @@ -6,7 +9,7 @@ enum class AccountType { SocialMediaAccountType }; -constexpr std::string getAccountTypeString(const AccountType &accountType) { +constexpr std::string_view getAccountTypeString(const AccountType& accountType) { switch (accountType) { case AccountType::BankAccountType: return "Bank Account"; @@ -18,3 +21,5 @@ constexpr std::string getAccountTypeString(const AccountType &accountType) { return "Unknown Account Type"; } } + +#endif //ACCOUNTTYPE_H diff --git a/src/Utils/ShowAccountsCommand.cpp b/src/Utils/ShowAccountsCommand.h similarity index 76% rename from src/Utils/ShowAccountsCommand.cpp rename to src/Utils/ShowAccountsCommand.h index 21ea196..e395124 100644 --- a/src/Utils/ShowAccountsCommand.cpp +++ b/src/Utils/ShowAccountsCommand.h @@ -1,19 +1,24 @@ +#ifndef SHOWACCOUNTSCOMMAND_H +#define SHOWACCOUNTSCOMMAND_H + +#include #include #include - namespace ShowAccountsCommands { template void showAccountsCommand() { for (const auto &database = Database::getDatabaseInstance(); const auto &account: database.getAccountsByType(T)) { account->show(); - } + } std::cout << "---------------------------------\n"; - } + } ; - void showAllAccounts() { + inline void showAllAccounts() { showAccountsCommand(); showAccountsCommand(); showAccountsCommand(); } } + +#endif //SHOWACCOUNTSCOMMAND_H diff --git a/src/Utils/VectorPlusTemplate.cpp b/src/Utils/VectorUtils.h similarity index 78% rename from src/Utils/VectorPlusTemplate.cpp rename to src/Utils/VectorUtils.h index 9cd17b9..0f72342 100644 --- a/src/Utils/VectorPlusTemplate.cpp +++ b/src/Utils/VectorUtils.h @@ -1,10 +1,15 @@ +#ifndef VECTORUTILS_H +#define VECTORUTILS_H + #include template -std::vector operator+(const std::vector &lhs, const std::vector &rhs) { +std::vector operator+(const std::vector &lhs, const std::vector &rhs){ std::vector result; result.reserve(lhs.size() + rhs.size()); result.insert(result.end(), lhs.begin(), lhs.end()); result.insert(result.end(), rhs.begin(), rhs.end()); return result; } + +#endif //VECTORUTILS_H diff --git a/src/main.cpp b/src/main.cpp index 3d8874b..4843965 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,13 +2,13 @@ #include #include -#include "AddAccountCommandTemplate.h" -#include "ShowAccountsCommand.cpp" -#include "Database/Database.h" +#include +#include +#include -#include "Database/Auth.h" -#include "EnvironmentReader/EnvironmentReader.h" -#include "Logger/Logger.h" +#include +#include +#include void initializeDatabase() { auto &logger = Logger::getInstance(); diff --git a/tests/AccountTestNotLoggedIn.cpp b/tests/AccountTestNotLoggedIn.cpp index 3033094..e3ebb7d 100644 --- a/tests/AccountTestNotLoggedIn.cpp +++ b/tests/AccountTestNotLoggedIn.cpp @@ -1,7 +1,16 @@ #include #include +#include +#include -TEST(AccountTest, noBankAccountCreatedWhenNotLoggedIn) { +class AccountTestNotLoggedIn : public ::testing::Test { +protected: + static void SetUpTestSuite() { + User::setCurrentUserId(-1); + } +}; + +TEST_F(AccountTestNotLoggedIn, noBankAccountCreatedWhenNotLoggedIn) { const auto bankAccountFactory = AccountFactory::accountFactory(AccountType::BankAccountType, { @@ -11,7 +20,7 @@ TEST(AccountTest, noBankAccountCreatedWhenNotLoggedIn) { ASSERT_THROW(bankAccountFactory->addAccount(), std::exception); } -TEST(AccountTest, noEmailAccountCreatedWhenNotLoggedIn) { +TEST_F(AccountTestNotLoggedIn, noEmailAccountCreatedWhenNotLoggedIn) { const auto emailAccountFactory = AccountFactory::accountFactory(AccountType::EmailAccountType, {{"username", "sebi1"},{"password","1234"}, {"emailAddress", "123412412"}, {"mailProvider", "bt"} @@ -19,7 +28,7 @@ TEST(AccountTest, noEmailAccountCreatedWhenNotLoggedIn) { ASSERT_THROW(emailAccountFactory->addAccount(), std::exception); } -TEST(AccountTest, noSocialMediaAccountCreatedWhenNotLoggedIn) { +TEST_F(AccountTestNotLoggedIn, noSocialMediaAccountCreatedWhenNotLoggedIn) { const auto socialMediaAccountFactory = AccountFactory::accountFactory(AccountType::SocialMediaAccountType, {{"username", "sebi1"},{"password","1234"}, diff --git a/tests/VectorPlusTest.cpp b/tests/VectorPlusTest.cpp index 372c2a9..cc5ad07 100644 --- a/tests/VectorPlusTest.cpp +++ b/tests/VectorPlusTest.cpp @@ -1,9 +1,9 @@ #include -#include -#include +#include #include -#include "AccountFactory.h" +#include +#include TEST(VectorPlusTest, IntTest) { const std::vector v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};