aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Michael Jurkoic <mjjurkoic@gmail.com>2024-03-17 19:15:29 -0500
committerLibravatar Michael Jurkoic <mjjurkoic@gmail.com>2024-03-17 19:15:29 -0500
commit9832867f9ed9dbcc7ffbd135291bc54c153640b0 (patch)
tree903b0f36b5a3faf379a18f27692be878054b8cef
parentc7096828e62fcea63120504b867150130377ab75 (diff)
Define a receive method on the WebSocket interface
-rw-r--r--include/client/web_socket_client.hpp9
-rw-r--r--test/nostr_service_test.cpp11
2 files changed, 16 insertions, 4 deletions
diff --git a/include/client/web_socket_client.hpp b/include/client/web_socket_client.hpp
index 0f58749..4e6cb8b 100644
--- a/include/client/web_socket_client.hpp
+++ b/include/client/web_socket_client.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <functional>
#include <string>
namespace client
@@ -42,6 +43,14 @@ public:
virtual std::tuple<std::string, bool> send(std::string message, std::string uri) = 0;
/**
+ * @brief Sets up a message handler for the given server.
+ * @param uri The URI of the server to which the message handler should be attached.
+ * @param messageHandler A callable object that will be invoked when the client receives a
+ * message from the server.
+ */
+ virtual void receive(std::string uri, std::function<void(const std::string&)> messageHandler) = 0;
+
+ /**
* @brief Closes the connection to the given server.
*/
virtual void closeConnection(std::string uri) = 0;
diff --git a/test/nostr_service_test.cpp b/test/nostr_service_test.cpp
index 83de3be..d4fc71b 100644
--- a/test/nostr_service_test.cpp
+++ b/test/nostr_service_test.cpp
@@ -7,11 +7,13 @@
#include <client/web_socket_client.hpp>
#include <nostr.hpp>
+using std::function;
using std::lock_guard;
using std::make_shared;
using std::mutex;
using std::shared_ptr;
using std::string;
+using std::tuple;
using std::unordered_map;
using ::testing::_;
using ::testing::Invoke;
@@ -23,10 +25,11 @@ class MockWebSocketClient : public client::IWebSocketClient {
public:
MOCK_METHOD(void, start, (), (override));
MOCK_METHOD(void, stop, (), (override));
- MOCK_METHOD(void, openConnection, (std::string uri), (override));
- MOCK_METHOD(bool, isConnected, (std::string uri), (override));
- MOCK_METHOD((std::tuple<std::string, bool>), send, (std::string message, std::string uri), (override));
- MOCK_METHOD(void, closeConnection, (std::string uri), (override));
+ MOCK_METHOD(void, openConnection, (string uri), (override));
+ MOCK_METHOD(bool, isConnected, (string uri), (override));
+ MOCK_METHOD((tuple<string, bool>), send, (string message, string uri), (override));
+ MOCK_METHOD(void, receive, (string uri, function<void(const string&)> messageHandler), (override));
+ MOCK_METHOD(void, closeConnection, (string uri), (override));
};
class NostrServiceTest : public testing::Test