-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPastEventTest.cpp
66 lines (54 loc) · 2.05 KB
/
PastEventTest.cpp
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
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest.h>
#include <crow.h>
#include <string>
#include "PastEvent.h"
#include <map>
//map to store Artists
std::map<std::string, Artist> artistMap;
//map to store Venues
std::map<std::string, Venue> venueMap;
TEST_CASE("Testing Past Event class functionality")
{
Artist art1("Name", "Type", 2.3);
artistMap.insert({"Name", art1});
Venue ven1("City", "Address", 2.5);
venueMap.insert({"City", ven1});
PastEvent finished("4", art1, ven1, "12/12/2004", "2:32");
SUBCASE("Testing addReview Method")
{
CHECK(finished.addReview("Good") == "Good");
}
finished.addReview("Good");
SUBCASE("Testing getReview Method")
{
CHECK(finished.getReview() == "Good");
}
SUBCASE("Testing convertoJson Method")
{
crow::json::wvalue jsonOutput = finished.convertToJson();
crow::json::rvalue jsonReadValue = crow::json::load(jsonOutput.dump());
CHECK(jsonReadValue["id"].s() == "4");
CHECK(jsonReadValue["date"].s() == "12/12/2004");
CHECK(jsonReadValue["time"].s() == "2:32");
CHECK(jsonReadValue["artist"]["name"].s() == "Name");
CHECK(jsonReadValue["venue"]["city"].s() == "City");
for(crow::json::rvalue review : jsonReadValue["reviews"])
{
CHECK(review.s() == "Good");
}
}
SUBCASE("Testing updateFromJson Method")
{
crow::json::rvalue updateJson = crow::json::load(R"({"venue":{"city":"City"},"time":"4:00","date":"12/02/2023","id":"2","artist":{"name":"Name"}, "reviews":{"0":"hey", "1":"world"}})");
finished.updateFromJson(updateJson);
CHECK(finished.getId() == "2");
CHECK(finished.getDate() == "12/02/2023");
CHECK(finished.getTime() == "4:00");
CHECK(finished.getArtist().getName() == "Name");
CHECK(finished.getWhere().getCity() == "City");
std::string oneReview = finished.getReview();
bool isReview = (oneReview == "hey") || (oneReview == "world");
CHECK(isReview);
}
}