Compare commits
No commits in common. "2885d6365bfc8ae2011f6aefafcbbf30928d6f3c" and "87d4335bbc4023f8566233065a19b91d7265d846" have entirely different histories.
2885d6365b
...
87d4335bbc
19 changed files with 325 additions and 4272 deletions
52
.drone.yml
52
.drone.yml
|
@ -1,47 +1,3 @@
|
||||||
---
|
|
||||||
|
|
||||||
kind: pipeline
|
|
||||||
name: deployment
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: build
|
|
||||||
image: node
|
|
||||||
commands:
|
|
||||||
- yarn install --frozen-lockfile
|
|
||||||
- yarn build
|
|
||||||
- name: test
|
|
||||||
image: node
|
|
||||||
commands:
|
|
||||||
- yarn test
|
|
||||||
depends_on:
|
|
||||||
- build
|
|
||||||
- name: lint
|
|
||||||
image: node
|
|
||||||
commands:
|
|
||||||
- yarn lint
|
|
||||||
depends_on:
|
|
||||||
- build
|
|
||||||
- name: deploy
|
|
||||||
image: plugins/npm
|
|
||||||
settings:
|
|
||||||
username: vylpes
|
|
||||||
password:
|
|
||||||
from_secret: npm_password
|
|
||||||
email: ethan@vylpes.com
|
|
||||||
token:
|
|
||||||
from_secret: npm_token
|
|
||||||
depends_on:
|
|
||||||
- test
|
|
||||||
- lint
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
branch:
|
|
||||||
- master
|
|
||||||
event:
|
|
||||||
- tag
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
name: integration
|
name: integration
|
||||||
|
|
||||||
|
@ -50,25 +6,17 @@ steps:
|
||||||
image: node
|
image: node
|
||||||
commands:
|
commands:
|
||||||
- yarn install --frozen-lockfile
|
- yarn install --frozen-lockfile
|
||||||
- yarn build
|
|
||||||
- name: test
|
- name: test
|
||||||
image: node
|
image: node
|
||||||
commands:
|
commands:
|
||||||
- yarn test
|
- yarn test
|
||||||
depends_on:
|
depends_on:
|
||||||
- build
|
- build
|
||||||
- name: lint
|
|
||||||
image: node
|
|
||||||
commands:
|
|
||||||
- yarn lint
|
|
||||||
depends_on:
|
|
||||||
- build
|
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
branch:
|
branch:
|
||||||
- develop
|
- develop
|
||||||
- feature/*
|
- feature/*
|
||||||
- hotfix/*
|
- hotfix/*
|
||||||
- renovate/*
|
|
||||||
event:
|
event:
|
||||||
- push
|
- push
|
|
@ -1 +0,0 @@
|
||||||
dist/
|
|
|
@ -44,7 +44,6 @@
|
||||||
"module": "writable",
|
"module": "writable",
|
||||||
"require": "writable",
|
"require": "writable",
|
||||||
"process": "writable",
|
"process": "writable",
|
||||||
"console": "writable",
|
"console": "writable"
|
||||||
"jest": "writable"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
Epic: \
|
|
||||||
Story Points:
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
*No description*
|
|
||||||
|
|
||||||
## Acceptance Criteria
|
|
||||||
|
|
||||||
*No acceptance criteria*
|
|
||||||
|
|
||||||
## Subtasks
|
|
||||||
|
|
||||||
*No subtasks*
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
*No notes*
|
|
|
@ -1,29 +0,0 @@
|
||||||
# Description
|
|
||||||
|
|
||||||
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
|
|
||||||
|
|
||||||
Fixes # (issue)
|
|
||||||
|
|
||||||
## Type of change
|
|
||||||
|
|
||||||
Please delete options that are not relevant.
|
|
||||||
|
|
||||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
|
||||||
- [ ] New feature (non-breaking change which adds functionality)
|
|
||||||
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
|
||||||
- [ ] This change requires a documentation update
|
|
||||||
|
|
||||||
# How Has This Been Tested?
|
|
||||||
|
|
||||||
Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration.
|
|
||||||
|
|
||||||
# Checklist
|
|
||||||
|
|
||||||
- [ ] My code follows the style guidelines of this project
|
|
||||||
- [ ] I have performed a self-review of my own code
|
|
||||||
- [ ] I have commented my code, particularly in hard-to-understand areas
|
|
||||||
- [ ] I have made corresponding changes to the documentation
|
|
||||||
- [ ] My changes generate no new warnings
|
|
||||||
- [ ] I have added tests that provde my fix is effective or that my feature works
|
|
||||||
- [ ] New and existing unit tests pass locally with my changes
|
|
||||||
- [ ] Any dependent changes have been merged and published in downstream modules
|
|
|
@ -1,5 +1 @@
|
||||||
app.ts
|
app.ts
|
||||||
|
|
||||||
tests/
|
|
||||||
jest.config.cjs
|
|
||||||
jest.setup.js
|
|
|
@ -196,10 +196,7 @@ function ban (member) {
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
// handle error here
|
// handle error here
|
||||||
});
|
});
|
||||||
}
|
}# Contributing to Random Bunny
|
||||||
```
|
|
||||||
|
|
||||||
# Contributing to Random Bunny
|
|
||||||
|
|
||||||
First off, thanks for taking the time to contribute!
|
First off, thanks for taking the time to contribute!
|
||||||
|
|
||||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020-2023 Vylpes
|
Copyright (c) 2020 Vylpes
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
4
app.ts
4
app.ts
|
@ -1,7 +1,7 @@
|
||||||
import randomBunny from "./dist/index.js";
|
import randomBunny from "./dist";
|
||||||
|
|
||||||
async function app() {
|
async function app() {
|
||||||
const result = await randomBunny('rabbits', 'hot');
|
const result = await randomBunny('rabbits', 'hot', 100);
|
||||||
|
|
||||||
console.log(result);
|
console.log(result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
preset: "ts-jest",
|
|
||||||
setupFiles: [ "./jest.setup.js" ]
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
jest.setTimeout(1 * 1000); // 1 second
|
|
||||||
jest.resetModules();
|
|
||||||
jest.resetAllMocks();
|
|
21
license
Normal file
21
license
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020 Vylpes
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
26
package.json
26
package.json
|
@ -4,7 +4,7 @@
|
||||||
"description": "Get a random subreddit image url",
|
"description": "Get a random subreddit image url",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "Vylpes",
|
"author": "Vylpes",
|
||||||
"exports": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"typings": "./dist/index.d.ts",
|
"typings": "./dist/index.d.ts",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"rabbit",
|
"rabbit",
|
||||||
|
@ -17,15 +17,14 @@
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"glob-parent": "^6.0.0",
|
"glob-parent": "^6.0.0",
|
||||||
"got-cjs": "^12.5.4",
|
"got": "^11.8.3",
|
||||||
"linqts": "^1.14.4"
|
"linqts": "^1.14.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"start": "ts-node app.ts",
|
"start": "ts-node app.ts",
|
||||||
"test": "jest",
|
"test": "echo none",
|
||||||
"lint": "eslint .",
|
"lint": "eslint ."
|
||||||
"release": "np --no-publish"
|
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitea.vylpes.xyz/RabbitLabs/random-bunny/issues",
|
"url": "https://gitea.vylpes.xyz/RabbitLabs/random-bunny/issues",
|
||||||
|
@ -34,19 +33,10 @@
|
||||||
"homepage": "https://gitea.vylpes.xyz/RabbitLabs/random-bunny",
|
"homepage": "https://gitea.vylpes.xyz/RabbitLabs/random-bunny",
|
||||||
"funding": "https://ko-fi.com/vylpes",
|
"funding": "https://ko-fi.com/vylpes",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/eslint": "^8.21.1",
|
"@types/node": "^16.11.11",
|
||||||
"@types/jest": "^29.4.0",
|
"eslint": "^7.17.0",
|
||||||
"@types/node": "^18.0.0",
|
"ts-node": "^10.4.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
"typescript": "^4.5.2"
|
||||||
"@typescript-eslint/parser": "^5.54.0",
|
|
||||||
"eslint": "^8.35.0",
|
|
||||||
"jest": "^29.4.3",
|
|
||||||
"jest-mock-extended": "^3.0.3",
|
|
||||||
"np": "^7.7.0",
|
|
||||||
"ts-jest": "^29.0.5",
|
|
||||||
"ts-mockito": "^2.6.1",
|
|
||||||
"ts-node": "^10.9.1",
|
|
||||||
"typescript": "^5.0.0"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
|
|
|
@ -21,7 +21,7 @@ yarn add random-bunny
|
||||||
import randomBunny from "random-bunny";
|
import randomBunny from "random-bunny";
|
||||||
|
|
||||||
// ... In an async function
|
// ... In an async function
|
||||||
const result = await randomBunny('rabbits', 'hot');
|
const result = await randomBunny('rabbits', 'hot', 100);
|
||||||
console.log(result);
|
console.log(result);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ console.log(result);
|
||||||
|
|
||||||
### `randomBunny()`
|
### `randomBunny()`
|
||||||
|
|
||||||
Returns a `json string` for a random post. Accepts 2 arguments: `subreddit`, and `sortby` ('new', 'hot', 'top')
|
Returns a `json string` for a random post. Accepts 3 arguments: `subreddit`, `sortby` ('new', 'hot', 'top'), `maxTries?` (default 100)
|
||||||
|
|
||||||
The json string which gets returned consists of:
|
The json string which gets returned consists of:
|
||||||
- archived
|
- archived
|
||||||
|
@ -44,6 +44,8 @@ The json string which gets returned consists of:
|
||||||
|
|
||||||
`sortBy` will default to 'hot' if not given or invalid
|
`sortBy` will default to 'hot' if not given or invalid
|
||||||
|
|
||||||
|
`maxTries` prevents the script from rerolling too many times. The script rerolls the randomiser if the post its given doesn't contain an image. Default 100.
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
* Node 4 or newer.
|
* Node 4 or newer.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import IRedditResult from "./IRedditResult.js";
|
import IRedditResult from "./IRedditResult";
|
||||||
|
|
||||||
export default interface IReturnResult {
|
export default interface IReturnResult {
|
||||||
IsSuccess: boolean;
|
IsSuccess: boolean;
|
||||||
|
|
62
src/index.ts
62
src/index.ts
|
@ -1,8 +1,8 @@
|
||||||
import IReturnResult from "./contracts/IReturnResult.js";
|
import IReturnResult from "./contracts/IReturnResult";
|
||||||
import IRedditResult from "./contracts/IRedditResult.js";
|
import IRedditResult from "./contracts/IRedditResult";
|
||||||
import fetch from "got-cjs";
|
import fetch from "got";
|
||||||
import { List } from 'linqts';
|
import { List } from 'linqts';
|
||||||
import IFetchResult from "./contracts/IFetchResult.js";
|
import IFetchResult from "./contracts/IFetchResult";
|
||||||
|
|
||||||
const sortable = [
|
const sortable = [
|
||||||
'new',
|
'new',
|
||||||
|
@ -10,7 +10,7 @@ const sortable = [
|
||||||
'top'
|
'top'
|
||||||
];
|
];
|
||||||
|
|
||||||
export default async function randomBunny(subreddit: string, sortBy?: string): Promise<IReturnResult> {
|
export default async function randomBunny(subreddit: string, sortBy?: string, maxTries = 100): Promise<IReturnResult> {
|
||||||
if (!sortBy || !sortable.includes(sortBy)) sortBy = 'hot';
|
if (!sortBy || !sortable.includes(sortBy)) sortBy = 'hot';
|
||||||
|
|
||||||
const result = await fetch(`https://reddit.com/r/${subreddit}/${sortBy}.json`);
|
const result = await fetch(`https://reddit.com/r/${subreddit}/${sortBy}.json`);
|
||||||
|
@ -30,39 +30,39 @@ export default async function randomBunny(subreddit: string, sortBy?: string): P
|
||||||
}
|
}
|
||||||
|
|
||||||
const data: IFetchResult[] = json.data.children;
|
const data: IFetchResult[] = json.data.children;
|
||||||
|
|
||||||
const dataWithImages = new List<IFetchResult>(data)
|
const dataWithImages = new List<IFetchResult>(data)
|
||||||
.Where(x => x!.data.url.includes('.jpg') || x!.data.url.includes('.png'))
|
.Where(x => x!.data.url.includes('.jpg') || x!.data.url.includes('.png'))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
let random = 0;
|
for (let i = 0; i < maxTries; i++) {
|
||||||
|
const random = Math.floor((Math.random() * dataWithImages.length - 1) + 0); // Between 0 and (size - 1)
|
||||||
|
|
||||||
if (dataWithImages.length == 0) {
|
const randomSelect = dataWithImages[random];
|
||||||
return {
|
|
||||||
IsSuccess: false,
|
if (!randomSelect) continue;
|
||||||
|
|
||||||
|
const randomData = randomSelect.data;
|
||||||
|
|
||||||
|
const redditResult: IRedditResult = {
|
||||||
|
Archived: randomData['archived'],
|
||||||
|
Downs: randomData['downs'],
|
||||||
|
Hidden: randomData['hidden'],
|
||||||
|
Permalink: randomData['permalink'],
|
||||||
|
Subreddit: randomData['subreddit'],
|
||||||
|
SubredditSubscribers: randomData['subreddit_subscribers'],
|
||||||
|
Title: randomData['title'],
|
||||||
|
Ups: randomData['ups'],
|
||||||
|
Url: randomData['url']
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
IsSuccess: true,
|
||||||
|
Result: redditResult
|
||||||
};
|
};
|
||||||
} 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;
|
|
||||||
|
|
||||||
const redditResult: IRedditResult = {
|
|
||||||
Archived: randomData['archived'],
|
|
||||||
Downs: randomData['downs'],
|
|
||||||
Hidden: randomData['hidden'],
|
|
||||||
Permalink: randomData['permalink'],
|
|
||||||
Subreddit: randomData['subreddit'],
|
|
||||||
SubredditSubscribers: randomData['subreddit_subscribers'],
|
|
||||||
Title: randomData['title'],
|
|
||||||
Ups: randomData['ups'],
|
|
||||||
Url: randomData['url']
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
IsSuccess: true,
|
IsSuccess: false
|
||||||
Result: redditResult
|
}
|
||||||
};
|
|
||||||
}
|
}
|
|
@ -1,172 +0,0 @@
|
||||||
import randomBunny from "../src/index";
|
|
||||||
import fetch from "got-cjs";
|
|
||||||
|
|
||||||
jest.mock('got-cjs');
|
|
||||||
const fetchMock = jest.mocked(fetch);
|
|
||||||
|
|
||||||
describe('randomBunny', () => {
|
|
||||||
test('GIVEN subreddit AND sortBy is supplied, EXPECT successful result', async() => {
|
|
||||||
fetchMock.mockResolvedValue({
|
|
||||||
body: JSON.stringify({
|
|
||||||
data: {
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
data: {
|
|
||||||
archived: false,
|
|
||||||
downs: 0,
|
|
||||||
hidden: false,
|
|
||||||
permalink: '/r/Rabbits/comments/12pa5te/someone_told_pickles_its_monday_internal_fury/',
|
|
||||||
subreddit: 'Rabbits',
|
|
||||||
subreddit_subscribers: 298713,
|
|
||||||
title: 'Someone told pickles it’s Monday… *internal fury*',
|
|
||||||
ups: 1208,
|
|
||||||
url: 'https://i.redd.it/cr8xudsnkgua1.jpg',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await randomBunny('rabbits', 'new');
|
|
||||||
|
|
||||||
expect(result.IsSuccess).toBeTruthy();
|
|
||||||
expect(result.Result).toBeDefined();
|
|
||||||
|
|
||||||
expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('GIVEN sortBy is NOT supplied, expect it to default to hot', async () => {
|
|
||||||
fetchMock.mockResolvedValue({
|
|
||||||
body: JSON.stringify({
|
|
||||||
data: {
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
data: {
|
|
||||||
archived: false,
|
|
||||||
downs: 0,
|
|
||||||
hidden: false,
|
|
||||||
permalink: '/r/Rabbits/comments/12pa5te/someone_told_pickles_its_monday_internal_fury/',
|
|
||||||
subreddit: 'Rabbits',
|
|
||||||
subreddit_subscribers: 298713,
|
|
||||||
title: 'Someone told pickles it’s Monday… *internal fury*',
|
|
||||||
ups: 1208,
|
|
||||||
url: 'https://i.redd.it/cr8xudsnkgua1.jpg',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await randomBunny('rabbits');
|
|
||||||
|
|
||||||
expect(result.IsSuccess).toBeTruthy();
|
|
||||||
expect(result.Result).toBeDefined();
|
|
||||||
|
|
||||||
expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/hot.json');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('GIVEN sortBy is NOT valid, expect it to default to hot', async () => {
|
|
||||||
fetchMock.mockResolvedValue({
|
|
||||||
body: JSON.stringify({
|
|
||||||
data: {
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
data: {
|
|
||||||
archived: false,
|
|
||||||
downs: 0,
|
|
||||||
hidden: false,
|
|
||||||
permalink: '/r/Rabbits/comments/12pa5te/someone_told_pickles_its_monday_internal_fury/',
|
|
||||||
subreddit: 'Rabbits',
|
|
||||||
subreddit_subscribers: 298713,
|
|
||||||
title: 'Someone told pickles it’s Monday… *internal fury*',
|
|
||||||
ups: 1208,
|
|
||||||
url: 'https://i.redd.it/cr8xudsnkgua1.jpg',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await randomBunny('rabbits', 'invalid');
|
|
||||||
|
|
||||||
expect(result.IsSuccess).toBeTruthy();
|
|
||||||
expect(result.Result).toBeDefined();
|
|
||||||
|
|
||||||
expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/hot.json');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('GIVEN the fetch fails, EXPECT failure result', async () => {
|
|
||||||
fetchMock.mockResolvedValue(null);
|
|
||||||
|
|
||||||
const result = await randomBunny('rabbits', 'new');
|
|
||||||
|
|
||||||
expect(result.IsSuccess).toBeFalsy();
|
|
||||||
expect(result.Result).toBeUndefined();
|
|
||||||
|
|
||||||
expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('GIVEN the result is NOT valid JSON, EXPECT failure result', async () => {
|
|
||||||
fetchMock.mockResolvedValue({
|
|
||||||
body: JSON.stringify(null),
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await randomBunny('rabbits', 'new');
|
|
||||||
|
|
||||||
expect(result.IsSuccess).toBeFalsy();
|
|
||||||
expect(result.Result).toBeUndefined();
|
|
||||||
|
|
||||||
expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('GIVEN randomSelect does NOT find a response, EXPECT failure result', async () => {
|
|
||||||
fetchMock.mockResolvedValue({
|
|
||||||
body: JSON.stringify({
|
|
||||||
data: {
|
|
||||||
children: [],
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await randomBunny('rabbits', 'new');
|
|
||||||
|
|
||||||
expect(result.IsSuccess).toBeFalsy();
|
|
||||||
expect(result.Result).toBeUndefined();
|
|
||||||
|
|
||||||
expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('GIVEN randomSelect does NOT find a valid response, EXPECT failure result', async () => {
|
|
||||||
fetchMock.mockResolvedValue({
|
|
||||||
body: JSON.stringify({
|
|
||||||
data: {
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
data: {
|
|
||||||
archived: false,
|
|
||||||
downs: 0,
|
|
||||||
hidden: false,
|
|
||||||
permalink: '/r/Rabbits/comments/12pa5te/someone_told_pickles_its_monday_internal_fury/',
|
|
||||||
subreddit: 'Rabbits',
|
|
||||||
subreddit_subscribers: 298713,
|
|
||||||
title: 'Someone told pickles it’s Monday… *internal fury*',
|
|
||||||
ups: 1208,
|
|
||||||
url: 'https://i.redd.it/cr8xudsnkgua1.webp',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await randomBunny('rabbits', 'new');
|
|
||||||
|
|
||||||
expect(result.IsSuccess).toBeFalsy();
|
|
||||||
expect(result.Result).toBeUndefined();
|
|
||||||
|
|
||||||
expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json');
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,11 +1,11 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||||
|
|
||||||
/* Basic Options */
|
/* Basic Options */
|
||||||
// "incremental": true, /* Enable incremental compilation */
|
// "incremental": true, /* Enable incremental compilation */
|
||||||
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
|
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
|
||||||
"module": "Node16", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
// "checkJs": true, /* Report errors in .js files. */
|
// "checkJs": true, /* Report errors in .js files. */
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||||
|
|
||||||
/* Strict Type-Checking Options */
|
/* Strict Type-Checking Options */
|
||||||
"strict": true, /* Enable all strict type-checking options. */
|
"strict": true, /* Enable all strict type-checking options. */
|
||||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||||
|
|
||||||
/* Additional Checks */
|
/* Additional Checks */
|
||||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||||
|
@ -42,9 +42,9 @@
|
||||||
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
||||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */
|
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */
|
||||||
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
||||||
|
|
||||||
/* Module Resolution Options */
|
/* Module Resolution Options */
|
||||||
"moduleResolution": "node16", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||||
|
@ -54,17 +54,17 @@
|
||||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||||
|
|
||||||
/* Source Map Options */
|
/* Source Map Options */
|
||||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||||
|
|
||||||
/* Experimental Options */
|
/* Experimental Options */
|
||||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||||
|
|
||||||
/* Advanced Options */
|
/* Advanced Options */
|
||||||
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
||||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||||
|
@ -73,11 +73,7 @@
|
||||||
"./src",
|
"./src",
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"./tests",
|
"./tests"
|
||||||
"jest.config.cjs",
|
]
|
||||||
"jest.setup.js"
|
|
||||||
],
|
|
||||||
"ts-node": {
|
|
||||||
"esm": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue