Skip to content

Commit 5d26aeb

Browse files
committed
test(discovery): bidirectional end to end tests
1 parent 07f682f commit 5d26aeb

File tree

3 files changed

+144
-4
lines changed

3 files changed

+144
-4
lines changed

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

Lines changed: 129 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,98 @@
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+
#ifdef GATEWAY_BIDIRECTIONAL
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+
64+
void DiscoverySDKTest::event_trigger(nlohmann::json event)
65+
{
66+
std::cout << "Event triggered: " << event["method"].dump() << std::endl;
67+
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() + "}'";
68+
system(trigger_cmd.c_str());
69+
std::cout << std::endl;
70+
std::cout << "[ADITYA] trigger_cmd: " << trigger_cmd << std::endl;
71+
}
72+
73+
void DiscoverySDKTest::provider_trigger(nlohmann::json provider)
74+
{
75+
std::cout << "Provider triggered: " << provider["method"].dump() << std::endl;
76+
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() + "}'";
77+
system(trigger_cmd.c_str());
78+
std::cout << std::endl;
79+
}
80+
81+
std::string InterestTypeToString(Firebolt::Discovery::InterestType interestType) {
82+
switch (interestType) {
83+
case Firebolt::Discovery::InterestType::INTEREST:
84+
return "interest";
85+
case Firebolt::Discovery::InterestType::DISINTEREST:
86+
return "disinterest";
87+
default:
88+
return "unknown";
89+
}
90+
}
91+
92+
std::string InterestReasonToString(Firebolt::Discovery::InterestReason interestReason) {
93+
switch (interestReason) {
94+
case Firebolt::Discovery::InterestReason::PLAYLIST:
95+
return "playlist";
96+
case Firebolt::Discovery::InterestReason::REACTION:
97+
return "reaction";
98+
case Firebolt::Discovery::InterestReason::RECORDING:
99+
return "recording";
100+
default:
101+
return "unknown";
102+
}
103+
}
104+
105+
106+
#endif
107+
28108
void DiscoverySDKTest::ConnectionChanged(const bool connected, const Firebolt::Error error)
29109
{
30-
cout << "Change in connection: connected: " << connected << " error: " << static_cast<int>(error) << endl;
31-
_connected = connected;
110+
if (!_connected) {
111+
cout << "Change in connection: connected: " << connected << " error: " << static_cast<int>(error) << endl;
112+
_connected = connected;
113+
}
32114
}
33115

34116
void DiscoverySDKTest::CreateFireboltInstance(const std::string& url)
@@ -67,6 +149,7 @@ bool DiscoverySDKTest::WaitOnConnectionReady()
67149
usleep(sleepSlot);
68150
waiting -= sleepSlot;
69151
}
152+
usleep(5000);
70153
return _connected;
71154
}
72155

@@ -90,9 +173,51 @@ inline const T ConvertToEnum(EnumMap<T> enumMap, const string& str)
90173
return value;
91174
}
92175

93-
void DiscoverySDKTest::OnUserInterestNotification::onUserInterest( const Firebolt::Content::InterestEvent& interest)
176+
std::string ContentRatingSchemeToString(Firebolt::Entertainment::ContentRatingScheme scheme)
177+
{
178+
switch (scheme)
179+
{
180+
case Firebolt::Entertainment::ContentRatingScheme::CA_MOVIE:
181+
return "CA-Movie";
182+
case Firebolt::Entertainment::ContentRatingScheme::CA_TV:
183+
return "CA-TV";
184+
case Firebolt::Entertainment::ContentRatingScheme::CA_MOVIE_FR:
185+
return "CA-Movie_Fr";
186+
case Firebolt::Entertainment::ContentRatingScheme::CA_TV_FR:
187+
return "CA-TV_Fr";
188+
case Firebolt::Entertainment::ContentRatingScheme::US_MOVIE:
189+
return "US-Movie";
190+
case Firebolt::Entertainment::ContentRatingScheme::US_TV:
191+
return "US-TV";
192+
default:
193+
return "UNKNOWN";
194+
}
195+
}
196+
197+
void DiscoverySDKTest::OnUserInterestNotification::onUserInterest(const Firebolt::Content::InterestEvent &interest)
94198
{
95-
cout << "User Interest changed notification" << endl;
199+
cout << "onUserInterest() notification \n";
200+
201+
#ifdef GATEWAY_BIDIRECTIONAL
202+
assert(interest.appId == userInterestEvent["payload"]["appId"]);
203+
assert(InterestTypeToString(interest.type) == userInterestEvent["payload"]["type"]);
204+
assert(InterestReasonToString(interest.reason) == userInterestEvent["payload"]["reason"]);
205+
assert(interest.entity.info->title.value() == userInterestEvent["payload"]["entity"]["info"]["title"]);
206+
assert(interest.entity.info->synopsis.value() == userInterestEvent["payload"]["entity"]["info"]["synopsis"]);
207+
assert(interest.entity.info->releaseDate.value() == userInterestEvent["payload"]["entity"]["info"]["releaseDate"]);
208+
size_t i = 0;
209+
for (const auto &rating : interest.entity.info->contentRatings.value())
210+
{
211+
assert(ContentRatingSchemeToString(rating.scheme) == userInterestEvent["payload"]["entity"]["info"]["contentRatings"][i]["scheme"]);
212+
i++;
213+
}
214+
size_t j = 0;
215+
for (const auto &ratings : interest.entity.info->contentRatings.value())
216+
{
217+
assert(ratings.rating == userInterestEvent["payload"]["entity"]["info"]["contentRatings"][j]["rating"]);
218+
j++;
219+
}
220+
#endif
96221
}
97222

98223
void DiscoverySDKTest::SubscribeUserInterest()

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

Lines changed: 11 additions & 0 deletions
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,19 @@ class DiscoverySDKTest {
4142

4243
static bool WaitOnConnectionReady();
4344

45+
#ifdef GATEWAY_BIDIRECTIONAL
46+
static void event_trigger(nlohmann::json event);
47+
static void provider_trigger(nlohmann::json provider);
48+
#endif
49+
4450
private:
4551
static void ConnectionChanged(const bool, const Firebolt::Error);
4652
static bool _connected;
4753
static OnUserInterestNotification _userInterestNotification;
4854

55+
#ifdef GATEWAY_BIDIRECTIONAL
56+
public:
57+
static const nlohmann::json userInterestEvent;
58+
#endif
59+
4960
};

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

Lines changed: 4 additions & 0 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;
@@ -42,8 +43,11 @@ void RunAllTests() {
4243

4344
// Ensure the connection is ready before running tests
4445
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

0 commit comments

Comments
 (0)