From b95f8fcb5b8dab78fbbdaa1fad1ebe853bdb887e Mon Sep 17 00:00:00 2001 From: Blackfaded Date: Mon, 12 Aug 2024 11:47:07 +0200 Subject: [PATCH] test: add apierror tests --- src/errors/ApiErrorResponseException.test.ts | 18 +++++++++++++++++ src/errors/ApiException.test.ts | 20 +++++++++++++++++++ .../ApiResponseRetrievalException.test.ts | 14 +++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 src/errors/ApiErrorResponseException.test.ts create mode 100644 src/errors/ApiException.test.ts create mode 100644 src/errors/ApiResponseRetrievalException.test.ts diff --git a/src/errors/ApiErrorResponseException.test.ts b/src/errors/ApiErrorResponseException.test.ts new file mode 100644 index 0000000..af4c3af --- /dev/null +++ b/src/errors/ApiErrorResponseException.test.ts @@ -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); + }); +}); diff --git a/src/errors/ApiException.test.ts b/src/errors/ApiException.test.ts new file mode 100644 index 0000000..058337e --- /dev/null +++ b/src/errors/ApiException.test.ts @@ -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); + }); +}); diff --git a/src/errors/ApiResponseRetrievalException.test.ts b/src/errors/ApiResponseRetrievalException.test.ts new file mode 100644 index 0000000..9d3e87a --- /dev/null +++ b/src/errors/ApiResponseRetrievalException.test.ts @@ -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'); + }); +});