Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phacUFPE committed Aug 27, 2024
1 parent c10dffd commit 0777b4e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/fixture/account/in_memory_account_repository.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ namespace tests {
return true;
}

bool getCharacterByNameAndAccountId(const uint32_t &id, const std::string &name) final {
for (auto it = accounts.begin(); it != accounts.end(); ++it) {
if (it->second.id == id) {
if (it->second.players.find(name) != it->second.players.end()) {
return true;
}
}
}
return false;
}

InMemoryAccountRepository &reset() {
accounts.clear();
coins_.clear();
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/account/account_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,4 +592,32 @@ suite<"account"> accountTest = [] {
expect(acc.load() == enumToValue(AccountErrors_t::Ok));
expect(acc.authenticate());
};

test("Account::getCharacterByNameAndAccountId using an account with the given character.") = [&injectionFixture] {
auto [accountRepository] = injectionFixture.get<AccountRepository>();

Account acc { 1 };
accountRepository.addAccount(
"session-key",
AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD, { { "Canary", 1 }, { "Canary2", 2 } }, false, getTimeNow() + 24 * 60 * 60 * 1000 }
);

const auto hasCharacter = accountRepository.getCharacterByNameAndAccountId(1, "Canary");

expect(hasCharacter);
};

test("Account::getCharacterByNameAndAccountId using an account without the given character.") = [&injectionFixture] {
auto [accountRepository] = injectionFixture.get<AccountRepository>();

Account acc { 1 };
accountRepository.addAccount(
"session-key",
AccountInfo { 1, 1, 1, AccountType::ACCOUNT_TYPE_GOD, { { "Canary", 1 }, { "Canary2", 2 } }, false, getTimeNow() + 24 * 60 * 60 * 1000 }
);

const auto hasCharacter = accountRepository.getCharacterByNameAndAccountId(1, "Invalid");

expect(!hasCharacter);
};
};

0 comments on commit 0777b4e

Please sign in to comment.