blob: 062608e6ef909e3bc45a5053337ea863dda7e791 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#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"};
Token aToken(kCredentialsFile);
const std::string kTokenContent{aToken.text()};
const std::string::size_type kTokenSize{kTokenContent.size()};
REQUIRE(kTokenSize >= 30);
REQUIRE(kTokenSize <= 40);
}
TEST_CASE("Retrieve number of cards", "[countCards]") {
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("1");
const json kResponse = aHearthstoneApi.makeApiRequest(aApiUrl());
REQUIRE(kResponse.size() > 0);
REQUIRE(kResponse.contains("pageCount"));
std::uint64_t kNumberOfCards{kResponse["pageCount"]};
REQUIRE(kNumberOfCards == 6033);
}
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);
}
|