Skip to content

Commit

Permalink
test: add apierror tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackfaded committed Aug 12, 2024
1 parent afb7250 commit b95f8fc
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/errors/ApiErrorResponseException.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { describe, test, expect } from 'vitest';
import { ApiErrorResponseException } from './ApiErrorResponseException.js';
import type { APIError } from '../models/APIError.js';

describe('ApiErrorResponseException', () => {
test('constructor', () => {
const apiException = new ApiErrorResponseException(404, 'Body');
expect(apiException).toBeDefined();
});

test('constructor with Errors', () => {
const apiError: APIError = {
errorCode: 'errorCode',
};
const apiException = new ApiErrorResponseException(404, 'Body', [apiError]);
expect(apiException.getErrors()).toContain(apiError);
});
});
20 changes: 20 additions & 0 deletions src/errors/ApiException.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, test, expect } from 'vitest';
import { ApiException } from './ApiException.js';

describe('ApiException', () => {
test('constructor', () => {
const apiException = new ApiException(404, 'Body');
expect(apiException).toBeDefined();
});

test('constructor with cause', () => {
const apiException = new ApiException(404, 'Body', new Error('Cause'));
expect(apiException.stack).toContain('Error: Cause');
});

test('getters', () => {
const apiException = new ApiException(404, 'Body');
expect(apiException.getResponseBody()).toEqual('Body');
expect(apiException.getStatusCode()).toEqual(404);
});
});
14 changes: 14 additions & 0 deletions src/errors/ApiResponseRetrievalException.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, expect, test } from 'vitest';
import { ApiResponseRetrievalException } from './ApiResponseRetrievalException.js';

describe('ApiResponseRetrievalException', () => {
test('constructor', () => {
const apiException = new ApiResponseRetrievalException(404, 'Body');
expect(apiException).toBeDefined();
});

test('constructor with cause', () => {
const apiException = new ApiResponseRetrievalException(404, 'Body', new Error('Cause'));
expect(apiException.stack).toContain('Error: Cause');
});
});

0 comments on commit b95f8fc

Please sign in to comment.