Skip to content

Commit

Permalink
chore: sync canary with v0.2.x (#107)
Browse files Browse the repository at this point in the history
This pull request is migrating the following changes from `v0.2.x` to
`canary`:

* [fix: bypassed
requests](https://github.com/diego-aquino/zimic/pull/105) (#104)
  • Loading branch information
diego-aquino authored Mar 17, 2024
1 parent 60a4f3d commit 779fb6f
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import HttpSearchParams from '@/http/searchParams/HttpSearchParams';
import { createHttpInterceptorWorker } from '@/interceptor/http/interceptorWorker/factory';
import HttpInterceptorWorker from '@/interceptor/http/interceptorWorker/HttpInterceptorWorker';
import HttpRequestTracker from '@/interceptor/http/requestTracker/HttpRequestTracker';
import { expectToThrowFetchError } from '@tests/utils/fetch';
import { usingHttpInterceptor } from '@tests/utils/interceptors';

import { HttpInterceptorSchema } from '../../../types/schema';
Expand Down Expand Up @@ -434,7 +435,7 @@ export function declareDeleteHttpInterceptorTests({ platform }: SharedHttpInterc
expect(specificDeletionRequest.response.body).toEqual(users[0]);

const unmatchedDeletionPromise = fetch(`${baseURL}/users/${2}`, { method: 'DELETE' });
await expect(unmatchedDeletionPromise).rejects.toThrowError();
await expectToThrowFetchError(unmatchedDeletionPromise);
});
});

Expand All @@ -455,7 +456,7 @@ export function declareDeleteHttpInterceptorTests({ platform }: SharedHttpInterc
method: 'DELETE',
body: JSON.stringify({ name: userName } satisfies User),
});
await expect(deletionPromise).rejects.toThrowError();
await expectToThrowFetchError(deletionPromise);

const deletionTrackerWithoutResponse = interceptor.delete(`/users/:id`);
expect(deletionTrackerWithoutResponse).toBeInstanceOf(HttpRequestTracker);
Expand All @@ -471,7 +472,7 @@ export function declareDeleteHttpInterceptorTests({ platform }: SharedHttpInterc
method: 'DELETE',
body: JSON.stringify({ name: userName } satisfies User),
});
await expect(deletionPromise).rejects.toThrowError();
await expectToThrowFetchError(deletionPromise);

expect(deletionRequestsWithoutResponse).toHaveLength(0);

