@@ -785,6 +785,54 @@ TEST_F(TodayServiceCase, NestedFragmentDirectives)
785
785
}
786
786
}
787
787
788
+ TEST_F (TodayServiceCase, QueryAppointmentsById)
789
+ {
790
+ auto ast = R"( query SpecificAppointment($appointmentId: ID!) {
791
+ appointmentsById(ids: [$appointmentId]) {
792
+ appointmentId: id
793
+ subject
794
+ when
795
+ isNow
796
+ }
797
+ })" _graphql;
798
+ response::Value variables (response::Type::Map);
799
+ variables.emplace_back (" appointmentId" , response::Value (std::string (" ZmFrZUFwcG9pbnRtZW50SWQ=" )));
800
+ auto state = std::make_shared<today::RequestState>(12 );
801
+ auto result = _service->resolve (state, *ast->root , " " , std::move (variables)).get ();
802
+ EXPECT_EQ (size_t (1 ), _getAppointmentsCount) << " today service lazy loads the appointments and caches the result" ;
803
+ EXPECT_GE (size_t (1 ), _getTasksCount) << " today service lazy loads the tasks and caches the result" ;
804
+ EXPECT_GE (size_t (1 ), _getUnreadCountsCount) << " today service lazy loads the unreadCounts and caches the result" ;
805
+ EXPECT_EQ (size_t (12 ), state->appointmentsRequestId ) << " today service passed the same RequestState" ;
806
+ EXPECT_EQ (size_t (0 ), state->tasksRequestId ) << " today service did not call the loader" ;
807
+ EXPECT_EQ (size_t (0 ), state->unreadCountsRequestId ) << " today service did not call the loader" ;
808
+ EXPECT_EQ (size_t (1 ), state->loadAppointmentsCount ) << " today service called the loader once" ;
809
+ EXPECT_EQ (size_t (0 ), state->loadTasksCount ) << " today service did not call the loader" ;
810
+ EXPECT_EQ (size_t (0 ), state->loadUnreadCountsCount ) << " today service did not call the loader" ;
811
+
812
+ try
813
+ {
814
+ ASSERT_TRUE (result.type () == response::Type::Map);
815
+ auto errorsItr = result.find (" errors" );
816
+ if (errorsItr != result.get <const response::MapType&>().cend ())
817
+ {
818
+ FAIL () << response::toJSON (response::Value (errorsItr->second ));
819
+ }
820
+ const auto data = service::ScalarArgument::require (" data" , result);
821
+
822
+ const auto appointmentsById = service::ScalarArgument::require<service::TypeModifier::List>(" appointmentsById" , data);
823
+ ASSERT_EQ (size_t (1 ), appointmentsById.size ());
824
+ const auto & appointmentEntry = appointmentsById.front ();
825
+ EXPECT_EQ (_fakeAppointmentId, service::IdArgument::require (" appointmentId" , appointmentEntry)) << " id should match in base64 encoding" ;
826
+ EXPECT_EQ (" Lunch?" , service::StringArgument::require (" subject" , appointmentEntry)) << " subject should match" ;
827
+ EXPECT_EQ (" tomorrow" , service::StringArgument::require (" when" , appointmentEntry)) << " when should match" ;
828
+ EXPECT_FALSE (service::BooleanArgument::require (" isNow" , appointmentEntry)) << " isNow should match" ;
829
+ }
830
+ catch (const service::schema_exception& ex)
831
+ {
832
+ FAIL () << response::toJSON (response::Value (ex.getErrors ()));
833
+ }
834
+ }
835
+
788
836
TEST (ArgumentsCase, ListArgumentStrings)
789
837
{
790
838
auto parsed = response::parseJSON (R"js( {"value":[
0 commit comments