diff --git a/src/metrics_impl.cpp b/src/metrics_impl.cpp index 9f29027..0e04139 100644 --- a/src/metrics_impl.cpp +++ b/src/metrics_impl.cpp @@ -30,17 +30,17 @@ MetricsImpl::MetricsImpl(Firebolt::Helpers::IHelper& helper) Result MetricsImpl::ready() const { - return helper_.invoke("Metrics.ready", nlohmann::json({})); + return helper_.invoke("Metrics.ready", nlohmann::json()); } Result MetricsImpl::signIn() const { - return helper_.invoke("Metrics.signIn", nlohmann::json({})); + return helper_.invoke("Metrics.signIn", nlohmann::json()); } Result MetricsImpl::signOut() const { - return helper_.invoke("Metrics.signOut", nlohmann::json({})); + return helper_.invoke("Metrics.signOut", nlohmann::json()); } Result MetricsImpl::startContent(const std::optional& entityId, diff --git a/test/unit/mock_helper.h b/test/unit/mock_helper.h index f2a9ffb..00598e5 100644 --- a/test/unit/mock_helper.h +++ b/test/unit/mock_helper.h @@ -107,8 +107,23 @@ class MockBase void mockInvoke(const std::string& methodName) { EXPECT_CALL(mockHelper, invoke(methodName, _)) - .WillOnce(Invoke([](const std::string& /*methodName*/, const nlohmann::json& /*parameters*/) - { return Firebolt::Result{Firebolt::Error::None}; })); + .WillOnce(Invoke( + [&](const std::string& invokedMethodName, const nlohmann::json& parameters) + { + nlohmann::json message = { + {"jsonrpc", "2.0"}, + {"id", "0"}, + {"method", invokedMethodName}, + }; + + if (!parameters.is_null()) + { + message["params"] = parameters; + } + + Firebolt::Error err = jsonEngine.MockResponse(message); + return Firebolt::Result{err}; + })); } void mockSubscribe(const std::string& eventName) diff --git a/test/utils.cpp b/test/utils.cpp index 60de1be..c24a4e1 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -125,7 +125,7 @@ void verifyUnsubscribeResult(const Firebolt::Result& result) FAIL() << "Unsubscribe failed." + toError(result); } } -void verifyEventReceived(std::mutex& mtx, std::condition_variable& cv, const bool& eventReceived) +void verifyEventReceived(std::mutex& mtx, std::condition_variable& cv, bool& eventReceived) { std::unique_lock lock(mtx); if (!cv.wait_for(lock, EventWaitTime, [&] { return eventReceived; })) @@ -134,11 +134,11 @@ void verifyEventReceived(std::mutex& mtx, std::condition_variable& cv, const boo } } -void verifyEventNotReceived(std::mutex& mtx, std::condition_variable& cv, const bool& eventReceived) +void verifyEventNotReceived(std::mutex& mtx, std::condition_variable& cv, bool& eventReceived) { - // Wait for the event to be received or timeout after 5 seconds + // Wait for the event to be received or timeout after EventWaitTime. std::unique_lock lock(mtx); - if (cv.wait_for(lock, std::chrono::seconds(EventWaitTime), [&] { return eventReceived; })) + if (cv.wait_for(lock, EventWaitTime, [&] { return eventReceived; })) { FAIL() << "Unexpectedly received event"; } diff --git a/test/utils.h b/test/utils.h index b5d0693..bd1e2e3 100644 --- a/test/utils.h +++ b/test/utils.h @@ -32,8 +32,8 @@ void triggerRaw(const std::string& payload); void verifyEventSubscription(const Firebolt::Result& id); void verifyUnsubscribeResult(const Firebolt::Result& result); -void verifyEventReceived(std::mutex& mtx, std::condition_variable& cv, const bool& eventReceived); -void verifyEventNotReceived(std::mutex& mtx, std::condition_variable& cv, const bool& eventReceived); +void verifyEventReceived(std::mutex& mtx, std::condition_variable& cv, bool& eventReceived); +void verifyEventNotReceived(std::mutex& mtx, std::condition_variable& cv, bool& eventReceived); template inline std::string toError(const Firebolt::Result& result) {