Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(cov): add/hit missing tests
 #180

Merged
merged 1 commit into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
81 changes: 21 additions & 60 deletions src/api/paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "api/paths.h"

#include <numeric>
#include <string>

namespace Ark {
Expand All @@ -22,6 +23,20 @@ namespace {
constexpr const uint8_t URL_MAX_LEN = 128U;
} //namespace

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

static std::string
joinQueryBody(const std::map<std::string, std::string>& bodyMap) {
return std::accumulate(bodyMap.begin(), bodyMap.end(),
std::string(),
[](const std::string& result,
const std::pair<const std::string, std::string>& p) {
return result + (result.empty() ? "" : "&") + p.first + "=" + p.second;
});
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

/**
Expand Down Expand Up @@ -94,16 +109,7 @@ std::pair<std::string, std::string> Blocks::search(
url += "/search";
url += query;

std::string parameterBuffer;
auto count = 0UL;
for (const auto& p : bodyParameters) {
++count;
parameterBuffer += p.first + '=' + p.second;
if (bodyParameters.size() > 1 && count < bodyParameters.size()) {
parameterBuffer += '&';
};
};
return { url, parameterBuffer };
return { url, joinQueryBody(bodyParameters) };
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -163,16 +169,7 @@ std::pair<std::string, std::string> Businesses::search(
url += "/search";
url += query;

std::string parameterBuffer;
auto count = 0UL;
for (const auto& p : bodyParameters) {
++count;
parameterBuffer += p.first + '=' + p.second;
if (bodyParameters.size() > 1 && count < bodyParameters.size()) {
parameterBuffer += '&';
};
};
return { url, parameterBuffer };
return { url, joinQueryBody(bodyParameters) };
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -219,16 +216,7 @@ std::pair<std::string, std::string> Bridgechains::search(
url += "/search";
url += query;

std::string parameterBuffer;
auto count = 0UL;
for (const auto& p : bodyParameters) {
++count;
parameterBuffer += p.first + '=' + p.second;
if (bodyParameters.size() > 1 && count < bodyParameters.size()) {
parameterBuffer += '&';
};
};
return { url, parameterBuffer };
return { url, joinQueryBody(bodyParameters) };
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -338,16 +326,7 @@ std::pair<std::string, std::string> Locks::search(
url += "/search";
url += query;

std::string parameterBuffer;
auto count = 0UL;
for (const auto& p : bodyParameters) {
++count;
parameterBuffer += p.first + '=' + p.second;
if (bodyParameters.size() > 1 && count < bodyParameters.size()) {
parameterBuffer += '&';
};
};
return { url, parameterBuffer };
return { url, joinQueryBody(bodyParameters) };
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -574,16 +553,7 @@ std::pair<std::string, std::string> Transactions::search(
url += "/search";
url += query;

std::string parameterBuffer;
auto count = 0UL;
for (const auto& p : bodyParameters) {
++count;
parameterBuffer += p.first + '=' + p.second;
if (bodyParameters.size() > 1 && count < bodyParameters.size()) {
parameterBuffer += '&';
};
};
return { url, parameterBuffer.c_str() };
return { url, joinQueryBody(bodyParameters) };
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -766,16 +736,7 @@ std::pair<std::string, std::string> Wallets::search(
url += "/search";
url += query;

std::string parameterBuffer;
auto count = 0UL;
for (const auto& p : bodyParameters) {
++count;
parameterBuffer += p.first + '=' + p.second;
if (bodyParameters.size() > 1 && count < bodyParameters.size()) {
parameterBuffer += '&';
};
};
return { url.c_str(), parameterBuffer.c_str() };
return { url, joinQueryBody(bodyParameters) };
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions test/api/paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ TEST(paths, test_node) {
const auto crypto = paths::Node::crypto(testHost);
ASSERT_STREQ("0.0.0.0:4003/api/node/configuration/crypto", crypto.c_str());

const auto fees = paths::Node::fees(testHost);
ASSERT_STREQ("0.0.0.0:4003/api/node/fees?days=7", fees.c_str());

const auto status = paths::Node::status(testHost);
ASSERT_STREQ("0.0.0.0:4003/api/node/status", status.c_str());

Expand Down