Skip to content

Commit d1e91a8

Browse files
committed
test(discovery): bidirectional end to end tests
1 parent 8c0fbcb commit d1e91a8

File tree

3 files changed

+162
-9
lines changed

3 files changed

+162
-9
lines changed

src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp

Lines changed: 145 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,131 @@
1919
#include <unistd.h>
2020
#include <cstring>
2121
#include <string>
22+
#include <cassert>
2223
#include "DiscoverySDKTest.h"
2324

2425
using namespace std;
2526
bool DiscoverySDKTest::_connected;
2627
DiscoverySDKTest::OnUserInterestNotification DiscoverySDKTest::_userInterestNotification;
2728

29+
30+
31+
const nlohmann::json DiscoverySDKTest::userInterestEvent = {
32+
{"method", "content.onUserInterest"},
33+
{"payload", {
34+
{"name", "interest"},
35+
{"appId", "cool-app"},
36+
{"type", "interest"},
37+
{"reason", "playlist"},
38+
{"entity", {
39+
{"identifiers", {
40+
{"entityId", "345"},
41+
{"entityType", "program"},
42+
{"programType", "movie"}
43+
}},
44+
{"info", {
45+
{"title", "Cool Runnings"},
46+
{"synopsis", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar sapien et ligula ullamcorper malesuada proin libero nunc."},
47+
{"releaseDate", "1993-01-01T00:00:00.000Z"},
48+
{"contentRatings", {
49+
{
50+
{"scheme", "US-Movie"},
51+
{"rating", "PG"}
52+
},
53+
{
54+
{"scheme", "CA-Movie"},
55+
{"rating", "G"}
56+
}
57+
}}
58+
}}
59+
}}
60+
}}
61+
};
62+
63+
#ifdef GATEWAY_BIDIRECTIONAL
64+
65+
std::string InterestTypeToString(Firebolt::Discovery::InterestType interestType) {
66+
switch (interestType) {
67+
case Firebolt::Discovery::InterestType::INTEREST:
68+
return "interest";
69+
case Firebolt::Discovery::InterestType::DISINTEREST:
70+
return "disinterest";
71+
default:
72+
return "unknown";
73+
}
74+
}
75+
76+
std::string InterestReasonToString(Firebolt::Discovery::InterestReason interestReason) {
77+
switch (interestReason) {
78+
case Firebolt::Discovery::InterestReason::PLAYLIST:
79+
return "playlist";
80+
case Firebolt::Discovery::InterestReason::REACTION:
81+
return "reaction";
82+
case Firebolt::Discovery::InterestReason::RECORDING:
83+
return "recording";
84+
default:
85+
return "unknown";
86+
}
87+
}
88+
89+
std::string ContentRatingSchemeToString(Firebolt::Entertainment::ContentRatingScheme scheme)
90+
{
91+
switch (scheme)
92+
{
93+
case Firebolt::Entertainment::ContentRatingScheme::CA_MOVIE:
94+
return "CA-Movie";
95+
case Firebolt::Entertainment::ContentRatingScheme::CA_TV:
96+
return "CA-TV";
97+
case Firebolt::Entertainment::ContentRatingScheme::CA_MOVIE_FR:
98+
return "CA-Movie_Fr";
99+
case Firebolt::Entertainment::ContentRatingScheme::CA_TV_FR:
100+
return "CA-TV_Fr";
101+
case Firebolt::Entertainment::ContentRatingScheme::US_MOVIE:
102+
return "US-Movie";
103+
case Firebolt::Entertainment::ContentRatingScheme::US_TV:
104+
return "US-TV";
105+
default:
106+
return "UNKNOWN";
107+
}
108+
}
109+
110+
void DiscoverySDKTest::event_trigger(nlohmann::json event)
111+
{
112+
std::cout << "Event triggered: " << event["method"].dump() << std::endl;
113+
std::string trigger_cmd = "curl --location --request POST http://localhost:3333/api/v1/bidirectionalEventPayload --header 'Content-Type: application/json' --data-raw '{ \"method\": " + event["method"].dump() + ", \"params\": " + event["payload"].dump() + "}'";
114+
system(trigger_cmd.c_str());
115+
std::cout << std::endl;
116+
std::cout << "[ADITYA] trigger_cmd: " << trigger_cmd << std::endl;
117+
}
118+
119+
void DiscoverySDKTest::provider_trigger(nlohmann::json provider)
120+
{
121+
std::cout << "Provider triggered: " << provider["method"].dump() << std::endl;
122+
std::string trigger_cmd = "curl --location --request POST http://localhost:3333/api/v1/bidirectionalPayload --header 'Content-Type: application/json' --data-raw '{ \"method\": " + provider["method"].dump() + ", \"params\": " + provider["payload"].dump() + "}'";
123+
system(trigger_cmd.c_str());
124+
std::cout << std::endl;
125+
}
126+
127+
#else
128+
129+
void DiscoverySDKTest::event_trigger(nlohmann::json event)
130+
{
131+
std::cout << "Event triggered: " << event["method"].dump() << std::endl;
132+
std::string trigger_cmd = "curl --location --request POST http://localhost:3333/api/v1/event --header 'Content-Type: application/json' --data-raw '{ \"method\": " + event["method"].dump() + ", \"result\": " + event["payload"].dump() + "}'";
133+
system(trigger_cmd.c_str());
134+
std::cout << std::endl;
135+
}
136+
137+
void DiscoverySDKTest::provider_trigger(nlohmann::json provider)
138+
{
139+
std::cout << "Provider triggered: " << provider["method"].dump() << std::endl;
140+
std::string trigger_cmd = "curl --location --request POST http://localhost:3333/api/v1/event --header 'Content-Type: application/json' --data-raw '{ \"method\": " + provider["method"].dump() + ", \"params\": " + provider["payload"].dump() + "}'";
141+
system(trigger_cmd.c_str());
142+
std::cout << std::endl;
143+
}
144+
145+
#endif
146+
28147
void DiscoverySDKTest::ConnectionChanged(const bool connected, const Firebolt::Error error)
29148
{
30149
cout << "Change in connection: connected: " << connected << " error: " << static_cast<int>(error) << endl;
@@ -90,9 +209,33 @@ inline const T ConvertToEnum(EnumMap<T> enumMap, const string& str)
90209
return value;
91210
}
92211

93-
void DiscoverySDKTest::OnUserInterestNotification::onUserInterest( const Firebolt::Content::InterestEvent& interest)
212+
213+
214+
void DiscoverySDKTest::OnUserInterestNotification::onUserInterest(const Firebolt::Content::InterestEvent &interest)
94215
{
95-
cout << "User Interest changed notification" << endl;
216+
cout << "onUserInterest() notification \n";
217+
218+
#ifdef GATEWAY_BIDIRECTIONAL
219+
assert(interest.appId == userInterestEvent["payload"]["appId"]);
220+
assert(InterestTypeToString(interest.type) == userInterestEvent["payload"]["type"]);
221+
assert(InterestReasonToString(interest.reason) == userInterestEvent["payload"]["reason"]);
222+
// assert(interest.entity.identifiers == userInterestEvent["payload"]["entity"]["identifiers"]);
223+
assert(interest.entity.info->title.value() == userInterestEvent["payload"]["entity"]["info"]["title"]);
224+
assert(interest.entity.info->synopsis.value() == userInterestEvent["payload"]["entity"]["info"]["synopsis"]);
225+
assert(interest.entity.info->releaseDate.value() == userInterestEvent["payload"]["entity"]["info"]["releaseDate"]);
226+
size_t i = 0;
227+
for (const auto &rating : interest.entity.info->contentRatings.value())
228+
{
229+
assert(ContentRatingSchemeToString(rating.scheme) == userInterestEvent["payload"]["entity"]["info"]["contentRatings"][i]["scheme"]);
230+
i++;
231+
}
232+
size_t j = 0;
233+
for (const auto &ratings : interest.entity.info->contentRatings.value())
234+
{
235+
assert(ratings.rating == userInterestEvent["payload"]["entity"]["info"]["contentRatings"][j]["rating"]);
236+
j++;
237+
}
238+
#endif
96239
}
97240

98241
void DiscoverySDKTest::SubscribeUserInterest()

src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#pragma once
2020

2121
#include <iostream>
22+
#include <nlohmann/json.hpp>
2223
#include "firebolt.h"
2324

2425
class DiscoverySDKTest {
@@ -41,9 +42,14 @@ class DiscoverySDKTest {
4142

4243
static bool WaitOnConnectionReady();
4344

45+
static void event_trigger(nlohmann::json event);
46+
static void provider_trigger(nlohmann::json provider);
47+
4448
private:
4549
static void ConnectionChanged(const bool, const Firebolt::Error);
4650
static bool _connected;
4751
static OnUserInterestNotification _userInterestNotification;
4852

49-
};
53+
public:
54+
static const nlohmann::json userInterestEvent;
55+
};

src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <string>
2222
#include <iostream>
2323
#include <stdexcept>
24+
#include <unistd.h>
2425
#include "DiscoverySDKTest.h"
2526

2627
using namespace std;
@@ -40,10 +41,13 @@ void RunAllTests() {
4041
}
4142
};
4243

43-
// Ensure the connection is ready before running tests
44-
if (DiscoverySDKTest::WaitOnConnectionReady()) {
44+
// // Ensure the connection is ready before running tests
45+
// if (DiscoverySDKTest::WaitOnConnectionReady()) {
46+
47+
sleep(2);
4548

4649
runTest(DiscoverySDKTest::SubscribeUserInterest, "SubscribeUserInterest");
50+
DiscoverySDKTest::event_trigger(DiscoverySDKTest::userInterestEvent);
4751
runTest(DiscoverySDKTest::UnsubscribeUserInterest, "UnsubscribeUserInterest");
4852
runTest(DiscoverySDKTest::RequestUserInterest, "RequestUserInterest");
4953

@@ -60,10 +64,10 @@ void RunAllTests() {
6064
cout << "============================" << endl;
6165
exit(1);
6266
}
63-
} else {
64-
cout << "Discovery Test not able to connect with server..." << endl;
65-
exit(1);
66-
}
67+
// } else {
68+
// cout << "Discovery Test not able to connect with server..." << endl;
69+
// exit(1);
70+
// }
6771
}
6872

6973
int main(int argc, char* argv[]) {

0 commit comments

Comments
 (0)