Compare commits
No commits in common. "renovate/linqts-2.x" and "master" have entirely different histories.
renovate/l
...
master
12 changed files with 443 additions and 700 deletions
10
docs/cli.md
10
docs/cli.md
|
@ -9,12 +9,13 @@ The project can be downloaded as a binary for your system via the [GitHub Releas
|
||||||
We currently support:
|
We currently support:
|
||||||
- Linux (x64)
|
- Linux (x64)
|
||||||
- Windows (x64)
|
- Windows (x64)
|
||||||
|
- macOS (x64, Arm64\*)
|
||||||
|
|
||||||
The git repository can also be cloned and ran via `yarn build` and `yarn start`.
|
The git repository can also be cloned and ran via `yarn build` and `yarn start`.
|
||||||
|
|
||||||
You can produce the binary using the `yarn package` command. This creates the binaries in the `./bin` folder.
|
You can produce the binary using the `yarn package` command. This creates the binaries in the `./bin` folder.
|
||||||
|
|
||||||
> **NOTE:** As of version 2.4 I will no longer be supporting and building macOS builds as I have no capacity to test and build for it.
|
> **NOTE:** We are aware of a bug in the macOS Arm64 builds failing to execute. For now you're still able to use the x64 builds under Rosetta fine. This will hopefully be fixed in a future release.
|
||||||
|
|
||||||
## Default Output
|
## Default Output
|
||||||
|
|
||||||
|
@ -26,7 +27,6 @@ $ random-bunny
|
||||||
Archived = false
|
Archived = false
|
||||||
Author = Rabbit_Owner
|
Author = Rabbit_Owner
|
||||||
Downvotes = 0
|
Downvotes = 0
|
||||||
Gallery = https://i.redd.it/sfz0srdrimjc1.png, https://i.redd.it/sfz0srdrimjc1.png
|
|
||||||
Hidden = false
|
Hidden = false
|
||||||
Permalink = /r/Rabbits/comments/1av1rg9/cute_baby_bun/
|
Permalink = /r/Rabbits/comments/1av1rg9/cute_baby_bun/
|
||||||
Subreddit = Rabbits
|
Subreddit = Rabbits
|
||||||
|
@ -36,8 +36,6 @@ Upvotes = 211
|
||||||
Url = https://i.redd.it/sfz0srdrimjc1.png
|
Url = https://i.redd.it/sfz0srdrimjc1.png
|
||||||
```
|
```
|
||||||
|
|
||||||
- The `Gallery` field is only shown when there is more than 1 image returned, which then the `Url` field is the first image of that list.
|
|
||||||
|
|
||||||
## Help
|
## Help
|
||||||
|
|
||||||
The command also includes a help option in case you are stuck.
|
The command also includes a help option in case you are stuck.
|
||||||
|
@ -75,11 +73,9 @@ $ random-bunny --json
|
||||||
|
|
||||||
$ randon-bunny -j
|
$ randon-bunny -j
|
||||||
|
|
||||||
{"Archived":false,"Author":"Rabbit_Owner","Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1av1rg9/cute_baby_bun/","Subreddit":"Rabbits","SubredditSubscribers":486085,"Title":"Cute baby bun","Ups":210,"Url":"https://i.redd.it/sfz0srdrimjc1.png","Gallery":["https://i.redd.it/sfz0srdrimjc1.png"]}
|
{"Archived":false,"Author":"Rabbit_Owner","Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1av1rg9/cute_baby_bun/","Subreddit":"Rabbits","SubredditSubscribers":486085,"Title":"Cute baby bun","Ups":210,"Url":"https://i.redd.it/sfz0srdrimjc1.png"}
|
||||||
```
|
```
|
||||||
|
|
||||||
- The `Url` field is the first image of the `Gallery` array
|
|
||||||
|
|
||||||
## Sort
|
## Sort
|
||||||
|
|
||||||
You can also choose the sorting option which reddit will use to return the available posts to randomise from.
|
You can also choose the sorting option which reddit will use to return the available posts to randomise from.
|
||||||
|
|
24
package.json
24
package.json
|
@ -6,9 +6,7 @@
|
||||||
"author": "Vylpes",
|
"author": "Vylpes",
|
||||||
"exports": "./dist/index.js",
|
"exports": "./dist/index.js",
|
||||||
"typings": "./dist/index.d.ts",
|
"typings": "./dist/index.d.ts",
|
||||||
"bin": {
|
"bin": "./dist/cli.js",
|
||||||
"random-bunny": "./dist/cli.js"
|
|
||||||
},
|
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"rabbit",
|
"rabbit",
|
||||||
|
@ -24,7 +22,7 @@
|
||||||
"glob-parent": "^6.0.0",
|
"glob-parent": "^6.0.0",
|
||||||
"got-cjs": "^12.5.4",
|
"got-cjs": "^12.5.4",
|
||||||
"htmlparser2": "^9.1.0",
|
"htmlparser2": "^9.1.0",
|
||||||
"linqts": "^2.0.0"
|
"linqts": "^1.14.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
|
@ -45,20 +43,24 @@
|
||||||
"@eslint/js": "^9.8.0",
|
"@eslint/js": "^9.8.0",
|
||||||
"@types/eslint": "^9.6.0",
|
"@types/eslint": "^9.6.0",
|
||||||
"@types/jest": "^29.5.8",
|
"@types/jest": "^29.5.8",
|
||||||
"@types/node": "^22.0.0",
|
"@types/node": "^20.0.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
||||||
"@typescript-eslint/parser": "^8.0.0",
|
"@typescript-eslint/parser": "^7.18.0",
|
||||||
"@yao-pkg/pkg": "^6.1.1",
|
"@yao-pkg/pkg": "^5.12.0",
|
||||||
"eslint": "^9.8.0",
|
"eslint": "^9.8.0",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-mock-extended": "^3.0.7",
|
"jest-mock-extended": "^3.0.3",
|
||||||
"np": "^10.0.0",
|
"np": "^10.0.0",
|
||||||
"ts-jest": "^29.1.1",
|
"ts-jest": "^29.1.1",
|
||||||
"ts-mockito": "^2.6.1",
|
"ts-mockito": "^2.6.1",
|
||||||
"typescript": "^5.0.0",
|
"typescript": "^5.0.0",
|
||||||
"typescript-eslint": "^7.18.0"
|
"typescript-eslint": "^7.18.0"
|
||||||
},
|
},
|
||||||
"resolutions": {},
|
"resolutions": {
|
||||||
|
"np/**/got": "^14.0.0",
|
||||||
|
"**/semver": "^7.5.2",
|
||||||
|
"@babel/traverse": "^7.23.2"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
|
@ -66,6 +68,8 @@
|
||||||
"scripts": "dist/**/*.js",
|
"scripts": "dist/**/*.js",
|
||||||
"targets": [
|
"targets": [
|
||||||
"latest-linux-x64",
|
"latest-linux-x64",
|
||||||
|
"latest-macos-x64",
|
||||||
|
"latest-macos-arm64",
|
||||||
"latest-win-x64"
|
"latest-win-x64"
|
||||||
],
|
],
|
||||||
"outputPath": "bin"
|
"outputPath": "bin"
|
||||||
|
|
|
@ -39,7 +39,6 @@ The json string which gets returned consists of:
|
||||||
- archived
|
- archived
|
||||||
- author
|
- author
|
||||||
- downs
|
- downs
|
||||||
- gallery
|
|
||||||
- hidden
|
- hidden
|
||||||
- permalink
|
- permalink
|
||||||
- subreddit
|
- subreddit
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#!/usr/bin/env node
|
|
||||||
import { Command, Option } from "commander";
|
import { Command, Option } from "commander";
|
||||||
import randomBunny from "./index";
|
import randomBunny from "./index";
|
||||||
import ICliOptions from "./contracts/ICliOptions";
|
import ICliOptions from "./contracts/ICliOptions";
|
||||||
|
|
|
@ -2,12 +2,11 @@ export default interface IRedditResult {
|
||||||
Archived: boolean,
|
Archived: boolean,
|
||||||
Author: string,
|
Author: string,
|
||||||
Downs: number,
|
Downs: number,
|
||||||
Gallery: string[],
|
|
||||||
Hidden: boolean,
|
Hidden: boolean,
|
||||||
Permalink: string,
|
Permalink: string,
|
||||||
Subreddit: string,
|
Subreddit: string,
|
||||||
SubredditSubscribers: number,
|
SubredditSubscribers: number,
|
||||||
Title: string,
|
Title: string,
|
||||||
Ups: number,
|
Ups: number,
|
||||||
Url: string,
|
Url: string
|
||||||
}
|
}
|
|
@ -2,19 +2,17 @@ import fetch from "got-cjs";
|
||||||
import * as htmlparser from "htmlparser2";
|
import * as htmlparser from "htmlparser2";
|
||||||
|
|
||||||
export default class ImageHelper {
|
export default class ImageHelper {
|
||||||
public static async FetchImageFromRedditGallery(url: string): Promise<string[]> {
|
public static async FetchImageFromRedditGallery(url: string): Promise<string | undefined> {
|
||||||
const fetched = await fetch(url);
|
const fetched = await fetch(url);
|
||||||
|
|
||||||
if (!fetched || fetched.errored || fetched.statusCode != 200) {
|
if (!fetched || fetched.errored || fetched.statusCode != 200) {
|
||||||
return [];
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dom = htmlparser.parseDocument(fetched.body);
|
const dom = htmlparser.parseDocument(fetched.body);
|
||||||
const img = htmlparser.DomUtils.findAll((x => x.tagName == "img" && x.attributes.find(y => y.value.includes("https://preview.redd.it")) != null), dom.children);
|
const img = htmlparser.DomUtils.findOne((x => x.tagName == "img" && x.attributes.find(y => y.value.includes("https://preview.redd.it")) != null), dom.children, true);
|
||||||
|
|
||||||
const imgSrc = img
|
const imgSrc = img?.attributes.find(x => x.name == "src")?.value;
|
||||||
.flatMap(x => x.attributes.find(x => x.name == "src")?.value)
|
|
||||||
.filter(x => x != undefined);
|
|
||||||
|
|
||||||
return imgSrc;
|
return imgSrc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,28 +5,29 @@ export default class OutputHelper {
|
||||||
public static GenerateOutput(response: IReturnResult, options: ICliOptions): string {
|
public static GenerateOutput(response: IReturnResult, options: ICliOptions): string {
|
||||||
const result = response.Result!;
|
const result = response.Result!;
|
||||||
|
|
||||||
let outputObject = {};
|
const outputLines: string[] = [];
|
||||||
|
|
||||||
outputObject = { ...result };
|
|
||||||
|
|
||||||
if (options.queryMetadata) {
|
|
||||||
outputObject = { ...outputObject, ...response.Query }
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.json) {
|
if (options.json) {
|
||||||
return JSON.stringify(outputObject);
|
return JSON.stringify(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.GetFriendlyObjectText(outputObject);
|
outputLines.push(`Archived = ${result.Archived}`);
|
||||||
}
|
outputLines.push(`Author = ${result.Author}`);
|
||||||
|
outputLines.push(`Downvotes = ${result.Downs}`);
|
||||||
|
outputLines.push(`Hidden = ${result.Hidden}`);
|
||||||
|
outputLines.push(`Permalink = ${result.Permalink}`);
|
||||||
|
outputLines.push(`Subreddit = ${result.Subreddit}`);
|
||||||
|
outputLines.push(`Subreddit Subscribers = ${result.SubredditSubscribers}`);
|
||||||
|
outputLines.push(`Title = ${result.Title}`);
|
||||||
|
outputLines.push(`Upvotes = ${result.Ups}`);
|
||||||
|
outputLines.push(`Url = ${result.Url}`);
|
||||||
|
|
||||||
private static GetFriendlyObjectText<T>(object: T): string {
|
if (options.queryMetadata != null) {
|
||||||
const output: string[] = [];
|
outputLines.push(`Query.Subreddit = ${response.Query.subreddit}`);
|
||||||
|
outputLines.push(`Query.Sort By = ${response.Query.sortBy}`);
|
||||||
for (const key in object) {
|
outputLines.push(`Query.Limit = ${response.Query.limit}`);
|
||||||
output.push(`${key} = ${object[key]}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return output.join("\n");
|
return outputLines.join("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -93,7 +93,6 @@ export default async function randomBunny(subreddit: string, sortBy: "new" | "ho
|
||||||
const randomData = randomSelect.data;
|
const randomData = randomSelect.data;
|
||||||
|
|
||||||
let url: string;
|
let url: string;
|
||||||
let gallery: string[];
|
|
||||||
|
|
||||||
if (randomData.url.includes("/gallery")) {
|
if (randomData.url.includes("/gallery")) {
|
||||||
const galleryImage = await ImageHelper.FetchImageFromRedditGallery(randomData.url);
|
const galleryImage = await ImageHelper.FetchImageFromRedditGallery(randomData.url);
|
||||||
|
@ -113,11 +112,9 @@ export default async function randomBunny(subreddit: string, sortBy: "new" | "ho
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
url = galleryImage[0];
|
url = galleryImage;
|
||||||
gallery = galleryImage;
|
|
||||||
} else {
|
} else {
|
||||||
url = randomData.url;
|
url = randomData.url;
|
||||||
gallery = [randomData.url];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const redditResult: IRedditResult = {
|
const redditResult: IRedditResult = {
|
||||||
|
@ -131,7 +128,6 @@ export default async function randomBunny(subreddit: string, sortBy: "new" | "ho
|
||||||
Title: randomData['title'],
|
Title: randomData['title'],
|
||||||
Ups: randomData['ups'],
|
Ups: randomData['ups'],
|
||||||
Url: url,
|
Url: url,
|
||||||
Gallery: gallery,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -3,48 +3,30 @@
|
||||||
exports[`GenerateOutput EXPECT standout output to be returned 1`] = `
|
exports[`GenerateOutput EXPECT standout output to be returned 1`] = `
|
||||||
"Archived = false
|
"Archived = false
|
||||||
Author = author
|
Author = author
|
||||||
Downs = 0
|
Downvotes = 0
|
||||||
Hidden = false
|
Hidden = false
|
||||||
Permalink = /r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/
|
Permalink = /r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/
|
||||||
Subreddit = Rabbits
|
Subreddit = Rabbits
|
||||||
SubredditSubscribers = 654751
|
Subreddit Subscribers = 654751
|
||||||
Title = This is my Ms Bear!
|
Title = This is my Ms Bear!
|
||||||
Ups = 17
|
Upvotes = 17
|
||||||
Url = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d
|
Url = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d"
|
||||||
Gallery = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d"
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`GenerateOutput GIVEN options.json is true, EXPECT output to be returned as JSON 1`] = `"{"Archived":false,"Author":"author","Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/","Subreddit":"Rabbits","SubredditSubscribers":654751,"Title":"This is my Ms Bear!","Ups":17,"Url":"https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d","Gallery":["https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d"]}"`;
|
exports[`GenerateOutput GIVEN options.json is true, EXPECT output to be returned as JSON 1`] = `"{"Archived":false,"Author":"author","Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/","Subreddit":"Rabbits","SubredditSubscribers":654751,"Title":"This is my Ms Bear!","Ups":17,"Url":"https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d"}"`;
|
||||||
|
|
||||||
exports[`GenerateOutput GIVEN options.queryMetadata AND options.json is supplied, EXPECT query metadata to be in JSON format 1`] = `"{"Archived":false,"Author":"author","Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/","Subreddit":"Rabbits","SubredditSubscribers":654751,"Title":"This is my Ms Bear!","Ups":17,"Url":"https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d","subreddit":"rabbits","sortBy":"hot","limit":100}"`;
|
|
||||||
|
|
||||||
exports[`GenerateOutput GIVEN options.queryMetadata is supplied, EXPECT query metadata to be added 1`] = `
|
exports[`GenerateOutput GIVEN options.queryMetadata is supplied, EXPECT query metadata to be added 1`] = `
|
||||||
"Archived = false
|
"Archived = false
|
||||||
Author = author
|
Author = author
|
||||||
Downs = 0
|
Downvotes = 0
|
||||||
Hidden = false
|
Hidden = false
|
||||||
Permalink = /r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/
|
Permalink = /r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/
|
||||||
Subreddit = Rabbits
|
Subreddit = Rabbits
|
||||||
SubredditSubscribers = 654751
|
Subreddit Subscribers = 654751
|
||||||
Title = This is my Ms Bear!
|
Title = This is my Ms Bear!
|
||||||
Ups = 17
|
Upvotes = 17
|
||||||
Url = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d
|
Url = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d
|
||||||
Gallery = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d
|
Query.Subreddit = rabbits
|
||||||
subreddit = rabbits
|
Query.Sort By = hot
|
||||||
sortBy = hot
|
Query.Limit = 100"
|
||||||
limit = 100"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`GenerateOutput GIVEN the Gallery input has more than 1 item, EXPECT Gallery line to be added 1`] = `
|
|
||||||
"Archived = false
|
|
||||||
Author = author
|
|
||||||
Downs = 0
|
|
||||||
Hidden = false
|
|
||||||
Permalink = /r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/
|
|
||||||
Subreddit = Rabbits
|
|
||||||
SubredditSubscribers = 654751
|
|
||||||
Title = This is my Ms Bear!
|
|
||||||
Ups = 17
|
|
||||||
Url = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d
|
|
||||||
Gallery = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d,https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d"
|
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -17,19 +17,18 @@ describe("FetchImageFromRedditGallery", () => {
|
||||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||||
expect(fetchMock).toHaveBeenCalledWith("https://redd.it/gallery/image");
|
expect(fetchMock).toHaveBeenCalledWith("https://redd.it/gallery/image");
|
||||||
|
|
||||||
expect(result.length).toBe(1);
|
expect(result).toBe("https://preview.redd.it/image.png");
|
||||||
expect(result[0]).toBe("https://preview.redd.it/image.png");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("GIVEN fetch is unable to return data, EXPECT empty array returned", async () => {
|
test("GIVEN fetch is unable to return data, EXPECT undefined returned", async () => {
|
||||||
fetchMock.mockResolvedValue(null);
|
fetchMock.mockResolvedValue(null);
|
||||||
|
|
||||||
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image");
|
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image");
|
||||||
|
|
||||||
expect(result.length).toBe(0);
|
expect(result).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("GIVEN fetch is an error, EXPECT empty array returned", async () => {
|
test("GIVEN fetch is an error, EXPECT undefined returned", async () => {
|
||||||
fetchMock.mockResolvedValue({
|
fetchMock.mockResolvedValue({
|
||||||
body: "<html><body><img src='https://preview.redd.it/image.png' /></body></html>",
|
body: "<html><body><img src='https://preview.redd.it/image.png' /></body></html>",
|
||||||
errored: "Error",
|
errored: "Error",
|
||||||
|
@ -38,10 +37,10 @@ describe("FetchImageFromRedditGallery", () => {
|
||||||
|
|
||||||
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image");
|
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image");
|
||||||
|
|
||||||
expect(result.length).toBe(0);
|
expect(result).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("GIVEN fetch is not status code of 200, EXPECT empty array returned", async () => {
|
test("GIVEN fetch is not status code of 200, EXPECT undefined returned", async () => {
|
||||||
fetchMock.mockResolvedValue({
|
fetchMock.mockResolvedValue({
|
||||||
body: "<html><body><img src='https://preview.redd.it/image.png' /></body></html>",
|
body: "<html><body><img src='https://preview.redd.it/image.png' /></body></html>",
|
||||||
errored: undefined,
|
errored: undefined,
|
||||||
|
@ -50,10 +49,10 @@ describe("FetchImageFromRedditGallery", () => {
|
||||||
|
|
||||||
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image");
|
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image");
|
||||||
|
|
||||||
expect(result.length).toBe(0);
|
expect(result).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("GIVEN image tag is not found, EXPECT empty array returned", async () => {
|
test("GIVEN image tag is not found, EXPECT undefined returned", async () => {
|
||||||
fetchMock.mockResolvedValue({
|
fetchMock.mockResolvedValue({
|
||||||
body: "<html><body></body></html>",
|
body: "<html><body></body></html>",
|
||||||
errored: undefined,
|
errored: undefined,
|
||||||
|
@ -62,10 +61,10 @@ describe("FetchImageFromRedditGallery", () => {
|
||||||
|
|
||||||
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image");
|
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image");
|
||||||
|
|
||||||
expect(result.length).toBe(0);
|
expect(result).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("GIVEN image source attribute is not found, EXPECT empty array returned", async () => {
|
test("GIVEN image source attribute is not found, EXPECT undefined returned", async () => {
|
||||||
fetchMock.mockResolvedValue({
|
fetchMock.mockResolvedValue({
|
||||||
body: "<html><body><img /></body></html>",
|
body: "<html><body><img /></body></html>",
|
||||||
errored: undefined,
|
errored: undefined,
|
||||||
|
@ -74,10 +73,10 @@ describe("FetchImageFromRedditGallery", () => {
|
||||||
|
|
||||||
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image");
|
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image");
|
||||||
|
|
||||||
expect(result.length).toBe(0);
|
expect(result).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("GIVEN image source attribute is not found that is a preview.redd.it url, EXPECT empty array returned", async () => {
|
test("GIVEN image source attribute is not found that is a preview.redd.it url, EXPECT undefined returned", async () => {
|
||||||
fetchMock.mockResolvedValue({
|
fetchMock.mockResolvedValue({
|
||||||
body: "<html><body><img src='main.png' /></body></html>",
|
body: "<html><body><img src='main.png' /></body></html>",
|
||||||
errored: undefined,
|
errored: undefined,
|
||||||
|
@ -86,6 +85,6 @@ describe("FetchImageFromRedditGallery", () => {
|
||||||
|
|
||||||
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image");
|
const result = await ImageHelper.FetchImageFromRedditGallery("https://redd.it/gallery/image");
|
||||||
|
|
||||||
expect(result.length).toBe(0);
|
expect(result).toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
|
@ -23,7 +23,6 @@ describe("GenerateOutput", () => {
|
||||||
Title: "This is my Ms Bear!",
|
Title: "This is my Ms Bear!",
|
||||||
Ups: 17,
|
Ups: 17,
|
||||||
Url: "https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d",
|
Url: "https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d",
|
||||||
Gallery: ["https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d"],
|
|
||||||
},
|
},
|
||||||
} as IReturnResult;
|
} as IReturnResult;
|
||||||
|
|
||||||
|
@ -56,7 +55,6 @@ describe("GenerateOutput", () => {
|
||||||
Title: "This is my Ms Bear!",
|
Title: "This is my Ms Bear!",
|
||||||
Ups: 17,
|
Ups: 17,
|
||||||
Url: "https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d",
|
Url: "https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d",
|
||||||
Gallery: ["https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d"],
|
|
||||||
},
|
},
|
||||||
} as IReturnResult;
|
} as IReturnResult;
|
||||||
|
|
||||||
|
@ -91,7 +89,6 @@ describe("GenerateOutput", () => {
|
||||||
Title: "This is my Ms Bear!",
|
Title: "This is my Ms Bear!",
|
||||||
Ups: 17,
|
Ups: 17,
|
||||||
Url: "https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d",
|
Url: "https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d",
|
||||||
Gallery: ["https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d"],
|
|
||||||
},
|
},
|
||||||
} as IReturnResult;
|
} as IReturnResult;
|
||||||
|
|
||||||
|
@ -105,75 +102,4 @@ describe("GenerateOutput", () => {
|
||||||
// Assert
|
// Assert
|
||||||
expect(result).toMatchSnapshot();
|
expect(result).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("GIVEN options.queryMetadata AND options.json is supplied, EXPECT query metadata to be in JSON format", () => {
|
|
||||||
// Arrange
|
|
||||||
const response = {
|
|
||||||
IsSuccess: true,
|
|
||||||
Query: {
|
|
||||||
subreddit: "rabbits",
|
|
||||||
sortBy: "hot",
|
|
||||||
limit: 100,
|
|
||||||
},
|
|
||||||
Result: {
|
|
||||||
Archived: false,
|
|
||||||
Author: 'author',
|
|
||||||
Downs: 0,
|
|
||||||
Hidden: false,
|
|
||||||
Permalink: "/r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/",
|
|
||||||
Subreddit: "Rabbits",
|
|
||||||
SubredditSubscribers: 654751,
|
|
||||||
Title: "This is my Ms Bear!",
|
|
||||||
Ups: 17,
|
|
||||||
Url: "https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d",
|
|
||||||
},
|
|
||||||
} as IReturnResult;
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
json: true,
|
|
||||||
queryMetadata: true,
|
|
||||||
} as ICliOptions;
|
|
||||||
|
|
||||||
// Act
|
|
||||||
const result = OutputHelper.GenerateOutput(response, options);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(result).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("GIVEN the Gallery input has more than 1 item, EXPECT Gallery line to be added", () => {
|
|
||||||
// Arrange
|
|
||||||
const response = {
|
|
||||||
IsSuccess: true,
|
|
||||||
Query: {
|
|
||||||
subreddit: "rabbits",
|
|
||||||
sortBy: "hot",
|
|
||||||
limit: 100,
|
|
||||||
},
|
|
||||||
Result: {
|
|
||||||
Archived: false,
|
|
||||||
Author: 'author',
|
|
||||||
Downs: 0,
|
|
||||||
Hidden: false,
|
|
||||||
Permalink: "/r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/",
|
|
||||||
Subreddit: "Rabbits",
|
|
||||||
SubredditSubscribers: 654751,
|
|
||||||
Title: "This is my Ms Bear!",
|
|
||||||
Ups: 17,
|
|
||||||
Url: "https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d",
|
|
||||||
Gallery: [
|
|
||||||
"https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d",
|
|
||||||
"https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d"
|
|
||||||
],
|
|
||||||
},
|
|
||||||
} as IReturnResult;
|
|
||||||
|
|
||||||
const options = {} as ICliOptions;
|
|
||||||
|
|
||||||
// Act
|
|
||||||
const result = OutputHelper.GenerateOutput(response, options);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(result).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
});
|
});
|
Loading…
Reference in a new issue