diff options
Diffstat (limited to 'battleNetApi/tests')
| -rw-r--r-- | battleNetApi/tests/tests.cpp | 59 |
1 files changed, 44 insertions, 15 deletions
diff --git a/battleNetApi/tests/tests.cpp b/battleNetApi/tests/tests.cpp index 611cf83..062608e 100644 --- a/battleNetApi/tests/tests.cpp +++ b/battleNetApi/tests/tests.cpp @@ -1,8 +1,10 @@ #include "apiUrl.hpp" #include "hearthstoneApi.hpp" #include <catch2/catch_test_macros.hpp> +#include <cstdint> #include <iostream> #include <nlohmann/json.hpp> +#include <string> TEST_CASE("Retrieve API Token", "[generateApiToken]") { const std::string kCredentialsFile{"tests/resources/credentials.json"}; @@ -13,7 +15,7 @@ TEST_CASE("Retrieve API Token", "[generateApiToken]") { REQUIRE(kTokenSize <= 40); } -TEST_CASE("Retrieve number of cards", "[getCardsCount]") { +TEST_CASE("Retrieve number of cards", "[countCards]") { const std::string kCredentialsFile{"tests/resources/credentials.json"}; Token aToken(kCredentialsFile); HearthstoneApi aHearthstoneApi(aToken); @@ -23,21 +25,48 @@ TEST_CASE("Retrieve number of cards", "[getCardsCount]") { aApiUrl.setLocale("fr_FR"); aApiUrl.setGameMode("constructed"); aApiUrl.setPageSize("1"); - const json kResponse{aHearthstoneApi.makeApiRequest(aApiUrl())}; + const json kResponse = aHearthstoneApi.makeApiRequest(aApiUrl()); REQUIRE(kResponse.size() > 0); - REQUIRE(kResponse[0].contains("pageCount")); - std::uint64_t kNumberOfCards{kResponse[0]["pageCount"]}; + REQUIRE(kResponse.contains("pageCount")); + std::uint64_t kNumberOfCards{kResponse["pageCount"]}; REQUIRE(kNumberOfCards == 6033); } -// 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() > 5000); -// } +TEST_CASE("Retrieve cards", "[retrieveCardsOnce]") { + const std::string kCredentialsFile{"tests/resources/credentials.json"}; + Token aToken(kCredentialsFile); + HearthstoneApi aHearthstoneApi(aToken); + const std::string kContentType{"cards"}; + const std::string kRegion{"eu"}; + ApiUrl aApiUrl(kContentType, kRegion); + aApiUrl.setLocale("fr_FR"); + aApiUrl.setGameMode("constructed"); + aApiUrl.setPageSize("16"); + const json kApiResponse = aHearthstoneApi.makeApiRequest(aApiUrl()); + REQUIRE(kApiResponse["cards"].size() == 16); +} + +TEST_CASE("Retrieve cards", "[retrieveCardsFourTimes]") { + const std::string kCredentialsFile{"tests/resources/credentials.json"}; + Token aToken(kCredentialsFile); + HearthstoneApi aHearthstoneApi(aToken); + const std::string kContentType{"cards"}; + const std::string kRegion{"eu"}; + ApiUrl aApiUrl(kContentType, kRegion); + aApiUrl.setLocale("fr_FR"); + aApiUrl.setGameMode("constructed"); + aApiUrl.setPageSize("16"); + aApiUrl.setPage("1"); + json kApiResponse = aHearthstoneApi.makeApiRequest(aApiUrl()); + + // Retrieve number of pages + const int kNumberOfPages{kApiResponse["pageCount"]}; + REQUIRE(kNumberOfPages >= 4); + for (int i{1}; i < 4; ++i) { + REQUIRE(kApiResponse["cards"].size() == 16); + aApiUrl.setPage(std::to_string(i + 1)); + kApiResponse = aHearthstoneApi.makeApiRequest(aApiUrl()); + } + REQUIRE(kApiResponse["cards"].size() >= 1); + REQUIRE(kApiResponse["cards"].size() <= 16); +} |
