Skip to content

Commit

Permalink
Update account_test.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
jprzimba committed Dec 17, 2024
1 parent 904508f commit af2e3da
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions tests/unit/account/account_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////

#include "pch.hpp"

#include <boost/ut.hpp>
Expand Down Expand Up @@ -48,13 +49,13 @@ suite<"account"> accountTest = [] {

test("Account::Account default constructors") = [] {
shared_ptr<Account> byId = make_shared<Account>(1);
shared_ptr<Account> byDescriptor = make_shared<Account>("crystalserver@test.com");
shared_ptr<Account> byDescriptor = make_shared<Account>("crystal@test.com");

expect(eq(byId->getID(), 1));
expect(eq(byDescriptor->getID(), 0));

expect(byId->getDescriptor().empty());
expect(eq(byDescriptor->getDescriptor(), string{"crystalserver@test.com"}));
expect(eq(byDescriptor->getDescriptor(), string{"crystal@test.com"}));

for (auto& account : { byId, byDescriptor }) {
expect(eq(account->getPremiumRemainingDays(), 0));
Expand All @@ -71,15 +72,15 @@ suite<"account"> accountTest = [] {

vector<AccountLoadTestCase> accountLoadTestCases{
{"returns by id if exists", make_shared<Account>(1), AccountErrors_t::Ok},
{"returns by descriptor if exists", make_shared<Account>("crystalserver@test.com"), AccountErrors_t::Ok},
{"returns by descriptor if exists", make_shared<Account>("crystal@test.com"), AccountErrors_t::Ok},
{"returns error if id is not valid", make_shared<Account>(2), AccountErrors_t::LoadingAccount},
{"returns error if descriptor is not valid", make_shared<Account>("[email protected]"), AccountErrors_t::LoadingAccount}
};

for (auto& testCase : accountLoadTestCases) {
test(testCase.description) = [&injectionFixture, &testCase] {
auto [accountRepository] = injectionFixture.get<AccountRepository>();
accountRepository.addAccount("crystalserver@test.com", AccountInfo{1, 1, 1, AccountType::ACCOUNT_TYPE_GOD});
accountRepository.addAccount("crystal@test.com", AccountInfo{1, 1, 1, AccountType::ACCOUNT_TYPE_GOD});
expect(eqEnum(testCase.account->load(), testCase.expectedError)) << testCase.description;
};
}
Expand All @@ -92,12 +93,12 @@ suite<"account"> accountTest = [] {
auto [accountRepository] = injectionFixture.get<AccountRepository>();

Account acc { 1 };
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
expect(eqEnum(acc.getAccountType(), AccountType::ACCOUNT_TYPE_GOD));

accountRepository.addAccount("crystalserver2@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GAMEMASTER });
accountRepository.addAccount("crystal2@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GAMEMASTER });

expect(eqEnum(acc.reload(), AccountErrors_t::Ok));
expect(eqEnum(acc.getAccountType(), AccountType::ACCOUNT_TYPE_GAMEMASTER));
Expand All @@ -112,7 +113,7 @@ suite<"account"> accountTest = [] {

Account acc { 1 };
accountRepository.failSave = true;
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
expect(eqEnum(acc.save(), AccountErrors_t::Storage));
Expand All @@ -123,7 +124,7 @@ suite<"account"> accountTest = [] {

Account acc { 1 };
accountRepository.failSave = false;
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
expect(eqEnum(acc.save(), AccountErrors_t::Ok));
Expand All @@ -137,7 +138,7 @@ suite<"account"> accountTest = [] {
auto [accountRepository] = injectionFixture.get<AccountRepository>();

Account acc { 1 };
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
expect(eqEnum(std::get<1>(acc.getCoins(CoinType::Normal)), AccountErrors_t::Storage));
Expand All @@ -147,7 +148,7 @@ suite<"account"> accountTest = [] {
auto [accountRepository] = injectionFixture.get<AccountRepository>();

Account acc { 1 };
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(1, CoinType::Normal, 100);

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
Expand All @@ -159,10 +160,10 @@ suite<"account"> accountTest = [] {
auto [accountRepository] = injectionFixture.get<AccountRepository>();

Account acc { 2 };
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(1, CoinType::Normal, 100);

accountRepository.addAccount("crystalserver2@test.com", AccountInfo { 2, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal2@test.com", AccountInfo { 2, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(2, CoinType::Normal, 33);

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
Expand All @@ -174,7 +175,7 @@ suite<"account"> accountTest = [] {
auto [accountRepository] = injectionFixture.get<AccountRepository>();

Account acc { 1 };
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(1, CoinType::Normal, 100);
accountRepository.setCoins(1, CoinType::Tournament, 100);

Expand All @@ -194,7 +195,7 @@ suite<"account"> accountTest = [] {

Account acc { 1 };
accountRepository.failAddCoins = true;
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(1, CoinType::Normal, 100);

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
Expand All @@ -205,7 +206,7 @@ suite<"account"> accountTest = [] {
auto [accountRepository] = injectionFixture.get<AccountRepository>();

Account acc { 1 };
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(1, CoinType::Normal, 100);

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
Expand All @@ -217,7 +218,7 @@ suite<"account"> accountTest = [] {

Account acc { 1 };
accountRepository.failAddCoins = false;
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(1, CoinType::Normal, 100);

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
Expand All @@ -231,10 +232,10 @@ suite<"account"> accountTest = [] {

Account acc { 2 };
accountRepository.failAddCoins = false;
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(1, CoinType::Normal, 100);

accountRepository.addAccount("crystalserver2@test.com", AccountInfo { 2, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal2@test.com", AccountInfo { 2, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(2, CoinType::Normal, 33);

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
Expand All @@ -250,7 +251,7 @@ suite<"account"> accountTest = [] {
accountRepository.failAddCoins = false;
accountRepository.setCoins(1, CoinType::Normal, 100);
accountRepository.setCoins(1, CoinType::Tournament, 57);
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
expect(eqEnum(acc.addCoins(CoinType::Normal, 100), AccountErrors_t::Ok));
Expand Down Expand Up @@ -278,7 +279,7 @@ suite<"account"> accountTest = [] {

Account acc { 1 };
accountRepository.failAddCoins = true;
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(1, CoinType::Normal, 100);

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
Expand All @@ -289,7 +290,7 @@ suite<"account"> accountTest = [] {
auto [accountRepository] = injectionFixture.get<AccountRepository>();

Account acc { 1 };
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(1, CoinType::Normal, 100);

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
Expand All @@ -301,7 +302,7 @@ suite<"account"> accountTest = [] {

Account acc { 1 };
accountRepository.failAddCoins = false;
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(1, CoinType::Normal, 100);

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
Expand All @@ -315,10 +316,10 @@ suite<"account"> accountTest = [] {

Account acc { 1 };
accountRepository.failAddCoins = false;
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(1, CoinType::Normal, 100);

accountRepository.addAccount("crystalserver2@test.com", AccountInfo { 2, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal2@test.com", AccountInfo { 2, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(2, CoinType::Normal, 33);

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
Expand All @@ -332,7 +333,7 @@ suite<"account"> accountTest = [] {

Account acc { 1 };
accountRepository.failAddCoins = false;
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.setCoins(1, CoinType::Normal, 100);
accountRepository.setCoins(1, CoinType::Tournament, 57);

Expand All @@ -359,7 +360,7 @@ suite<"account"> accountTest = [] {
Account acc { 1 };
accountRepository.failAddCoins = false;
accountRepository.setCoins(1, CoinType::Normal, 1);
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
expect(eqEnum(acc.load(), AccountErrors_t::Ok));
expect(eqEnum(acc.removeCoins(CoinType::Normal, 100), AccountErrors_t::RemoveCoins));

Expand Down Expand Up @@ -391,7 +392,7 @@ suite<"account"> accountTest = [] {
auto [accountRepository] = injectionFixture.get<AccountRepository>();

Account acc { 1 };
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
expect(eqEnum(acc.load(), AccountErrors_t::Ok));
accountRepository.setCoins(1, CoinType::Normal, 1);

Expand All @@ -415,7 +416,7 @@ suite<"account"> accountTest = [] {
auto [accountRepository] = injectionFixture.get<AccountRepository>();

Account acc { 1 };
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
expect(eq(acc.getPassword(), std::string { "123456" }));
Expand All @@ -426,7 +427,7 @@ suite<"account"> accountTest = [] {

Account acc { 1 };
accountRepository.failGetPassword = true;
accountRepository.addAccount("crystalserver@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });
accountRepository.addAccount("crystal@test.com", AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD });

expect(eqEnum(acc.load(), AccountErrors_t::Ok));
expect(eq(std::string{}, acc.getPassword()));
Expand Down Expand Up @@ -521,7 +522,7 @@ suite<"account"> accountTest = [] {

Account acc { 1 };
accountRepository.addAccount(
"crystalserver@test.com",
"crystal@test.com",
AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD, {{ "Crystal", 1 }, { "Crystal2", 2 }} }
);

Expand All @@ -539,7 +540,7 @@ suite<"account"> accountTest = [] {

Account acc { 1 };
accountRepository.addAccount(
"crystalserver@test.com",
"crystal@test.com",
AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD, { { "Crystal", 1 }, { "Crystal2", 2 } } }
);

Expand Down

0 comments on commit af2e3da

Please sign in to comment.