Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
inkognitro committed Oct 7, 2024
1 parent cba70b5 commit 302ce34
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 74 deletions.
48 changes: 14 additions & 34 deletions src/templates/core/axiosRequestHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ afterAll(async () => {
describe('AxiosRequestHandler', () => {
it('can receive plain text data', async () => {
const rr = await requestHandler.execute(
createRequest({
endpointSchema: createEndpointSchema(getPlainTextEndpointSchema),
})
createRequest(createEndpointSchema(getPlainTextEndpointSchema))
);
expect(rr.response?.status).toBe(200);
expect(rr.response.contentType).toContain(
Expand All @@ -75,10 +73,9 @@ describe('AxiosRequestHandler', () => {

it('can send and receive plain text data', async () => {
const rr = await requestHandler.execute(
createRequest({
createRequest(createEndpointSchema(postPlainTextEndpointSchema), {
contentType: 'text/plain',
body: 'ping',
endpointSchema: createEndpointSchema(postPlainTextEndpointSchema),
})
);
expect(rr.response?.status).toBe(200);
Expand All @@ -91,9 +88,7 @@ describe('AxiosRequestHandler', () => {

it('can receive json data', async () => {
const rr = await requestHandler.execute(
createRequest({
endpointSchema: createEndpointSchema(getJsonEndpointSchema),
})
createRequest(createEndpointSchema(getJsonEndpointSchema))
);
expect(rr.response?.status).toBe(200);
expect(rr.response.contentType).toContain(
Expand All @@ -105,10 +100,9 @@ describe('AxiosRequestHandler', () => {

it('can send and receive json data', async () => {
const rr = await requestHandler.execute(
createRequest({
createRequest(createEndpointSchema(postJsonEndpointSchema), {
contentType: 'application/json',
body: {foo: 'bar'},
endpointSchema: createEndpointSchema(postJsonEndpointSchema),
})
);
expect(rr.response?.status).toBe(200);
Expand All @@ -121,11 +115,7 @@ describe('AxiosRequestHandler', () => {

it('can receive urlencoded form data', async () => {
const rr = await requestHandler.execute(
createRequest({
endpointSchema: createEndpointSchema(
getFormUrlEncodedDataEndpointSchema
),
})
createRequest(createEndpointSchema(getFormUrlEncodedDataEndpointSchema))
);
expect(rr.response?.status).toBe(200);
expect(rr.response.contentType).toContain(
Expand All @@ -137,13 +127,10 @@ describe('AxiosRequestHandler', () => {

it('can send and receive urlencoded form data', async () => {
const rr = await requestHandler.execute(
createRequest({
contentType: 'application/x-www-form-urlencoded',
body: {foo: 'bar'},
endpointSchema: createEndpointSchema(
postFormUrlEncodedDataEndpointSchema
),
})
createRequest(
createEndpointSchema(postFormUrlEncodedDataEndpointSchema),
{contentType: 'application/x-www-form-urlencoded', body: {foo: 'bar'}}
)
);
expect(rr.response?.status).toBe(200);
expect(rr.response.contentType).toContain(
Expand All @@ -155,9 +142,7 @@ describe('AxiosRequestHandler', () => {

it('can receive multipart form data', async () => {
const rr = await requestHandler.execute(
createRequest({
endpointSchema: createEndpointSchema(getFormDataEndpointSchema),
})
createRequest(createEndpointSchema(getFormDataEndpointSchema))
);
expect(rr.response?.status).toBe(200);
expect(rr.response.contentType).toContain(
Expand All @@ -171,10 +156,9 @@ describe('AxiosRequestHandler', () => {
const formData = new FormData();
formData.append('foo', 'bar');
const rr = await requestHandler.execute(
createRequest({
createRequest(createEndpointSchema(postFormDataEndpointSchema), {
contentType: 'multipart/form-data',
body: formData,
endpointSchema: createEndpointSchema(postFormDataEndpointSchema),
})
);
expect(rr.response?.status).toBe(200);
Expand All @@ -187,12 +171,11 @@ describe('AxiosRequestHandler', () => {

it('can send from object converted form data', async () => {
const rr = await requestHandler.execute(
createRequest({
createRequest(createEndpointSchema(postFormDataEndpointSchema), {
contentType: 'multipart/form-data',
body: {
foo: 'bar',
},
endpointSchema: createEndpointSchema(postFormDataEndpointSchema),
})
);
expect(rr.response?.status).toBe(200);
Expand All @@ -205,9 +188,7 @@ describe('AxiosRequestHandler', () => {

it('can receive blob data', async () => {
const rr = await requestHandler.execute(
createRequest({
endpointSchema: createEndpointSchema(getBlobEndpointSchema),
})
createRequest(createEndpointSchema(getBlobEndpointSchema))
);
expect(rr.response?.status).toBe(200);
expect(rr.response.contentType).toContain(
Expand All @@ -219,10 +200,9 @@ describe('AxiosRequestHandler', () => {

it('can send and receive blob data', async () => {
const rr = await requestHandler.execute(
createRequest({
createRequest(createEndpointSchema(postBlobEndpointSchema), {
contentType: 'application/pdf',
body: mockPdfBlob,
endpointSchema: createEndpointSchema(postBlobEndpointSchema),
})
);
expect(rr.response?.status).toBe(200);
Expand Down
51 changes: 17 additions & 34 deletions src/templates/core/fetchApiRequestHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ afterAll(async () => {
describe('FetchApiRequestHandler', () => {
it('can receive plain text data', async () => {
const rr = await requestHandler.execute(
createRequest({
endpointSchema: createEndpointSchema(getPlainTextEndpointSchema),
})
createRequest(createEndpointSchema(getPlainTextEndpointSchema))
);
expect(rr.response?.status).toBe(200);
expect(rr.response.contentType).toContain(
Expand All @@ -73,10 +71,9 @@ describe('FetchApiRequestHandler', () => {

it('can send and receive plain text data', async () => {
const rr = await requestHandler.execute(
createRequest({
createRequest(createEndpointSchema(postPlainTextEndpointSchema), {
contentType: 'text/plain',
body: 'ping',
endpointSchema: createEndpointSchema(postPlainTextEndpointSchema),
})
);
expect(rr.response?.status).toBe(200);
Expand All @@ -89,9 +86,7 @@ describe('FetchApiRequestHandler', () => {

it('can receive json data', async () => {
const rr = await requestHandler.execute(
createRequest({
endpointSchema: createEndpointSchema(getJsonEndpointSchema),
})
createRequest(createEndpointSchema(getJsonEndpointSchema))
);
expect(rr.response?.status).toBe(200);
expect(rr.response.contentType).toContain(
Expand All @@ -103,10 +98,9 @@ describe('FetchApiRequestHandler', () => {

it('can send and receive json data', async () => {
const rr = await requestHandler.execute(
createRequest({
createRequest(createEndpointSchema(postJsonEndpointSchema), {
contentType: 'application/json',
body: {foo: 'bar'},
endpointSchema: createEndpointSchema(postJsonEndpointSchema),
})
);
expect(rr.response?.status).toBe(200);
Expand All @@ -119,11 +113,7 @@ describe('FetchApiRequestHandler', () => {

it('can receive urlencoded form data', async () => {
const rr = await requestHandler.execute(
createRequest({
endpointSchema: createEndpointSchema(
getFormUrlEncodedDataEndpointSchema
),
})
createRequest(createEndpointSchema(getFormUrlEncodedDataEndpointSchema))
);
expect(rr.response?.status).toBe(200);
expect(rr.response.contentType).toContain(
Expand All @@ -135,13 +125,13 @@ describe('FetchApiRequestHandler', () => {

it('can send and receive urlencoded form data', async () => {
const rr = await requestHandler.execute(
createRequest({
contentType: 'application/x-www-form-urlencoded',
body: {foo: 'bar'},
endpointSchema: createEndpointSchema(
postFormUrlEncodedDataEndpointSchema
),
})
createRequest(
createEndpointSchema(postFormUrlEncodedDataEndpointSchema),
{
contentType: 'application/x-www-form-urlencoded',
body: {foo: 'bar'},
}
)
);
expect(rr.response?.status).toBe(200);
expect(rr.response.contentType).toContain(
Expand All @@ -153,9 +143,7 @@ describe('FetchApiRequestHandler', () => {

it('can receive multipart form data', async () => {
const rr = await requestHandler.execute(
createRequest({
endpointSchema: createEndpointSchema(getFormDataEndpointSchema),
})
createRequest(createEndpointSchema(getFormDataEndpointSchema))
);
expect(rr.response?.status).toBe(200);
expect(rr.response.contentType).toContain(
Expand All @@ -169,10 +157,9 @@ describe('FetchApiRequestHandler', () => {
const formData = new FormData();
formData.append('foo', 'bar');
const rr = await requestHandler.execute(
createRequest({
createRequest(createEndpointSchema(postFormDataEndpointSchema), {
contentType: 'multipart/form-data',
body: formData,
endpointSchema: createEndpointSchema(postFormDataEndpointSchema),
})
);
expect(rr.response?.status).toBe(200);
Expand All @@ -185,12 +172,11 @@ describe('FetchApiRequestHandler', () => {

it('can send from object converted form data', async () => {
const rr = await requestHandler.execute(
createRequest({
createRequest(createEndpointSchema(postFormDataEndpointSchema), {
contentType: 'multipart/form-data',
body: {
foo: 'bar',
},
endpointSchema: createEndpointSchema(postFormDataEndpointSchema),
})
);
expect(rr.response?.status).toBe(200);
Expand All @@ -203,9 +189,7 @@ describe('FetchApiRequestHandler', () => {

it('can receive blob data', async () => {
const rr = await requestHandler.execute(
createRequest({
endpointSchema: createEndpointSchema(getBlobEndpointSchema),
})
createRequest(createEndpointSchema(getBlobEndpointSchema))
);
expect(rr.response?.status).toBe(200);
expect(rr.response.contentType).toContain(
Expand All @@ -217,10 +201,9 @@ describe('FetchApiRequestHandler', () => {

it('can send and receive blob data', async () => {
const rr = await requestHandler.execute(
createRequest({
createRequest(createEndpointSchema(postBlobEndpointSchema), {
contentType: 'application/pdf',
body: mockPdfBlob,
endpointSchema: createEndpointSchema(postBlobEndpointSchema),
})
);
expect(rr.response?.status).toBe(200);
Expand Down
12 changes: 6 additions & 6 deletions src/templates/core/scopedRequestHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ describe('ScopedRequestHandler', () => {
const mockRequestHandler = new MockRequestHandler();
const scopedRequestHandler1 = new ScopedRequestHandler(mockRequestHandler);
const scopedRequestHandler2 = new ScopedRequestHandler(mockRequestHandler);
const request1_1 = createRequest({endpointSchema});
const request1_2 = createRequest({endpointSchema});
const request2_1 = createRequest({endpointSchema});
const request1_1 = createRequest(endpointSchema);
const request1_2 = createRequest(endpointSchema);
const request2_1 = createRequest(endpointSchema);
scopedRequestHandler1.execute(request1_1);
scopedRequestHandler1.execute(request1_2);
scopedRequestHandler2.execute(request2_1);
Expand All @@ -53,9 +53,9 @@ describe('ScopedRequestHandler', () => {
const mockRequestHandler = new MockRequestHandler();
const scopedRequestHandler1 = new ScopedRequestHandler(mockRequestHandler);
const scopedRequestHandler2 = new ScopedRequestHandler(mockRequestHandler);
const request1_1 = createRequest({endpointSchema});
const request1_2 = createRequest({endpointSchema});
const request2_1 = createRequest({endpointSchema});
const request1_1 = createRequest(endpointSchema);
const request1_2 = createRequest(endpointSchema);
const request2_1 = createRequest(endpointSchema);
scopedRequestHandler1.execute(request1_1);
scopedRequestHandler1.execute(request1_2);
scopedRequestHandler2.execute(request2_1);
Expand Down

0 comments on commit 302ce34

Please sign in to comment.