message: Add tests for httpExchange AbortError and redirect mode status
diff: @@ -61,12 +61,12 @@ describe('httpExchange', () => {
  });
  it('errors with CombinedError', done => {
  - (global as any).fetch.mockReturnValue(
  - Promise.resolve({
  + const response = {
  json: () => ({ errors: ['error message'] }),
  status: 200,
  - })
  - );
  + };
  +
  + (global as any).fetch.mockReturnValue(Promise.resolve(response));
  const exchange = httpExchange();
  const operation = {
  @@ -176,4 +176,97 @@ describe('httpExchange', () => {
  },
  });
  });
  +
  + it('ignores AbortErrors', done => {
  + const err = new Error();
  + err.name = 'AbortError';
  + (global as any).fetch.mockReturnValue(Promise.reject(err));
  +
  + const exchange = httpExchange();
  + const operation = {
  + context: {
  + fetchOptions: {},
  + url: 'http://localhost:3000/graphql',
  + },
  + key: 'test',
  + operationName: 'query',
  + query: `{ ping }`,
  + };
  +
  + exchange(operation).subscribe({
  + error: () => {
  + throw new Error('Should not be called');
  + },
  + next: () => {
  + throw new Error('Should not be called');
  + },
  + });
  +
  + setTimeout(done);
  + });
  +
  + it('does not error on manual redirect mode for 3xx status codes', done => {
  + (global as any).fetch.mockReturnValue(
  + Promise.resolve({
  + json: () => ({ data: [{ id: 5 }] }),
  + status: 302,
  + })
  + );
  +
  + const exchange = httpExchange();
  + const operation = {
  + context: {
  + fetchOptions: {
  + redirect: 'manual',
  + },
  + url: 'http://localhost:3000/graphql',
  + },
  + key: 'test',
  + operationName: 'query',
  + query: `{ ping }`,
  + variables: {},
  + };
  +
  + exchange(operation).subscribe({
  + error: err => {
  + throw err;
  + },
  + next: x => {
  + expect(x).toEqual({ data: [{ id: 5 }] });
  + done();
  + },
  + });
  + });
  +
  + it('errors outside of 2xx status code in the usual redirect mode', done => {
  + (global as any).fetch.mockReturnValue(
  + Promise.resolve({
  + json: () => ({ data: [{ id: 5 }] }),
  + statusText: 'test',
  + status: 302,
  + })
  + );
  +
  + const exchange = httpExchange();
  + const operation = {
  + context: {
  + fetchOptions: {},
  + url: 'http://localhost:3000/graphql',
  + },
  + key: 'test',
  + operationName: 'query',
  + query: `{ ping }`,
  + variables: {},
  + };
  +
  + exchange(operation).subscribe({
  + error: err => {
  + expect(err.networkError.message).toBe('test');
  + done();
  + },
  + next: () => {
  + throw new Error('Should not be called');
  + },
  + });
  + });
  });
  