@@ -90,17 +90,6 @@ size_t TodayServiceCase::_getAppointmentsCount = 0;
90
90
size_t TodayServiceCase::_getTasksCount = 0 ;
91
91
size_t TodayServiceCase::_getUnreadCountsCount = 0 ;
92
92
93
- struct TestRequestId
94
- : service::RequestState
95
- {
96
- TestRequestId (size_t id)
97
- : _id(id)
98
- {
99
- }
100
-
101
- size_t _id;
102
- };
103
-
104
93
TEST_F (TodayServiceCase, QueryEverything)
105
94
{
106
95
auto ast = R"(
@@ -135,11 +124,18 @@ TEST_F(TodayServiceCase, QueryEverything)
135
124
}
136
125
})" _graphql;
137
126
response::Value variables (response::Type::Map);
138
- auto state = std::make_shared<TestRequestId>( 0 );
127
+ auto state = std::make_shared<today::RequestState>( 1 );
139
128
auto result = _service->resolve (state, *ast->root , " Everything" , variables).get ();
140
129
EXPECT_EQ (size_t (1 ), _getAppointmentsCount) << " today service lazy loads the appointments and caches the result" ;
141
130
EXPECT_EQ (size_t (1 ), _getTasksCount) << " today service lazy loads the tasks and caches the result" ;
142
131
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
+
143
139
144
140
try
145
141
{
@@ -210,11 +206,17 @@ TEST_F(TodayServiceCase, QueryAppointments)
210
206
}
211
207
})" _graphql;
212
208
response::Value variables (response::Type::Map);
213
- auto state = std::make_shared<TestRequestId>( 1 );
209
+ auto state = std::make_shared<today::RequestState>( 2 );
214
210
auto result = _service->resolve (state, *ast->root , " " , variables).get ();
215
211
EXPECT_EQ (size_t (1 ), _getAppointmentsCount) << " today service lazy loads the appointments and caches the result" ;
216
212
EXPECT_GE (size_t (1 ), _getTasksCount) << " today service lazy loads the tasks and caches the result" ;
217
213
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" ;
218
220
219
221
try
220
222
{
@@ -266,11 +268,17 @@ TEST_F(TodayServiceCase, QueryTasks)
266
268
}
267
269
})gql" _graphql;
268
270
response::Value variables (response::Type::Map);
269
- auto state = std::make_shared<TestRequestId>( 2 );
271
+ auto state = std::make_shared<today::RequestState>( 3 );
270
272
auto result = _service->resolve (state, *ast->root , " " , variables).get ();
271
273
EXPECT_GE (size_t (1 ), _getAppointmentsCount) << " today service lazy loads the appointments and caches the result" ;
272
274
EXPECT_EQ (size_t (1 ), _getTasksCount) << " today service lazy loads the tasks and caches the result" ;
273
275
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" ;
274
282
275
283
try
276
284
{
@@ -321,11 +329,17 @@ TEST_F(TodayServiceCase, QueryUnreadCounts)
321
329
}
322
330
})" _graphql;
323
331
response::Value variables (response::Type::Map);
324
- auto state = std::make_shared<TestRequestId>( 3 );
332
+ auto state = std::make_shared<today::RequestState>( 4 );
325
333
auto result = _service->resolve (state, *ast->root , " " , variables).get ();
326
334
EXPECT_GE (size_t (1 ), _getAppointmentsCount) << " today service lazy loads the appointments and caches the result" ;
327
335
EXPECT_GE (size_t (1 ), _getTasksCount) << " today service lazy loads the tasks and caches the result" ;
328
336
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" ;
329
343
330
344
try
331
345
{
@@ -375,7 +389,7 @@ TEST_F(TodayServiceCase, MutateCompleteTask)
375
389
}
376
390
})" _graphql;
377
391
response::Value variables (response::Type::Map);
378
- auto state = std::make_shared<TestRequestId>( 4 );
392
+ auto state = std::make_shared<today::RequestState>( 5 );
379
393
auto result = _service->resolve (state, *ast->root , " " , variables).get ();
380
394
381
395
try
@@ -451,7 +465,7 @@ TEST_F(TodayServiceCase, Introspection)
451
465
}
452
466
})" _graphql;
453
467
response::Value variables (response::Type::Map);
454
- auto state = std::make_shared<TestRequestId>( 5 );
468
+ auto state = std::make_shared<today::RequestState>( 6 );
455
469
auto result = _service->resolve (state, *ast->root , " " , variables).get ();
456
470
457
471
try
0 commit comments