Expand Down Expand Up @@ -617,7 +618,7 @@ export function declareDeleteHttpInterceptorTests({ platform }: SharedHttpInterc
expect(initialDeletionRequests).toHaveLength(0);

const deletionPromise = fetch(`${baseURL}/users/${1}`, { method: 'DELETE' });
await expect(deletionPromise).rejects.toThrowError();
await expectToThrowFetchError(deletionPromise);

deletionTracker.respond({
status: 200,
Expand Down Expand Up @@ -722,7 +723,7 @@ export function declareDeleteHttpInterceptorTests({ platform }: SharedHttpInterc
expect(initialDeletionRequests).toHaveLength(0);

const deletionPromise = fetch(`${baseURL}/users/${1}`, { method: 'DELETE' });
await expect(deletionPromise).rejects.toThrowError();
await expectToThrowFetchError(deletionPromise);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import HttpSearchParams from '@/http/searchParams/HttpSearchParams';
import { createHttpInterceptorWorker } from '@/interceptor/http/interceptorWorker/factory';
import HttpInterceptorWorker from '@/interceptor/http/interceptorWorker/HttpInterceptorWorker';
import HttpRequestTracker from '@/interceptor/http/requestTracker/HttpRequestTracker';
import { expectToThrowFetchError } from '@tests/utils/fetch';
import { usingHttpInterceptor } from '@tests/utils/interceptors';

import { HttpInterceptorSchema } from '../../../types/schema';
Expand Down Expand Up @@ -454,7 +455,7 @@ export function declareGetHttpInterceptorTests({ platform }: SharedHttpIntercept
expect(specificGetRequest.response.body).toEqual(users[0]);

const unmatchedGetPromise = fetch(`${baseURL}/users/${2}`, { method: 'GET' });
await expect(unmatchedGetPromise).rejects.toThrowError();
await expectToThrowFetchError(unmatchedGetPromise);
});
});

Expand All @@ -469,7 +470,7 @@ export function declareGetHttpInterceptorTests({ platform }: SharedHttpIntercept
};
}>({ worker, baseURL }, async (interceptor) => {
let fetchPromise = fetch(`${baseURL}/users`, { method: 'GET' });
await expect(fetchPromise).rejects.toThrowError();
await expectToThrowFetchError(fetchPromise);

const listTrackerWithoutResponse = interceptor.get('/users');
expect(listTrackerWithoutResponse).toBeInstanceOf(HttpRequestTracker);
Expand All @@ -482,7 +483,7 @@ export function declareGetHttpInterceptorTests({ platform }: SharedHttpIntercept
expectTypeOf<typeof listRequestWithoutResponse.response>().toEqualTypeOf<never>();

fetchPromise = fetch(`${baseURL}/users`, { method: 'GET' });
await expect(fetchPromise).rejects.toThrowError();
await expectToThrowFetchError(fetchPromise);

expect(listRequestsWithoutResponse).toHaveLength(0);

Expand Down Expand Up @@ -626,7 +627,7 @@ export function declareGetHttpInterceptorTests({ platform }: SharedHttpIntercept
expect(initialListRequests).toHaveLength(0);

const listPromise = fetch(`${baseURL}/users`, { method: 'GET' });
await expect(listPromise).rejects.toThrowError();
await expectToThrowFetchError(listPromise);

listTracker.respond({
status: 200,
Expand Down Expand Up @@ -731,7 +732,7 @@ export function declareGetHttpInterceptorTests({ platform }: SharedHttpIntercept
expect(initialListRequests).toHaveLength(0);

const listPromise = fetch(`${baseURL}/users`, { method: 'GET' });
await expect(listPromise).rejects.toThrowError();
await expectToThrowFetchError(listPromise);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import HttpSearchParams from '@/http/searchParams/HttpSearchParams';
import { createHttpInterceptorWorker } from '@/interceptor/http/interceptorWorker/factory';
import HttpInterceptorWorker from '@/interceptor/http/interceptorWorker/HttpInterceptorWorker';
import HttpRequestTracker from '@/interceptor/http/requestTracker/HttpRequestTracker';
import { expectToThrowFetchError } from '@tests/utils/fetch';
import { usingHttpInterceptor } from '@tests/utils/interceptors';

import { HttpInterceptorSchema } from '../../../types/schema';
Expand Down Expand Up @@ -399,7 +400,7 @@ export function declareHeadHttpInterceptorTests({ platform }: SharedHttpIntercep
expect(specificHeadRequest.response.body).toBe(null);

const unmatchedHeadPromise = fetch(`${baseURL}/users/${2}`, { method: 'HEAD' });
await expect(unmatchedHeadPromise).rejects.toThrowError();
await expectToThrowFetchError(unmatchedHeadPromise);
});
});

Expand All @@ -414,7 +415,7 @@ export function declareHeadHttpInterceptorTests({ platform }: SharedHttpIntercep
};
}>({ worker, baseURL }, async (interceptor) => {
let fetchPromise = fetch(`${baseURL}/users`, { method: 'HEAD' });
await expect(fetchPromise).rejects.toThrowError();
await expectToThrowFetchError(fetchPromise);

const headTrackerWithoutResponse = interceptor.head('/users');
expect(headTrackerWithoutResponse).toBeInstanceOf(HttpRequestTracker);
Expand All @@ -427,7 +428,7 @@ export function declareHeadHttpInterceptorTests({ platform }: SharedHttpIntercep
expectTypeOf<typeof headRequestWithoutResponse.response>().toEqualTypeOf<never>();

fetchPromise = fetch(`${baseURL}/users`, { method: 'HEAD' });
await expect(fetchPromise).rejects.toThrowError();
await expectToThrowFetchError(fetchPromise);

expect(headRequestsWithoutResponse).toHaveLength(0);

Expand Down Expand Up @@ -563,7 +564,7 @@ export function declareHeadHttpInterceptorTests({ platform }: SharedHttpIntercep
expect(initialHeadRequests).toHaveLength(0);

const headPromise = fetch(`${baseURL}/users`, { method: 'HEAD' });
await expect(headPromise).rejects.toThrowError();
await expectToThrowFetchError(headPromise);

const noContentHeadTracker = headTracker.respond({
status: 204,
Expand Down Expand Up @@ -661,7 +662,7 @@ export function declareHeadHttpInterceptorTests({ platform }: SharedHttpIntercep
expect(initialHeadRequests).toHaveLength(0);

const headPromise = fetch(`${baseURL}/users`, { method: 'HEAD' });
await expect(headPromise).rejects.toThrowError();
await expectToThrowFetchError(headPromise);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import HttpSearchParams from '@/http/searchParams/HttpSearchParams';
import { createHttpInterceptorWorker } from '@/interceptor/http/interceptorWorker/factory';
import HttpInterceptorWorker from '@/interceptor/http/interceptorWorker/HttpInterceptorWorker';
import HttpRequestTracker from '@/interceptor/http/requestTracker/HttpRequestTracker';
import { expectToThrowFetchError } from '@tests/utils/fetch';
import { usingHttpInterceptor } from '@tests/utils/interceptors';

import { HttpInterceptorSchema } from '../../../types/schema';
Expand Down Expand Up @@ -414,7 +415,7 @@ export function declareOptionsHttpInterceptorTests({ platform }: SharedHttpInter
expect(specificOptionsRequest.response.body).toBe(null);

const unmatchedOptionsPromise = fetch(`${baseURL}/filters/${2}`, { method: 'OPTIONS' });
await expect(unmatchedOptionsPromise).rejects.toThrowError();
await expectToThrowFetchError(unmatchedOptionsPromise);
});
});

Expand All @@ -429,7 +430,7 @@ export function declareOptionsHttpInterceptorTests({ platform }: SharedHttpInter
};
}>({ worker, baseURL }, async (interceptor) => {
let fetchPromise = fetch(`${baseURL}/filters`, { method: 'OPTIONS' });
await expect(fetchPromise).rejects.toThrowError();
await expectToThrowFetchError(fetchPromise);

const optionsTrackerWithoutResponse = interceptor.options('/filters');
expect(optionsTrackerWithoutResponse).toBeInstanceOf(HttpRequestTracker);
Expand All @@ -442,7 +443,7 @@ export function declareOptionsHttpInterceptorTests({ platform }: SharedHttpInter
expectTypeOf<typeof optionsRequestWithoutResponse.response>().toEqualTypeOf<never>();

fetchPromise = fetch(`${baseURL}/filters`, { method: 'OPTIONS' });
await expect(fetchPromise).rejects.toThrowError();
await expectToThrowFetchError(fetchPromise);

expect(optionsRequestsWithoutResponse).toHaveLength(0);

Expand Down Expand Up @@ -578,7 +579,7 @@ export function declareOptionsHttpInterceptorTests({ platform }: SharedHttpInter
expect(initialOptionsRequests).toHaveLength(0);

const optionsPromise = fetch(`${baseURL}/filters`, { method: 'OPTIONS' });
await expect(optionsPromise).rejects.toThrowError();
await expectToThrowFetchError(optionsPromise);

const noContentOptionsTracker = optionsTracker.respond({
status: 204,
Expand Down Expand Up @@ -676,7 +677,7 @@ export function declareOptionsHttpInterceptorTests({ platform }: SharedHttpInter
expect(initialOptionsRequests).toHaveLength(0);

const optionsPromise = fetch(`${baseURL}/filters`, { method: 'OPTIONS' });
await expect(optionsPromise).rejects.toThrowError();
await expectToThrowFetchError(optionsPromise);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import HttpSearchParams from '@/http/searchParams/HttpSearchParams';
import { createHttpInterceptorWorker } from '@/interceptor/http/interceptorWorker/factory';
import HttpInterceptorWorker from '@/interceptor/http/interceptorWorker/HttpInterceptorWorker';
import HttpRequestTracker from '@/interceptor/http/requestTracker/HttpRequestTracker';
import { expectToThrowFetchError } from '@tests/utils/fetch';
import { usingHttpInterceptor } from '@tests/utils/interceptors';

import { HttpInterceptorSchema } from '../../../types/schema';
Expand Down Expand Up @@ -435,7 +436,7 @@ export function declarePatchHttpInterceptorTests({ platform }: SharedHttpInterce
expect(specificUpdateRequest.response.body).toEqual(users[0]);

const unmatchedUpdatePromise = fetch(`${baseURL}/users/${2}`, { method: 'PATCH' });
await expect(unmatchedUpdatePromise).rejects.toThrowError();
await expectToThrowFetchError(unmatchedUpdatePromise);
});
});

Expand All @@ -456,7 +457,7 @@ export function declarePatchHttpInterceptorTests({ platform }: SharedHttpInterce
method: 'PATCH',
body: JSON.stringify({ name: userName } satisfies User),
});
await expect(updatePromise).rejects.toThrowError();
await expectToThrowFetchError(updatePromise);

const updateTrackerWithoutResponse = interceptor.patch('/users');
expect(updateTrackerWithoutResponse).toBeInstanceOf(HttpRequestTracker);
Expand All @@ -472,7 +473,7 @@ export function declarePatchHttpInterceptorTests({ platform }: SharedHttpInterce
method: 'PATCH',
body: JSON.stringify({ name: userName } satisfies User),
});
await expect(updatePromise).rejects.toThrowError();
await expectToThrowFetchError(updatePromise);

expect(updateRequestsWithoutResponse).toHaveLength(0);

Expand Down Expand Up @@ -618,7 +619,7 @@ export function declarePatchHttpInterceptorTests({ platform }: SharedHttpInterce
expect(initialUpdateRequests).toHaveLength(0);

const updatePromise = fetch(`${baseURL}/users`, { method: 'PATCH' });
await expect(updatePromise).rejects.toThrowError();
await expectToThrowFetchError(updatePromise);

updateTracker.respond({
status: 200,
Expand Down Expand Up @@ -723,7 +724,7 @@ export function declarePatchHttpInterceptorTests({ platform }: SharedHttpInterce
expect(initialUpdateRequests).toHaveLength(0);

const updatePromise = fetch(`${baseURL}/users`, { method: 'PATCH' });
await expect(updatePromise).rejects.toThrowError();
await expectToThrowFetchError(updatePromise);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import HttpSearchParams from '@/http/searchParams/HttpSearchParams';
import { createHttpInterceptorWorker } from '@/interceptor/http/interceptorWorker/factory';
import HttpInterceptorWorker from '@/interceptor/http/interceptorWorker/HttpInterceptorWorker';
import HttpRequestTracker from '@/interceptor/http/requestTracker/HttpRequestTracker';
import { expectToThrowFetchError } from '@tests/utils/fetch';
import { usingHttpInterceptor } from '@tests/utils/interceptors';

import { HttpInterceptorSchema } from '../../../types/schema';
Expand Down Expand Up @@ -441,7 +442,7 @@ export function declarePostHttpInterceptorTests({ platform }: SharedHttpIntercep
expect(specificCreationRequest.response.body).toEqual(users[0]);

const unmatchedCreationPromise = fetch(`${baseURL}/users/${2}`, { method: 'POST' });
await expect(unmatchedCreationPromise).rejects.toThrowError();
await expectToThrowFetchError(unmatchedCreationPromise);
});
});

Expand All @@ -462,7 +463,7 @@ export function declarePostHttpInterceptorTests({ platform }: SharedHttpIntercep
method: 'POST',
body: JSON.stringify({ name: userName } satisfies User),
});
await expect(creationPromise).rejects.toThrowError();
await expectToThrowFetchError(creationPromise);

const creationTrackerWithoutResponse = interceptor.post('/users');
expect(creationTrackerWithoutResponse).toBeInstanceOf(HttpRequestTracker);
Expand All @@ -478,7 +479,7 @@ export function declarePostHttpInterceptorTests({ platform }: SharedHttpIntercep
method: 'POST',
body: JSON.stringify({ name: userName } satisfies User),
});
await expect(creationPromise).rejects.toThrowError();
await expectToThrowFetchError(creationPromise);

expect(creationRequestsWithoutResponse).toHaveLength(0);

Expand Down Expand Up @@ -629,7 +630,7 @@ export function declarePostHttpInterceptorTests({ platform }: SharedHttpIntercep
expect(initialCreationRequests).toHaveLength(0);

const creationPromise = fetch(`${baseURL}/users`, { method: 'POST' });
await expect(creationPromise).rejects.toThrowError();
await expectToThrowFetchError(creationPromise);

creationTracker.respond({
status: 201,
Expand Down Expand Up @@ -734,7 +735,7 @@ export function declarePostHttpInterceptorTests({ platform }: SharedHttpIntercep
expect(initialCreationRequests).toHaveLength(0);

const creationPromise = fetch(`${baseURL}/users`, { method: 'POST' });
await expect(creationPromise).rejects.toThrowError();
await expectToThrowFetchError(creationPromise);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import HttpSearchParams from '@/http/searchParams/HttpSearchParams';
import { createHttpInterceptorWorker } from '@/interceptor/http/interceptorWorker/factory';
import HttpInterceptorWorker from '@/interceptor/http/interceptorWorker/HttpInterceptorWorker';
import HttpRequestTracker from '@/interceptor/http/requestTracker/HttpRequestTracker';
import { expectToThrowFetchError } from '@tests/utils/fetch';
import { usingHttpInterceptor } from '@tests/utils/interceptors';

import { HttpInterceptorSchema } from '../../../types/schema';
Expand Down Expand Up @@ -435,7 +436,7 @@ export function declarePutHttpInterceptorTests({ platform }: SharedHttpIntercept
expect(specificUpdateRequest.response.body).toEqual(users[0]);

const unmatchedUpdatePromise = fetch(`${baseURL}/users/${2}`, { method: 'PUT' });
await expect(unmatchedUpdatePromise).rejects.toThrowError();
await expectToThrowFetchError(unmatchedUpdatePromise);
});
});

Expand All @@ -456,7 +457,7 @@ export function declarePutHttpInterceptorTests({ platform }: SharedHttpIntercept
method: 'PUT',
body: JSON.stringify({ name: userName } satisfies User),
});
await expect(updatePromise).rejects.toThrowError();
await expectToThrowFetchError(updatePromise);

const updateTrackerWithoutResponse = interceptor.put('/users');
expect(updateTrackerWithoutResponse).toBeInstanceOf(HttpRequestTracker);
Expand All @@ -472,7 +473,7 @@ export function declarePutHttpInterceptorTests({ platform }: SharedHttpIntercept
method: 'PUT',
body: JSON.stringify({ name: userName } satisfies User),
});
await expect(updatePromise).rejects.toThrowError();
await expectToThrowFetchError(updatePromise);

expect(updateRequestsWithoutResponse).toHaveLength(0);

Expand Down Expand Up @@ -618,7 +619,7 @@ export function declarePutHttpInterceptorTests({ platform }: SharedHttpIntercept
expect(initialUpdateRequests).toHaveLength(0);

const updatePromise = fetch(`${baseURL}/users`, { method: 'PUT' });
await expect(updatePromise).rejects.toThrowError();
await expectToThrowFetchError(updatePromise);

updateTracker.respond({
status: 200,
Expand Down Expand Up @@ -723,7 +724,7 @@ export function declarePutHttpInterceptorTests({ platform }: SharedHttpIntercept
expect(initialUpdateRequests).toHaveLength(0);

const updatePromise = fetch(`${baseURL}/users`, { method: 'PUT' });
await expect(updatePromise).rejects.toThrowError();
await expectToThrowFetchError(updatePromise);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,9 @@ class HttpInterceptorWorker implements PublicHttpInterceptorWorker {
}

static async parseRawRequest<MethodSchema extends HttpInterceptorMethodSchema>(
rawRequest: HttpRequest,
originalRawRequest: HttpRequest,
): Promise<HttpInterceptorRequest<MethodSchema>> {
const rawRequest = originalRawRequest.clone();
const rawRequestClone = rawRequest.clone();

type BodySchema = Default<Default<MethodSchema['request']>['body']>;
Expand Down Expand Up @@ -289,7 +290,8 @@ class HttpInterceptorWorker implements PublicHttpInterceptorWorker {
static async parseRawResponse<
MethodSchema extends HttpInterceptorMethodSchema,
StatusCode extends HttpInterceptorResponseSchemaStatusCode<Default<MethodSchema['response']>>,
>(rawResponse: HttpResponse): Promise<HttpInterceptorResponse<MethodSchema, StatusCode>> {
>(originalRawResponse: HttpResponse): Promise<HttpInterceptorResponse<MethodSchema, StatusCode>> {
const rawResponse = originalRawResponse.clone();
const rawResponseClone = rawResponse.clone();

type BodySchema = Default<Default<MethodSchema['response']>[StatusCode]['body']>;
Expand Down
Loading

0 comments on commit 779fb6f

Please sign in to comment.