diff options
| author | Aotrix <[email protected]> | 2026-01-01 03:35:41 +0100 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2026-01-01 03:35:41 +0100 |
| commit | c05901c38c6a77779807a6b224b9b624bfcaa5d3 (patch) | |
| tree | fb8d212cd9995e4eecd351de352ea6aab2295924 /battleNetApi/tests | |
| parent | a56ae1a7ad5f624b05570965bed76e928bbd945c (diff) | |
removed useless files
Diffstat (limited to 'battleNetApi/tests')
| -rw-r--r-- | battleNetApi/tests/tests.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/battleNetApi/tests/tests.cpp b/battleNetApi/tests/tests.cpp new file mode 100644 index 0000000..2c3a2ff --- /dev/null +++ b/battleNetApi/tests/tests.cpp @@ -0,0 +1,64 @@ +#include "apiUrl.hpp" +#include "hearthstoneApi.hpp" +#include <catch2/catch_test_macros.hpp> +#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 == 5992); +} + +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() > 6000); +} |
