summaryrefslogtreecommitdiff
path: root/submodules/battleNetApi/tests
diff options
context:
space:
mode:
authorAotrix <[email protected]>2025-11-17 13:30:23 +0100
committerAotrix <[email protected]>2025-11-17 13:30:23 +0100
commit9dab564d3aaabda88efda5e3289392d0be716084 (patch)
tree4d2d0188119ba33f29c0dc6c362c26a47a9e637d /submodules/battleNetApi/tests
parentf78e3e1428f59fb96cb02cf6fbaad692a582f9d5 (diff)
changed subprojects to submodules
Diffstat (limited to 'submodules/battleNetApi/tests')
-rw-r--r--submodules/battleNetApi/tests/tests.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/submodules/battleNetApi/tests/tests.cpp b/submodules/battleNetApi/tests/tests.cpp
new file mode 100644
index 0000000..74845c5
--- /dev/null
+++ b/submodules/battleNetApi/tests/tests.cpp
@@ -0,0 +1,65 @@
+#include "apiUrl.hpp"
+#include "hearthstoneApi.hpp"
+#include <catch2/catch_test_macros.hpp>
+#include <iostream>
+#include <utility>
+
+class TokenMock {
+ public:
+ TokenMock()
+ : mTokenFilePath{"resources/token_info"}, mUsername{"2b50f1123b424d5e9c21971a110fdd04"},
+ mPassword{"MrMkhVMNdOeqPL4Q4XVQAsRPR14J7Yq6"}, mToken{mTokenFilePath, mUsername, mPassword} {}
+ std::string toString() const { return mToken.toString(); }
+ Token &getToken() { return mToken; }
+
+ private:
+ const std::string mTokenFilePath;
+ const std::string mUsername;
+ const std::string mPassword;
+ Token mToken;
+};
+
+class HearthstoneApiMock {
+ public:
+ HearthstoneApiMock() : mHearthstoneApi(std::move(mToken.getToken())) {};
+ std::string makeApiRequest(const std::string &iUrl) { return mHearthstoneApi.makeApiRequest(iUrl); }
+ std::uint64_t numberOfCards(const std::string &iApiResponse) {
+ return mHearthstoneApi.numberOfCards(iApiResponse);
+ };
+
+ private:
+ TokenMock mToken;
+ const HearthstoneApi mHearthstoneApi;
+};
+
+TEST_CASE("Retrieve API Token", "[getApiToken]") {
+ TokenMock aToken;
+ const std::string kTokenContent{aToken.toString()};
+ const std::string::size_type kTokenSize{kTokenContent.size()};
+ REQUIRE(kTokenSize >= 30);
+ REQUIRE(kTokenSize <= 40);
+}
+
+TEST_CASE("Retrieve number of cards", "[getCardsCount]") {
+ HearthstoneApiMock aHearthstoneApi;
+ const std::string kContentType{"cards"};
+ const std::string kRegion{"eu"};
+ ApiUrl aApiUrl(kContentType, kRegion);
+ aApiUrl.setLocale("fr_FR");
+ aApiUrl.setGameMode("constructed");
+ aApiUrl.setPageSize("1");
+ std::uint64_t kNumberOfCards{aHearthstoneApi.numberOfCards(aHearthstoneApi.makeApiRequest(aApiUrl()))};
+ REQUIRE(kNumberOfCards == 5991);
+}
+
+TEST_CASE("Retrieve cards", "[retrieveCards]") {
+ HearthstoneApiMock aHearthstoneApi;
+ const std::string kContentType{"cards"};
+ const std::string kRegion{"eu"};
+ ApiUrl aApiUrl(kContentType, kRegion);
+ aApiUrl.setLocale("fr_FR");
+ aApiUrl.setGameMode("constructed");
+ aApiUrl.setPageSize("10");
+ const std::string kApiResponse{aHearthstoneApi.makeApiRequest(aApiUrl())};
+ REQUIRE(kApiResponse.size() > 300);
+}