@@ -90,17 +90,6 @@ size_t TodayServiceCase::_getAppointmentsCount = 0;
9090size_t TodayServiceCase::_getTasksCount = 0 ;
9191size_t TodayServiceCase::_getUnreadCountsCount = 0 ;
9292
93- struct TestRequestId
94- : service::RequestState
95- {
96- TestRequestId (size_t id)
97- : _id(id)
98- {
99- }
100-
101- size_t _id;
102- };
103-
10493TEST_F (TodayServiceCase, QueryEverything)
10594{
10695 auto ast = R"(
@@ -135,11 +124,18 @@ TEST_F(TodayServiceCase, QueryEverything)
135124 }
136125 })" _graphql;
137126 response::Value variables (response::Type::Map);
138- auto state = std::make_shared<TestRequestId>( 0 );
127+ auto state = std::make_shared<today::RequestState>( 1 );
139128 auto result = _service->resolve (state, *ast->root , " Everything" , variables).get ();
140129 EXPECT_EQ (size_t (1 ), _getAppointmentsCount) << " today service lazy loads the appointments and caches the result" ;
141130 EXPECT_EQ (size_t (1 ), _getTasksCount) << " today service lazy loads the tasks and caches the result" ;
142131 EXPECT_EQ (size_t (1 ), _getUnreadCountsCount) << " today service lazy loads the unreadCounts and caches the result" ;
132+ EXPECT_EQ (size_t (1 ), state->appointmentsRequestId ) << " today service passed the same RequestState" ;
133+ EXPECT_EQ (size_t (1 ), state->tasksRequestId ) << " today service passed the same RequestState" ;
134+ EXPECT_EQ (size_t (1 ), state->unreadCountsRequestId ) << " today service passed the same RequestState" ;
135+ EXPECT_EQ (size_t (1 ), state->loadAppointmentsCount ) << " today service called the loader once" ;
136+ EXPECT_EQ (size_t (1 ), state->loadTasksCount ) << " today service called the loader once" ;
137+ EXPECT_EQ (size_t (1 ), state->loadUnreadCountsCount ) << " today service called the loader once" ;
138+
143139
144140 try
145141 {
@@ -210,11 +206,17 @@ TEST_F(TodayServiceCase, QueryAppointments)
210206 }
211207 })" _graphql;
212208 response::Value variables (response::Type::Map);
213- auto state = std::make_shared<TestRequestId>( 1 );
209+ auto state = std::make_shared<today::RequestState>( 2 );
214210 auto result = _service->resolve (state, *ast->root , " " , variables).get ();
215211 EXPECT_EQ (size_t (1 ), _getAppointmentsCount) << " today service lazy loads the appointments and caches the result" ;
216212 EXPECT_GE (size_t (1 ), _getTasksCount) << " today service lazy loads the tasks and caches the result" ;
217213 EXPECT_GE (size_t (1 ), _getUnreadCountsCount) << " today service lazy loads the unreadCounts and caches the result" ;
214+ EXPECT_EQ (size_t (2 ), state->appointmentsRequestId ) << " today service passed the same RequestState" ;
215+ EXPECT_EQ (size_t (0 ), state->tasksRequestId ) << " today service did not call the loader" ;
216+ EXPECT_EQ (size_t (0 ), state->unreadCountsRequestId ) << " today service did not call the loader" ;
217+ EXPECT_EQ (size_t (1 ), state->loadAppointmentsCount ) << " today service called the loader once" ;
218+ EXPECT_EQ (size_t (0 ), state->loadTasksCount ) << " today service did not call the loader" ;
219+ EXPECT_EQ (size_t (0 ), state->loadUnreadCountsCount ) << " today service did not call the loader" ;
218220
219221 try
220222 {
@@ -266,11 +268,17 @@ TEST_F(TodayServiceCase, QueryTasks)
266268 }
267269 })gql" _graphql;
268270 response::Value variables (response::Type::Map);
269- auto state = std::make_shared<TestRequestId>( 2 );
271+ auto state = std::make_shared<today::RequestState>( 3 );
270272 auto result = _service->resolve (state, *ast->root , " " , variables).get ();
271273 EXPECT_GE (size_t (1 ), _getAppointmentsCount) << " today service lazy loads the appointments and caches the result" ;
272274 EXPECT_EQ (size_t (1 ), _getTasksCount) << " today service lazy loads the tasks and caches the result" ;
273275 EXPECT_GE (size_t (1 ), _getUnreadCountsCount) << " today service lazy loads the unreadCounts and caches the result" ;
276+ EXPECT_EQ (size_t (0 ), state->appointmentsRequestId ) << " today service did not call the loader" ;
277+ EXPECT_EQ (size_t (3 ), state->tasksRequestId ) << " today service passed the same RequestState" ;
278+ EXPECT_EQ (size_t (0 ), state->unreadCountsRequestId ) << " today service did not call the loader" ;
279+ EXPECT_EQ (size_t (0 ), state->loadAppointmentsCount ) << " today service did not call the loader" ;
280+ EXPECT_EQ (size_t (1 ), state->loadTasksCount ) << " today service called the loader once" ;
281+ EXPECT_EQ (size_t (0 ), state->loadUnreadCountsCount ) << " today service did not call the loader" ;
274282
275283 try
276284 {
@@ -321,11 +329,17 @@ TEST_F(TodayServiceCase, QueryUnreadCounts)
321329 }
322330 })" _graphql;
323331 response::Value variables (response::Type::Map);
324- auto state = std::make_shared<TestRequestId>( 3 );
332+ auto state = std::make_shared<today::RequestState>( 4 );
325333 auto result = _service->resolve (state, *ast->root , " " , variables).get ();
326334 EXPECT_GE (size_t (1 ), _getAppointmentsCount) << " today service lazy loads the appointments and caches the result" ;
327335 EXPECT_GE (size_t (1 ), _getTasksCount) << " today service lazy loads the tasks and caches the result" ;
328336 EXPECT_EQ (size_t (1 ), _getUnreadCountsCount) << " today service lazy loads the unreadCounts and caches the result" ;
337+ EXPECT_EQ (size_t (0 ), state->appointmentsRequestId ) << " today service did not call the loader" ;
338+ EXPECT_EQ (size_t (0 ), state->tasksRequestId ) << " today service did not call the loader" ;
339+ EXPECT_EQ (size_t (4 ), state->unreadCountsRequestId ) << " today service passed the same RequestState" ;
340+ EXPECT_EQ (size_t (0 ), state->loadAppointmentsCount ) << " today service did not call the loader" ;
341+ EXPECT_EQ (size_t (0 ), state->loadTasksCount ) << " today service did not call the loader" ;
342+ EXPECT_EQ (size_t (1 ), state->loadUnreadCountsCount ) << " today service called the loader once" ;
329343
330344 try
331345 {
@@ -375,7 +389,7 @@ TEST_F(TodayServiceCase, MutateCompleteTask)
375389 }
376390 })" _graphql;
377391 response::Value variables (response::Type::Map);
378- auto state = std::make_shared<TestRequestId>( 4 );
392+ auto state = std::make_shared<today::RequestState>( 5 );
379393 auto result = _service->resolve (state, *ast->root , " " , variables).get ();
380394
381395 try
@@ -451,7 +465,7 @@ TEST_F(TodayServiceCase, Introspection)
451465 }
452466 })" _graphql;
453467 response::Value variables (response::Type::Map);
454- auto state = std::make_shared<TestRequestId>( 5 );
468+ auto state = std::make_shared<today::RequestState>( 6 );
455469 auto result = _service->resolve (state, *ast->root , " " , variables).get ();
456470
457471 try
0 commit comments