Skip to content
This repository has been archived by the owner on Feb 25, 2019. It is now read-only.

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Feb 12, 2019
1 parent 38c5b12 commit 760af7d
Show file tree
Hide file tree
Showing 18 changed files with 1,734 additions and 319 deletions.
16 changes: 0 additions & 16 deletions src/bat_native_confirmations.cc

This file was deleted.

8 changes: 0 additions & 8 deletions src/bat_native_confirmations.h

This file was deleted.

136 changes: 0 additions & 136 deletions src/mock_confirmations_client.cc

This file was deleted.

58 changes: 0 additions & 58 deletions src/mock_confirmations_client.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/refill_tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class RefillTokens {

void Refill(const WalletInfo& wallet_info, const std::string& public_key);

void OnRefill(const Result result);

void RetryGettingSignedTokens();

private:
Expand All @@ -60,8 +62,6 @@ class RefillTokens {
const std::string& response,
const std::map<std::string, std::string>& headers);

void OnRefill(const Result result);

bool ShouldRefillTokens() const;
int CalculateAmountOfTokensToRefill() const;

Expand Down
17 changes: 12 additions & 5 deletions src/unblinded_tokens.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ void UnblindedTokens::SetTokens(const std::vector<UnblindedToken>& tokens) {
confirmations_->SaveState();
}

void UnblindedTokens::SetTokensFromList(const base::ListValue& list) {
void UnblindedTokens::SetTokensFromList(const base::Value& list) {
base::ListValue list_values(list.GetList());

std::vector<UnblindedToken> unblinded_tokens;
for (const auto& token_value : list) {
auto token_base64 = token_value.GetString();
for (const auto& value : list_values) {
auto token_base64 = value.GetString();
auto token = UnblindedToken::decode_base64(token_base64);
unblinded_tokens.push_back(token);
}
Expand All @@ -53,8 +55,13 @@ void UnblindedTokens::SetTokensFromList(const base::ListValue& list) {
}

void UnblindedTokens::AddTokens(const std::vector<UnblindedToken>& tokens) {
unblinded_tokens_.insert(unblinded_tokens_.end(), tokens.begin(),
tokens.end());
for (const auto& token : tokens) {
if (TokenExists(token)) {
continue;
}

unblinded_tokens_.push_back(token);
}

confirmations_->SaveState();
}
Expand Down
2 changes: 1 addition & 1 deletion src/unblinded_tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class UnblindedTokens {
base::Value GetTokensAsList();

void SetTokens(const std::vector<UnblindedToken>& tokens);
void SetTokensFromList(const base::ListValue& list);
void SetTokensFromList(const base::Value& list);

void AddTokens(const std::vector<UnblindedToken>& tokens);

Expand Down
50 changes: 41 additions & 9 deletions test/confirmations_client_mock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,74 @@ namespace confirmations {
MockLogStreamImpl::MockLogStreamImpl(
const char* file,
const int line,
const LogLevel log_level) {
const ledger::LogLevel log_level) {
std::string level;

switch (log_level) {
case LogLevel::LOG_ERROR: {
case ledger::LogLevel::LOG_ERROR: {
level = "ERROR";
break;
}
case LogLevel::LOG_WARNING: {
case ledger::LogLevel::LOG_WARNING: {
level = "WARNING";
break;
}
case LogLevel::LOG_INFO: {
case ledger::LogLevel::LOG_INFO: {
level = "INFO";
break;
}
case ledger::LogLevel::LOG_DEBUG: {
level = "DEBUG";
break;
}
case ledger::LogLevel::LOG_REQUEST: {
level = "REQUEST";
break;
}
case ledger::LogLevel::LOG_RESPONSE: {
level = "RESPONSE";
break;
}
}

log_message_ = level + ": in " + file + " on line "
+ std::to_string(line) + ": ";
log_message_ = level + ": in " + std::string(file) + " on line "
+ std::to_string(line) + ": ";
}

std::ostream& MockLogStreamImpl::stream() {
std::cout << std::endl << log_message_;
return std::cout;
}

MockVerboseLogStreamImpl::MockVerboseLogStreamImpl(
const char* file,
int line,
int vlog_level) {
log_message_ = "VLOG: in " + std::string(file) + " on line "
+ std::to_string(line) + ": ";
}

std::ostream& MockVerboseLogStreamImpl::stream() {
std::cout << std::endl << log_message_;
return std::cout;
}

MockConfirmationsClient::MockConfirmationsClient() = default;

MockConfirmationsClient::~MockConfirmationsClient() = default;

std::unique_ptr<LogStream> MockConfirmationsClient::Log(
std::unique_ptr<ledger::LogStream> MockConfirmationsClient::Log(
const char* file,
const int line,
const LogLevel log_level) const {
int line,
const ledger::LogLevel log_level) const {
return std::make_unique<MockLogStreamImpl>(file, line, log_level);
}

std::unique_ptr<ledger::LogStream> MockConfirmationsClient::VerboseLog(
const char* file,
int line,
int vlog_level) const {
return std::make_unique<MockVerboseLogStreamImpl>(file, line, vlog_level);
}

} // namespace confirmations
Loading

0 comments on commit 760af7d

Please sign in to comment.