FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cppgraphqlgen/test/ClientTests.cpp at main · gitmodimo/cppgraphqlgen · GitHub
gitmodimo
/
cppgraphqlgen
Public
forked from
microsoft/cppgraphqlgen
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cppgraphqlgen
/
test
/
ClientTests.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
216 lines (185 loc) · 8.85 KB
Breadcrumbs
cppgraphqlgen
/
test
/
ClientTests.cpp
Copy path
File metadata and controls
216 lines (185 loc) · 8.85 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//
Copyright (c) Microsoft Corporation. All rights reserved.
//
Licensed under the MIT License.
#
include
<
gtest/gtest.h
>
#
include
"
MutateClient.h
"
#
include
"
QueryClient.h
"
#
include
"
SubscribeClient.h
"
#
include
"
TodayMock.h
"
#
include
<
chrono
>
using
namespace
graphql
;
using
namespace
std
::literals
;
class
ClientCase
: public ::testing::Test
{
public:
void
SetUp
()
override
{
_mockService =
today::mock_service
();
}
void
TearDown
()
override
{
_mockService.
reset
();
}
protected:
std::unique_ptr<today::TodayMockService> _mockService;
};
TEST_F
(ClientCase, QueryEverything)
{
using
namespace
client
::query::Query
;
auto
query =
GetRequestObject
();
response::Value
variables
(response::Type::Map);
auto
state = std::make_shared<today::RequestState>(
1
);
auto
result = _mockService->
service
->
resolve
({ query, {},
std::move
(variables), std::launch::async, state })
.
get
();
EXPECT_EQ
(
size_t
{
1
}, _mockService->
getAppointmentsCount
)
<<
"
today service lazy loads the appointments and caches the result
"
;
EXPECT_EQ
(
size_t
{
1
}, _mockService->
getTasksCount
)
<<
"
today service lazy loads the tasks and caches the result
"
;
EXPECT_EQ
(
size_t
{
1
}, _mockService->
getUnreadCountsCount
)
<<
"
today service lazy loads the unreadCounts and caches the result
"
;
EXPECT_EQ
(
size_t
{
1
}, state->
appointmentsRequestId
)
<<
"
today service passed the same RequestState
"
;
EXPECT_EQ
(
size_t
{
1
}, state->
tasksRequestId
) <<
"
today service passed the same RequestState
"
;
EXPECT_EQ
(
size_t
{
1
}, state->
unreadCountsRequestId
)
<<
"
today service passed the same RequestState
"
;
EXPECT_EQ
(
size_t
{
1
}, state->
loadAppointmentsCount
) <<
"
today service called the loader once
"
;
EXPECT_EQ
(
size_t
{
1
}, state->
loadTasksCount
) <<
"
today service called the loader once
"
;
EXPECT_EQ
(
size_t
{
1
}, state->
loadUnreadCountsCount
) <<
"
today service called the loader once
"
;
try
{
ASSERT_TRUE
(result.
type
() == response::Type::Map);
auto
serviceResponse =
client::parseServiceResponse
(
std::move
(result));
const
auto
response =
parseResponse
(
std::move
(serviceResponse.
data
));
EXPECT_EQ
(
size_t
{
0
}, serviceResponse.
errors
.
size
()) <<
"
no errors expected
"
;
ASSERT_TRUE
(response.
appointments
.
edges
.
has_value
()) <<
"
appointments should be set
"
;
ASSERT_EQ
(
size_t
{
1
}, response.
appointments
.
edges
->
size
())
<<
"
appointments should have 1 entry
"
;
ASSERT_TRUE
((*response.
appointments
.
edges
)[
0
].
has_value
()) <<
"
edge should be set
"
;
const
auto
& appointmentNode = (*response.
appointments
.
edges
)[
0
]->
node
;
ASSERT_TRUE
(appointmentNode.
has_value
()) <<
"
node should be set
"
;
EXPECT_EQ
(
today::getFakeAppointmentId
(), appointmentNode->
id
)
<<
"
id should match in base64 encoding
"
;
ASSERT_TRUE
(appointmentNode->
subject
.
has_value
()) <<
"
subject should be set
"
;
EXPECT_EQ
(
"
Lunch?
"
, *(appointmentNode->
subject
)) <<
"
subject should match
"
;
ASSERT_TRUE
(appointmentNode->
when
.
has_value
()) <<
"
when should be set
"
;
EXPECT_EQ
(
"
tomorrow
"
, appointmentNode->
when
->
get
<std::string>()) <<
"
when should match
"
;
EXPECT_FALSE
(appointmentNode->
isNow
) <<
"
isNow should match
"
;
EXPECT_EQ
(
"
Appointment
"
, appointmentNode->
_typename
) <<
"
__typename should match
"
;
ASSERT_TRUE
(response.
tasks
.
edges
.
has_value
()) <<
"
tasks should be set
"
;
ASSERT_EQ
(
size_t
{
1
}, response.
tasks
.
edges
->
size
()) <<
"
tasks should have 1 entry
"
;
ASSERT_TRUE
((*response.
tasks
.
edges
)[
0
].
has_value
()) <<
"
edge should be set
"
;
const
auto
& taskNode = (*response.
tasks
.
edges
)[
0
]->
node
;
ASSERT_TRUE
(taskNode.
has_value
()) <<
"
node should be set
"
;
EXPECT_EQ
(
today::getFakeTaskId
(), taskNode->
id
) <<
"
id should match in base64 encoding
"
;
ASSERT_TRUE
(taskNode->
title
.
has_value
()) <<
"
subject should be set
"
;
EXPECT_EQ
(
"
Don't forget
"
, *(taskNode->
title
)) <<
"
title should match
"
;
EXPECT_TRUE
(taskNode->
isComplete
) <<
"
isComplete should match
"
;
EXPECT_EQ
(
"
Task
"
, taskNode->
_typename
) <<
"
__typename should match
"
;
ASSERT_TRUE
(response.
unreadCounts
.
edges
.
has_value
()) <<
"
unreadCounts should be set
"
;
ASSERT_EQ
(
size_t
{
1
}, response.
unreadCounts
.
edges
->
size
())
<<
"
unreadCounts should have 1 entry
"
;
ASSERT_TRUE
((*response.
unreadCounts
.
edges
)[
0
].
has_value
()) <<
"
edge should be set
"
;
const
auto
& unreadCountNode = (*response.
unreadCounts
.
edges
)[
0
]->
node
;
ASSERT_TRUE
(unreadCountNode.
has_value
()) <<
"
node should be set
"
;
EXPECT_EQ
(
today::getFakeFolderId
(), unreadCountNode->
id
)
<<
"
id should match in base64 encoding
"
;
ASSERT_TRUE
(unreadCountNode->
name
.
has_value
()) <<
"
name should be set
"
;
EXPECT_EQ
(
"
\"
Fake
\"
Inbox
"
, *(unreadCountNode->
name
)) <<
"
name should match
"
;
EXPECT_EQ
(
3
, unreadCountNode->
unreadCount
) <<
"
unreadCount should match
"
;
EXPECT_EQ
(
"
Folder
"
, unreadCountNode->
_typename
) <<
"
__typename should match
"
;
EXPECT_EQ
(client::query::Query::TaskState::Unassigned, response.
testTaskState
)
<<
"
testTaskState should match
"
;
ASSERT_EQ
(
size_t
{
1
}, response.
anyType
.
size
()) <<
"
anyType should have 1 entry
"
;
ASSERT_TRUE
(response.
anyType
[
0
].
has_value
()) <<
"
appointment should be set
"
;
const
auto
& anyType = *response.
anyType
[
0
];
EXPECT_EQ
(
"
Appointment
"
, anyType.
_typename
) <<
"
__typename should match
"
;
EXPECT_EQ
(
today::getFakeAppointmentId
(), anyType.
id
)
<<
"
id should match in base64 encoding
"
;
EXPECT_FALSE
(anyType.
title
.
has_value
()) <<
"
appointment should not have a title
"
;
EXPECT_FALSE
(anyType.
isComplete
) <<
"
appointment should not set isComplete
"
;
ASSERT_TRUE
(anyType.
subject
.
has_value
()) <<
"
subject should be set
"
;
EXPECT_EQ
(
"
Lunch?
"
, *(anyType.
subject
)) <<
"
subject should match
"
;
ASSERT_TRUE
(anyType.
when
.
has_value
()) <<
"
when should be set
"
;
EXPECT_EQ
(
"
tomorrow
"
, anyType.
when
->
get
<std::string>()) <<
"
when should match
"
;
EXPECT_FALSE
(anyType.
isNow
) <<
"
isNow should match
"
;
}
catch
(
const
std::logic_error& ex)
{
FAIL
() << ex.
what
();
}
}
TEST_F
(ClientCase, MutateCompleteTask)
{
using
namespace
client
::mutation::CompleteTaskMutation
;
auto
query =
GetRequestObject
();
auto
variables =
serializeVariables
(
{ std::make_unique<CompleteTaskInput>(CompleteTaskInput {
today::getFakeTaskId
(),
std::
nullopt
,
std::make_optional
(
true
),
std::make_optional
(
"
Hi There!
"
s) }) });
auto
state = std::make_shared<today::RequestState>(
5
);
auto
result =
_mockService->
service
->
resolve
({ query, {},
std::move
(variables), {}, state }).
get
();
try
{
ASSERT_TRUE
(result.
type
() == response::Type::Map);
auto
serviceResponse =
client::parseServiceResponse
(
std::move
(result));
const
auto
response =
parseResponse
(
std::move
(serviceResponse.
data
));
EXPECT_EQ
(
size_t
{
0
}, serviceResponse.
errors
.
size
()) <<
"
no errors expected
"
;
const
auto
& completedTask = response.
completedTask
;
const
auto
& task = completedTask.
completedTask
;
ASSERT_TRUE
(task.
has_value
()) <<
"
should get back a task
"
;
EXPECT_EQ
(
today::getFakeTaskId
(), task->
completedTaskId
)
<<
"
id should match in base64 encoding
"
;
ASSERT_TRUE
(task->
title
.
has_value
()) <<
"
title should be set
"
;
EXPECT_EQ
(
"
Mutated Task!
"
, *(task->
title
)) <<
"
title should match
"
;
EXPECT_TRUE
(task->
isComplete
) <<
"
isComplete should match
"
;
const
auto
& clientMutationId = completedTask.
clientMutationId
;
ASSERT_TRUE
(clientMutationId.
has_value
()) <<
"
clientMutationId should be set
"
;
EXPECT_EQ
(
"
Hi There!
"
, *clientMutationId) <<
"
clientMutationId should match
"
;
}
catch
(
const
std::logic_error& ex)
{
FAIL
() << ex.
what
();
}
}
TEST_F
(ClientCase, SubscribeNextAppointmentChangeDefault)
{
using
namespace
client
::subscription::TestSubscription
;
auto
query =
GetRequestObject
();
response::Value
variables
(response::Type::Map);
auto
state = std::make_shared<today::RequestState>(
6
);
response::Value result;
auto
key = _mockService->
service
->
subscribe
({ [&result](response::Value&& response) {
result =
std::move
(response);
},
std::move
(query),
"
TestSubscription
"
s,
std::move
(variables),
{},
state })
.
get
();
_mockService->
service
->
deliver
({
"
nextAppointmentChange
"
sv }).
get
();
_mockService->
service
->
unsubscribe
({ key }).
get
();
try
{
ASSERT_TRUE
(result.
type
() == response::Type::Map);
auto
serviceResponse =
client::parseServiceResponse
(
std::move
(result));
const
auto
response =
parseResponse
(
std::move
(serviceResponse.
data
));
EXPECT_EQ
(
size_t
{
0
}, serviceResponse.
errors
.
size
()) <<
"
no errors expected
"
;
const
auto
& appointmentNode = response.
nextAppointment
;
ASSERT_TRUE
(appointmentNode.
has_value
()) <<
"
should get back a task
"
;
EXPECT_EQ
(
today::getFakeAppointmentId
(), appointmentNode->
nextAppointmentId
)
<<
"
id should match in base64 encoding
"
;
ASSERT_TRUE
(appointmentNode->
subject
.
has_value
()) <<
"
subject should be set
"
;
EXPECT_EQ
(
"
Lunch?
"
, *(appointmentNode->
subject
)) <<
"
subject should match
"
;
ASSERT_TRUE
(appointmentNode->
when
.
has_value
()) <<
"
when should be set
"
;
EXPECT_EQ
(
"
tomorrow
"
, appointmentNode->
when
->
get
<std::string>()) <<
"
when should match
"
;
EXPECT_TRUE
(appointmentNode->
isNow
) <<
"
isNow should match
"
;
}
catch
(
const
std::logic_error& ex)
{
FAIL
() << ex.
what
();
}
}
Back
|
FazBrowse Home
|
New Git URL