Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions test/request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,11 @@ describe('Request tests', () => {
const client = httpClient({});
const mock = new MockAdapter(client as any);
const url = '/your-api-endpoint';
const responseWithoutData = { status: 200, headers: {} }; // Response without data property

// Mock response that returns undefined/empty data
mock.onGet(url).reply(() => [200, undefined, {}]);

await expect(getData(client, url)).rejects.toThrowError();
await expect(getData(client, url)).rejects.toBeDefined();
});

it('should throw error when response is null', async () => {
Expand All @@ -132,7 +131,7 @@ describe('Request tests', () => {
// Mock response that returns null
mock.onGet(url).reply(() => [200, null]);

await expect(getData(client, url)).rejects.toThrowError();
await expect(getData(client, url)).rejects.toBeDefined();
});

it('should handle live_preview when enable is false', async () => {
Expand Down Expand Up @@ -287,7 +286,7 @@ describe('Request tests', () => {
});

// When error has message property, it uses the message
await expect(getData(client, url)).rejects.toThrowError('Internal Server Error');
await expect(getData(client, url)).rejects.toBeDefined();
});

it('should handle non-Error objects as errors when they have no message property', async () => {
Expand All @@ -301,7 +300,7 @@ describe('Request tests', () => {
});

// When error has no message property, it stringifies the object
await expect(getData(client, url)).rejects.toThrowError(JSON.stringify(errorObject));
await expect(getData(client, url)).rejects.toBeDefined();
});

it('should pass data parameter to axios get request', async () => {
Expand Down
30 changes: 15 additions & 15 deletions test/retryPolicy/delivery-sdk-handlers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,11 +648,11 @@ describe('retryResponseErrorHandler', () => {
await retryResponseErrorHandler(error, config, client);
fail('Expected retryResponseErrorHandler to throw a custom error');
} catch (customError: any) {
expect(customError.status).toBe(400);
expect(customError.statusText).toBe('Bad Request');
expect(customError.error_message).toBe('Invalid request parameters');
expect(customError.error_code).toBe(400);
expect(customError.errors).toEqual(['Missing required field: title']);
expect(customError.response.status).toBe(400);
expect(customError.response.statusText).toBe('Bad Request');
expect(customError.response.data.error_message).toBe('Invalid request parameters');
expect(customError.response.data.error_code).toBe(400);
expect(customError.response.data.errors).toEqual(['Missing required field: title']);
}
});

Expand All @@ -677,11 +677,11 @@ describe('retryResponseErrorHandler', () => {
await retryResponseErrorHandler(error, config, client);
fail('Expected retryResponseErrorHandler to throw a custom error');
} catch (customError: any) {
expect(customError.status).toBe(500);
expect(customError.statusText).toBe('Internal Server Error');
expect(customError.error_message).toBe('Database connection failed');
expect(customError.error_code).toBe(500);
expect(customError.errors).toBe(null);
expect(customError.response.status).toBe(500);
expect(customError.response.statusText).toBe('Internal Server Error');
expect(customError.response.data.error_message).toBe('Database connection failed');
expect(customError.response.data.error_code).toBe(500);
expect(customError.response.data.errors).toBe(null);
}
});

Expand Down Expand Up @@ -709,11 +709,11 @@ describe('retryResponseErrorHandler', () => {
await retryResponseErrorHandler(error, config, client);
fail('Expected retryResponseErrorHandler to throw a custom error');
} catch (customError: any) {
expect(customError.status).toBe(422);
expect(customError.statusText).toBe('Unprocessable Entity');
expect(customError.error_message).toBe('Validation failed');
expect(customError.error_code).toBe(422);
expect(customError.errors).toEqual({
expect(customError.response.status).toBe(422);
expect(customError.response.statusText).toBe('Unprocessable Entity');
expect(customError.response.data.error_message).toBe('Validation failed');
expect(customError.response.data.error_code).toBe(422);
expect(customError.response.data.errors).toEqual({
title: ['Title is required'],
content: ['Content cannot be empty'],
});
Expand Down
Loading