blob: 65133012bc3ab46bf5e92ebca851528d96a8dc30 (
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
|
#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()};
std::cout << kTokenContent << '\n';
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()))};
std::cout << std::format("Number of cards: {}", kNumberOfCards) << '\n';
}
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);
}
|