From 8b4efab7ceef17042aee4d59f326a7cfb585d700 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Wed, 13 Sep 2023 11:09:38 +0100 Subject: [PATCH] Update tests --- src/index.ts | 12 ++++++------ tests/index.test.ts | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 344ab7c..4ff8e67 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,10 @@ -import IReturnResult from "./contracts/IReturnResult.js"; -import IRedditResult from "./contracts/IRedditResult.js"; +import IReturnResult from "./contracts/IReturnResult"; +import IRedditResult from "./contracts/IRedditResult"; import fetch from "got-cjs"; import { List } from 'linqts'; -import IFetchResult from "./contracts/IFetchResult.js"; -import { ErrorCode } from "./constants/ErrorCode.js"; -import ErrorMessages from "./constants/ErrorMessages.js"; +import IFetchResult from "./contracts/IFetchResult"; +import { ErrorCode } from "./constants/ErrorCode"; +import ErrorMessages from "./constants/ErrorMessages"; const sortable = [ 'new', @@ -34,7 +34,7 @@ export default async function randomBunny(subreddit: string, sortBy?: string): P IsSuccess: false, Error: { Code: ErrorCode.UnableToParseJSON, - Message: ErrorMessages.FailedToFetchReddit, + Message: ErrorMessages.UnableToParseJSON, }, } } diff --git a/tests/index.test.ts b/tests/index.test.ts index 6eafc35..107e7ff 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,3 +1,5 @@ +import { ErrorCode } from "../src/constants/ErrorCode"; +import ErrorMessages from "../src/constants/ErrorMessages"; import randomBunny from "../src/index"; import fetch from "got-cjs"; @@ -32,6 +34,7 @@ describe('randomBunny', () => { expect(result.IsSuccess).toBeTruthy(); expect(result.Result).toBeDefined(); + expect(result.Error).toBeUndefined(); expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json'); }); @@ -63,6 +66,7 @@ describe('randomBunny', () => { expect(result.IsSuccess).toBeTruthy(); expect(result.Result).toBeDefined(); + expect(result.Error).toBeUndefined(); expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/hot.json'); }); @@ -94,6 +98,7 @@ describe('randomBunny', () => { expect(result.IsSuccess).toBeTruthy(); expect(result.Result).toBeDefined(); + expect(result.Error).toBeUndefined(); expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/hot.json'); }); @@ -105,6 +110,10 @@ describe('randomBunny', () => { expect(result.IsSuccess).toBeFalsy(); expect(result.Result).toBeUndefined(); + expect(result.Error).toBeDefined(); + + expect(result.Error!.Code).toBe(ErrorCode.FailedToFetchReddit); + expect(result.Error!.Message).toBe(ErrorMessages.FailedToFetchReddit); expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json'); }); @@ -118,6 +127,10 @@ describe('randomBunny', () => { expect(result.IsSuccess).toBeFalsy(); expect(result.Result).toBeUndefined(); + expect(result.Error).toBeDefined(); + + expect(result.Error!.Code).toBe(ErrorCode.UnableToParseJSON); + expect(result.Error!.Message).toBe(ErrorMessages.UnableToParseJSON); expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json'); }); @@ -135,6 +148,10 @@ describe('randomBunny', () => { expect(result.IsSuccess).toBeFalsy(); expect(result.Result).toBeUndefined(); + expect(result.Error).toBeDefined(); + + expect(result.Error!.Code).toBe(ErrorCode.NoImageResultsFound); + expect(result.Error!.Message).toBe(ErrorMessages.NoImageResultsFound); expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json'); }); @@ -166,6 +183,10 @@ describe('randomBunny', () => { expect(result.IsSuccess).toBeFalsy(); expect(result.Result).toBeUndefined(); + expect(result.Error).toBeDefined(); + + expect(result.Error!.Code).toBe(ErrorCode.NoImageResultsFound); + expect(result.Error!.Message).toBe(ErrorMessages.NoImageResultsFound); expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json'); });