@@ -53,28 +53,28 @@ public void Setup()
53
53
public void ShouldParseSuccessfulResponse ( )
54
54
{
55
55
const string RESPONSE_JSON = @"
56
- {
57
- ""data"": {
58
- ""customer"": {
59
- ""audiences"": {
60
- ""edges"": [
61
- {
62
- ""node"": {
63
- ""name"": ""has_email"",
64
- ""state"": ""qualified"",
65
- }
66
- },
67
- {
68
- ""node"": {
69
- ""name"": ""has_email_opted_in"",
70
- ""state"": ""not-qualified""
56
+ {
57
+ ""data"": {
58
+ ""customer"": {
59
+ ""audiences"": {
60
+ ""edges"": [
61
+ {
62
+ ""node"": {
63
+ ""name"": ""has_email"",
64
+ ""state"": ""qualified"",
65
+ }
66
+ },
67
+ {
68
+ ""node"": {
69
+ ""name"": ""has_email_opted_in"",
70
+ ""state"": ""not-qualified""
71
+ }
72
+ },
73
+ ]
74
+ },
71
75
}
72
- },
73
- ]
74
- },
75
- }
76
- }
77
- }" ;
76
+ }
77
+ }" ;
78
78
79
79
var response = new OdpSegmentApiManager ( ) . DeserializeSegmentsFromJson ( RESPONSE_JSON ) ;
80
80
@@ -110,38 +110,207 @@ public void ShouldHandleAttemptToDeserializeInvalidJsonResponse()
110
110
}
111
111
112
112
[ Test ]
113
- public void ShouldParseErrorResponse ( )
113
+ public void ShouldParseInvalidIdentifierExceptionResponse ( )
114
114
{
115
115
const string RESPONSE_JSON = @"
116
- {
117
- ""errors"": [
118
- {
119
- ""message"": ""Exception while fetching data (/customer) : Exception: could not resolve _fs_user_id = not-real-user-id"",
120
- ""locations"": [
121
- {
122
- ""line"": 2,
123
- ""column"": 3
116
+ {
117
+ ""errors"": [
118
+ {
119
+ ""message"": ""Exception while fetching data (/customer) : Exception: could not resolve _fs_user_id = not-real-user-id"",
120
+ ""locations"": [
121
+ {
122
+ ""line"": 2,
123
+ ""column"": 3
124
+ }
125
+ ],
126
+ ""path"": [
127
+ ""customer""
128
+ ],
129
+ ""extensions"": {
130
+ ""code"": ""INVALID_IDENTIFIER_EXCEPTION"",
131
+ ""classification"": ""DataFetchingException""
132
+ }
133
+ }
134
+ ],
135
+ ""data"": {
136
+ ""customer"": null
124
137
}
125
- ],
126
- ""path"": [
127
- ""customer""
128
- ],
129
- ""extensions"": {
130
- ""classification"": ""InvalidIdentifierException""
131
- }
132
- }
133
- ],
134
- ""data"": {
135
- ""customer"": null
136
- }
137
- }" ;
138
+ }" ;
138
139
139
140
var response = new OdpSegmentApiManager ( ) . DeserializeSegmentsFromJson ( RESPONSE_JSON ) ;
140
141
141
142
Assert . IsNull ( response . Data . Customer ) ;
142
143
Assert . IsNotNull ( response . Errors ) ;
143
- Assert . AreEqual ( response . Errors [ 0 ] . Extensions . Classification ,
144
- "InvalidIdentifierException" ) ;
144
+ Assert . AreEqual ( "DataFetchingException" ,
145
+ response . Errors [ 0 ] . Extensions . Classification ) ;
146
+ Assert . AreEqual ( "INVALID_IDENTIFIER_EXCEPTION" ,
147
+ response . Errors [ 0 ] . Extensions . Code
148
+ ) ;
149
+ }
150
+
151
+ [ Test ]
152
+ public void ShouldParseOnlyFirstErrorInvalidIdentifierExceptionResponse ( )
153
+ {
154
+ const string RESPONSE_JSON = @"
155
+ {
156
+ ""errors"": [
157
+ {
158
+ ""message"": ""Exception while fetching data (/customer) : Exception: could not resolve _fs_user_id = not-real-user-id"",
159
+ ""locations"": [
160
+ {
161
+ ""line"": 2,
162
+ ""column"": 3
163
+ }
164
+ ],
165
+ ""path"": [
166
+ ""customer""
167
+ ],
168
+ ""extensions"": {
169
+ ""code"": ""INVALID_IDENTIFIER_EXCEPTION"",
170
+ ""classification"": ""DataFetchingException""
171
+ }
172
+ },
173
+ {
174
+ ""message"": ""Second Ignored Exception while fetching data (/desks) : Exception: yet another exception not yet known"",
175
+ ""locations"": [
176
+ {
177
+ ""line"": 4,
178
+ ""column"": 5
179
+ }
180
+ ],
181
+ ""path"": [
182
+ ""desks/wooden""
183
+ ],
184
+ ""extensions"": {
185
+ ""code"": ""SECOND_IGNORED_UNPLANNED_EXCEPTION"",
186
+ ""classification"": ""IgnoredNewException""
187
+ }
188
+ }
189
+ ],
190
+ ""data"": {
191
+ ""customer"": null
192
+ }
193
+ }" ;
194
+ var httpClient = HttpClientTestUtil . MakeHttpClient ( HttpStatusCode . OK , RESPONSE_JSON ) ;
195
+ var manager =
196
+ new OdpSegmentApiManager ( _mockLogger . Object , _mockErrorHandler . Object , httpClient ) ;
197
+
198
+ var segments = manager . FetchSegments (
199
+ VALID_ODP_PUBLIC_KEY ,
200
+ ODP_GRAPHQL_HOST ,
201
+ Constants . FS_USER_ID ,
202
+ "tester-156" ,
203
+ _segmentsToCheck ) ;
204
+
205
+
206
+ Assert . IsNull ( segments ) ;
207
+ _mockLogger . Verify (
208
+ l => l . Log ( LogLevel . WARN , "Audience segments fetch failed (invalid identifier)" ) ,
209
+ Times . Once ) ;
210
+ }
211
+
212
+ [ Test ]
213
+ public void ShouldParseOnlyFirstErrorThatOdpThrowsAtUsResponse ( )
214
+ {
215
+ const string RESPONSE_JSON = @"
216
+ {
217
+ ""errors"": [
218
+ {
219
+ ""message"": ""Exception while fetching data (/chairs) : Exception: could not the chair = musical"",
220
+ ""locations"": [
221
+ {
222
+ ""line"": 4,
223
+ ""column"": 1
224
+ }
225
+ ],
226
+ ""path"": [
227
+ ""chair/musical""
228
+ ],
229
+ ""extensions"": {
230
+ ""classification"": ""YetKnownOdpException""
231
+ }
232
+ },
233
+ {
234
+ ""message"": ""Second Ignored Exception while fetching data (/desks) : Exception: yet another exception not yet known"",
235
+ ""locations"": [
236
+ {
237
+ ""line"": 4,
238
+ ""column"": 5
239
+ }
240
+ ],
241
+ ""path"": [
242
+ ""desks/wooden""
243
+ ],
244
+ ""extensions"": {
245
+ ""code"": ""SECOND_IGNORED_UNPLANNED_EXCEPTION"",
246
+ ""classification"": ""IgnoredNewException""
247
+ }
248
+ }
249
+ ],
250
+ ""data"": {
251
+ ""customer"": null
252
+ }
253
+ }" ;
254
+ var httpClient = HttpClientTestUtil . MakeHttpClient ( HttpStatusCode . OK , RESPONSE_JSON ) ;
255
+ var manager =
256
+ new OdpSegmentApiManager ( _mockLogger . Object , _mockErrorHandler . Object , httpClient ) ;
257
+
258
+ var segments = manager . FetchSegments (
259
+ VALID_ODP_PUBLIC_KEY ,
260
+ ODP_GRAPHQL_HOST ,
261
+ Constants . FS_USER_ID ,
262
+ "tester-325" ,
263
+ _segmentsToCheck ) ;
264
+
265
+
266
+ Assert . IsNull ( segments ) ;
267
+ _mockLogger . Verify (
268
+ l => l . Log ( LogLevel . ERROR ,
269
+ "Audience segments fetch failed (YetKnownOdpException)" ) ,
270
+ Times . Once ) ;
271
+ }
272
+
273
+
274
+ [ Test ]
275
+ public void ShouldParseBadExtensionsShapeInResponse ( )
276
+ {
277
+ const string RESPONSE_JSON = @"
278
+ {
279
+ ""errors"": [
280
+ {
281
+ ""message"": ""Exception while fetching data (/chairs) : Exception: could not the chair = musical"",
282
+ ""locations"": [
283
+ {
284
+ ""line"": 4,
285
+ ""column"": 1
286
+ }
287
+ ],
288
+ ""path"": [
289
+ ""chair/musical""
290
+ ],
291
+ ""extensions"": { }
292
+ }
293
+ ],
294
+ ""data"": {
295
+ ""customer"": null
296
+ }
297
+ }" ;
298
+ var httpClient = HttpClientTestUtil . MakeHttpClient ( HttpStatusCode . OK , RESPONSE_JSON ) ;
299
+ var manager =
300
+ new OdpSegmentApiManager ( _mockLogger . Object , _mockErrorHandler . Object , httpClient ) ;
301
+
302
+ var segments = manager . FetchSegments (
303
+ VALID_ODP_PUBLIC_KEY ,
304
+ ODP_GRAPHQL_HOST ,
305
+ Constants . FS_USER_ID ,
306
+ "tester-895" ,
307
+ _segmentsToCheck ) ;
308
+
309
+
310
+ Assert . IsNull ( segments ) ;
311
+ _mockLogger . Verify (
312
+ l => l . Log ( LogLevel . ERROR , "Audience segments fetch failed (decode error)" ) ,
313
+ Times . Once ) ;
145
314
}
146
315
147
316
[ Test ]
0 commit comments