Setup Jest (#57)
All checks were successful
continuous-integration/drone/push Build is passing

- Setup Jest
- Add test scripts
- Configure Drone

Fixes #1

Co-authored-by: Ethan Lane <ethan@vylpes.com>
Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/random-bunny/pulls/57
This commit is contained in:
Vylpes 2023-04-22 13:20:30 +01:00
parent 2ab2fe04fd
commit 06485e0a88
11 changed files with 2510 additions and 115 deletions

View file

@ -1,6 +1,6 @@
import IReturnResult from "./contracts/IReturnResult.js";
import IRedditResult from "./contracts/IRedditResult.js";
import fetch from "got";
import fetch from "got-cjs";
import { List } from 'linqts';
import IFetchResult from "./contracts/IFetchResult.js";
@ -35,15 +35,17 @@ export default async function randomBunny(subreddit: string, sortBy?: string): P
.Where(x => x!.data.url.includes('.jpg') || x!.data.url.includes('.png'))
.ToArray();
const random = Math.floor((Math.random() * dataWithImages.length - 1) + 0); // Between 0 and (size - 1)
let random = 0;
const randomSelect = dataWithImages[random];
if (!randomSelect) {
if (dataWithImages.length == 0) {
return {
IsSuccess: false,
};
};
} else if (dataWithImages.length > 1) {
random = Math.floor((Math.random() * dataWithImages.length - 1) + 0); // Between 0 and (size - 1)
}
const randomSelect = dataWithImages[random];
const randomData = randomSelect.data;