diff options
author | Michael Jurkoic <mjjurkoic@gmail.com> | 2024-04-11 09:26:19 -0500 |
---|---|---|
committer | Michael Jurkoic <mjjurkoic@gmail.com> | 2024-04-11 09:26:19 -0500 |
commit | ebbb900849cd5c7ecd471e298c049404c8898b27 (patch) | |
tree | df59d126238c469c0797c3e51770ccc87c71034d /test/nostr_service_test.cpp | |
parent | c8bb6c8f56e0c6d93c8623722ab932c04de882b5 (diff) |
Update existing unit tests for recent code changes
All preexisting unit tests now pass and test for the correct behavior.
Diffstat (limited to 'test/nostr_service_test.cpp')
-rw-r--r-- | test/nostr_service_test.cpp | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/test/nostr_service_test.cpp b/test/nostr_service_test.cpp index 854de78..cd6307b 100644 --- a/test/nostr_service_test.cpp +++ b/test/nostr_service_test.cpp @@ -422,10 +422,16 @@ TEST_F(NostrServiceTest, PublishEvent_CorrectlyIndicates_AllSuccesses) defaultTestRelays); nostrService->openRelayConnections(); - EXPECT_CALL(*mockClient, send(_, _)) + EXPECT_CALL(*mockClient, send(_, _, _)) .Times(2) - .WillRepeatedly(Invoke([](string message, string uri) + .WillRepeatedly(Invoke([](string message, string uri, function<void(const string&)> messageHandler) { + json messageArr = json::parse(message); + auto event = nostr::Event::fromString(messageArr[1]); + + json jarr = json::array({ "OK", event.id, true, "Event accepted" }); + messageHandler(jarr.dump()); + return make_tuple(uri, true); })); @@ -467,9 +473,10 @@ TEST_F(NostrServiceTest, PublishEvent_CorrectlyIndicates_AllFailures) defaultTestRelays); nostrService->openRelayConnections(); - EXPECT_CALL(*mockClient, send(_, _)) + // Simulate a case where the message failed to send to all relays. + EXPECT_CALL(*mockClient, send(_, _, _)) .Times(2) - .WillRepeatedly(Invoke([](string message, string uri) + .WillRepeatedly(Invoke([](string message, string uri, function<void(const string&)> messageHandler) { return make_tuple(uri, false); })); @@ -512,15 +519,23 @@ TEST_F(NostrServiceTest, PublishEvent_CorrectlyIndicates_MixedSuccessesAndFailur defaultTestRelays); nostrService->openRelayConnections(); - EXPECT_CALL(*mockClient, send(_, defaultTestRelays[0])) + // Simulate a scenario where the message fails to send to one relay, but sends successfully to + // the other, and the relay accepts it. + EXPECT_CALL(*mockClient, send(_, defaultTestRelays[0], _)) .Times(1) - .WillRepeatedly(Invoke([](string message, string uri) + .WillRepeatedly(Invoke([](string message, string uri, function<void(const string&)> messageHandler) { + json messageArr = json::parse(message); + auto event = nostr::Event::fromString(messageArr[1]); + + json jarr = json::array({ "OK", event.id, true, "Event accepted" }); + messageHandler(jarr.dump()); + return make_tuple(uri, true); })); - EXPECT_CALL(*mockClient, send(_, defaultTestRelays[1])) + EXPECT_CALL(*mockClient, send(_, defaultTestRelays[1], _)) .Times(1) - .WillRepeatedly(Invoke([](string message, string uri) + .WillRepeatedly(Invoke([](string message, string uri, function<void(const string&)> messageHandler) { return make_tuple(uri, false); })); @@ -534,4 +549,10 @@ TEST_F(NostrServiceTest, PublishEvent_CorrectlyIndicates_MixedSuccessesAndFailur ASSERT_EQ(failures.size(), 1); ASSERT_EQ(failures[0], defaultTestRelays[1]); }; + +// TODO: Add unit tests for events rejected by relays. + +// TODO: Add unit tests for queries. + +// TODO: Add unit tests for closing subscriptions. } // namespace nostr_test |