diff --git a/src/cli.ts b/src/cli.ts index 6f0639f..0de5ab3 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,4 +1,4 @@ -import { Command, Option } from "commander"; +import { Command } from "commander"; import randomBunny from "./index"; import ICliOptions from "./contracts/ICliOptions"; import { exit } from "process"; @@ -9,15 +9,13 @@ program .name('random-bunny') .description('Get a random image url from a subreddit of your choosing') .version('2.2') - .option('-s, --subreddit ', 'The subreddit to search', 'rabbits') - .option('-q, --query-metadata', 'Include query metadata in result') - .addOption(new Option('--sort ', 'Sort by').default('hot').choices(['hot', 'new', 'top'])); + .option('-s, --subreddit ', 'The subreddit to search', 'rabbits'); program.parse(); const options: ICliOptions = program.opts(); -randomBunny(options.subreddit, options.sort) +randomBunny(options.subreddit) .then((response) => { if (response.IsSuccess) { const result = response.Result!; @@ -33,11 +31,6 @@ randomBunny(options.subreddit, options.sort) outputLines.push(`Upvotes = ${result.Ups}`); outputLines.push(`Url = ${result.Url}`); - if (options.queryMetadata != null) { - outputLines.push(`Query.Subreddit = ${response.Query.subreddit}`); - outputLines.push(`Query.Sort By = ${response.Query.sortBy}`); - } - console.log(outputLines.join("\n")); exit(0); } else { diff --git a/src/contracts/ICliOptions.ts b/src/contracts/ICliOptions.ts index ce5ada4..c85971d 100644 --- a/src/contracts/ICliOptions.ts +++ b/src/contracts/ICliOptions.ts @@ -1,5 +1,3 @@ export default interface ICliOptions { subreddit: string, - sort: string, - queryMetadata?: boolean, } \ No newline at end of file diff --git a/src/contracts/IReturnResult.ts b/src/contracts/IReturnResult.ts index b5f5303..780069d 100644 --- a/src/contracts/IReturnResult.ts +++ b/src/contracts/IReturnResult.ts @@ -1,10 +1,8 @@ import IError from "./IError.js"; import IRedditResult from "./IRedditResult.js"; -import QueryResult from "./QueryResult.js"; export default interface IReturnResult { IsSuccess: boolean; - Query: QueryResult; Result?: IRedditResult; Error?: IError; } \ No newline at end of file diff --git a/src/contracts/QueryResult.ts b/src/contracts/QueryResult.ts deleted file mode 100644 index ee97e30..0000000 --- a/src/contracts/QueryResult.ts +++ /dev/null @@ -1,4 +0,0 @@ -export default interface QueryResult { - subreddit: string, - sortBy: string, -} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 29f8ecf..26195c4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,10 +26,6 @@ export default async function randomBunny(subreddit: string, sortBy: string = 'h if (!result) { return { IsSuccess: false, - Query: { - subreddit: subreddit, - sortBy: sortBy, - }, Error: { Code: ErrorCode.FailedToFetchReddit, Message: ErrorMessages.FailedToFetchReddit, @@ -42,10 +38,6 @@ export default async function randomBunny(subreddit: string, sortBy: string = 'h if (!json) { return { IsSuccess: false, - Query: { - subreddit: subreddit, - sortBy: sortBy, - }, Error: { Code: ErrorCode.UnableToParseJSON, Message: ErrorMessages.UnableToParseJSON, @@ -64,10 +56,6 @@ export default async function randomBunny(subreddit: string, sortBy: string = 'h if (dataWithImages.length == 0) { return { IsSuccess: false, - Query: { - subreddit: subreddit, - sortBy: sortBy, - }, Error: { Code: ErrorCode.NoImageResultsFound, Message: ErrorMessages.NoImageResultsFound, @@ -95,10 +83,6 @@ export default async function randomBunny(subreddit: string, sortBy: string = 'h return { IsSuccess: true, - Query: { - subreddit: subreddit, - sortBy: sortBy, - }, Result: redditResult }; } \ No newline at end of file diff --git a/tests/cli.test.ts b/tests/cli.test.ts index aa68d3b..6d105d3 100644 --- a/tests/cli.test.ts +++ b/tests/cli.test.ts @@ -88,65 +88,7 @@ describe('subreddit', () => { expect(subreddit).toBe('Horses'); }, 5000); -}); - -describe('sort', () => { - test('GIVEN --sort is not supplird, EXPECT sort to be defaulted', async () => { - const result = await cli(['-q'], '.'); - - const sortBy = result.stdout.split('\n') - .find(x => x && x.length > 0 && x.split(' = ')[0] == 'Query.Sort By')! - .split(' = ')[1]; - - expect(sortBy).toBe('hot'); - }, 5000); - - test('GIVEN --sort is supplied WITH a valid input, EXPECT sort to be used', async () => { - const result = await cli(['-q', '--sort', 'new'], '.'); - - const sortBy = result.stdout.split('\n') - .find(x => x && x.length > 0 && x.split(' = ')[0] == 'Query.Sort By')! - .split(' = ')[1]; - - expect(sortBy).toBe('new'); - }, 5000); - - test('GIVEN --sort is supplied WITH an invalid input, EXPECT error', async () => { - const result = await cli(['-q', '--sort', 'invalid'], '.'); - - expect(result.code).toBe(1); - expect(result.stderr).toBe("error: option '--sort ' argument 'invalid' is invalid. Allowed choices are hot, new, top.\n"); - }); -}); - -describe('query-metadata', () => { - test('GIVEN --query-metadata is not supplied, EXPECT no query metadata returned', async () => { - const result = await cli([], '.'); - - const query = result.stdout.split('\n') - .find(x => x && x.length > 0 && x.split(' = ')[0].startsWith('Query')); - - expect(query).toBeUndefined(); - }, 5000); - - test('GIVEN --query-metadata is not supplied, EXPECT no query metadata returned', async () => { - const result = await cli(['--query-metadata'], '.'); - - const query = result.stdout.split('\n') - .find(x => x && x.length > 0 && x.split(' = ')[0].startsWith('Query')); - - expect(query).toBeDefined(); - }, 5000); - - test('GIVEN -q is not supplied, EXPECT no query metadata returned', async () => { - const result = await cli(['-q'], '.'); - - const query = result.stdout.split('\n') - .find(x => x && x.length > 0 && x.split(' = ')[0].startsWith('Query')); - - expect(query).toBeDefined(); - }, 5000); -}); +}) function cli(args: string[], cwd: string): Promise { return new Promise(resolve => {