|
16 | 16 | */ |
17 | 17 |
|
18 | 18 | import * as _ from 'lodash'; |
19 | | -import { expect } from 'chai'; |
| 19 | +import * as chai from 'chai'; |
20 | 20 | import * as sinon from 'sinon'; |
| 21 | +import * as sinonChai from 'sinon-chai'; |
| 22 | +import * as chaiAsPromised from 'chai-as-promised'; |
| 23 | + |
| 24 | +chai.should(); |
| 25 | +chai.use(sinonChai); |
| 26 | +chai.use(chaiAsPromised); |
| 27 | + |
| 28 | +const expect = chai.expect; |
21 | 29 | import { |
22 | 30 | AuthorizedHttpClient, |
23 | 31 | HttpClient, |
@@ -252,6 +260,72 @@ describe('DataConnectApiClient', () => { |
252 | 260 | return apiClient.executeGraphql('query', {}) |
253 | 261 | .should.eventually.be.rejected.and.deep.include(expected); |
254 | 262 | }); |
| 263 | + |
| 264 | + it('should reject when GraphQL errors with debugDetails are returned', async () => { |
| 265 | + const gqlErrorResponse = { |
| 266 | + errors: [ |
| 267 | + { |
| 268 | + message: 'SQL execution failed', |
| 269 | + path: ['content_update'], |
| 270 | + extensions: { |
| 271 | + code: 'INTERNAL', |
| 272 | + debugDetails: 'Quota exceeded for quota metric Connect Queries' |
| 273 | + } |
| 274 | + } |
| 275 | + ] |
| 276 | + }; |
| 277 | + sandbox |
| 278 | + .stub(HttpClient.prototype, 'send') |
| 279 | + .resolves(utils.responseFrom(gqlErrorResponse, 200)); |
| 280 | + |
| 281 | + await expect(apiClient.executeGraphql('query', {})) |
| 282 | + .to.be.rejectedWith( |
| 283 | + FirebaseDataConnectError, |
| 284 | + 'SQL execution failed: Quota exceeded for quota metric Connect Queries' |
| 285 | + ); |
| 286 | + }); |
| 287 | + |
| 288 | + it('should reject and format multiple GraphQL errors', async () => { |
| 289 | + const gqlErrorResponse = { |
| 290 | + errors: [ |
| 291 | + { message: 'First error' }, |
| 292 | + { |
| 293 | + message: 'Second error', |
| 294 | + extensions: { debugDetails: 'detailed failure' } |
| 295 | + } |
| 296 | + ] |
| 297 | + }; |
| 298 | + sandbox |
| 299 | + .stub(HttpClient.prototype, 'send') |
| 300 | + .resolves(utils.responseFrom(gqlErrorResponse, 200)); |
| 301 | + |
| 302 | + await expect(apiClient.executeGraphql('query', {})) |
| 303 | + .to.be.rejectedWith( |
| 304 | + FirebaseDataConnectError, |
| 305 | + 'First error; Second error: detailed failure' |
| 306 | + ); |
| 307 | + }); |
| 308 | + |
| 309 | + it('should reject with formatted GraphQL errors on non-200 HTTP response', async () => { |
| 310 | + const gqlErrorResponse = { |
| 311 | + errors: [ |
| 312 | + { |
| 313 | + message: 'Bad request', |
| 314 | + extensions: { debugDetails: 'Field not found' } |
| 315 | + } |
| 316 | + ] |
| 317 | + }; |
| 318 | + const mockErr = utils.errorFrom(gqlErrorResponse, 400); |
| 319 | + sandbox |
| 320 | + .stub(HttpClient.prototype, 'send') |
| 321 | + .rejects(mockErr); |
| 322 | + |
| 323 | + await expect(apiClient.executeGraphql('query', {})) |
| 324 | + .to.be.rejectedWith( |
| 325 | + FirebaseDataConnectError, |
| 326 | + 'Bad request: Field not found' |
| 327 | + ); |
| 328 | + }); |
255 | 329 | }); |
256 | 330 |
|
257 | 331 | it('should resolve with the GraphQL response on success', async () => { |
|
0 commit comments