@@ -922,6 +922,57 @@ TEST_F(TodayServiceCase, SubscribeNodeChangeMismatchedId)
922
922
}
923
923
}
924
924
925
+ TEST_F (TodayServiceCase, SubscribeNodeChangeMatchingVariable)
926
+ {
927
+ auto ast = peg::parseString (R"( subscription TestSubscription($taskId: ID!) {
928
+ changedNode: nodeChange(id: $taskId) {
929
+ changedId: id
930
+ ...on Task {
931
+ title
932
+ isComplete
933
+ }
934
+ }
935
+ })" );
936
+ response::Value variables (response::Type::Map);
937
+ variables.emplace_back (" taskId" , response::Value (std::string (" ZmFrZVRhc2tJZA==" )));
938
+ auto state = std::make_shared<today::RequestState>(14 );
939
+ auto subscriptionObject = std::make_shared<today::NodeChange>(
940
+ [this ](const std::shared_ptr<service::RequestState>& state, std::vector<uint8_t >&& idArg) -> std::shared_ptr<service::Object>
941
+ {
942
+ EXPECT_EQ (14 , std::static_pointer_cast<today::RequestState>(state)->requestId ) << " should pass the RequestState to the subscription resolvers" ;
943
+ EXPECT_EQ (_fakeTaskId, idArg);
944
+ return std::static_pointer_cast<service::Object>(std::make_shared<today::Task>(std::vector<uint8_t >(_fakeTaskId), " Don't forget" , true ));
945
+ });
946
+ response::Value result;
947
+ auto key = _service->subscribe (service::SubscriptionParams { state, std::move (ast), " TestSubscription" , std::move (std::move (variables)) },
948
+ [&result](std::future<response::Value> response)
949
+ {
950
+ result = response.get ();
951
+ });
952
+ _service->deliver (" nodeChange" , { {" id" , response::Value (std::string (" ZmFrZVRhc2tJZA==" )) } }, std::static_pointer_cast<service::Object>(subscriptionObject));
953
+ _service->unsubscribe (key);
954
+
955
+ try
956
+ {
957
+ ASSERT_TRUE (result.type () == response::Type::Map);
958
+ auto errorsItr = result.find (" errors" );
959
+ if (errorsItr != result.get <const response::MapType&>().cend ())
960
+ {
961
+ FAIL () << response::toJSON (response::Value (errorsItr->second ));
962
+ }
963
+ const auto data = service::ScalarArgument::require (" data" , result);
964
+
965
+ const auto taskNode = service::ScalarArgument::require (" changedNode" , data);
966
+ EXPECT_EQ (_fakeTaskId, service::IdArgument::require (" changedId" , taskNode)) << " id should match in base64 encoding" ;
967
+ EXPECT_EQ (" Don't forget" , service::StringArgument::require (" title" , taskNode)) << " title should match" ;
968
+ EXPECT_TRUE (service::BooleanArgument::require (" isComplete" , taskNode)) << " isComplete should match" ;
969
+ }
970
+ catch (const service::schema_exception& ex)
971
+ {
972
+ FAIL () << response::toJSON (response::Value (ex.getErrors ()));
973
+ }
974
+ }
975
+
925
976
TEST (ArgumentsCase, ListArgumentStrings)
926
977
{
927
978
auto parsed = response::parseJSON (R"js( {"value":[
0 commit comments