Compare commits
1 commit
0c863c0268
...
9bb8b6c23c
Author | SHA1 | Date | |
---|---|---|---|
9bb8b6c23c |
5 changed files with 317 additions and 487 deletions
|
@ -43,13 +43,13 @@
|
|||
"eslint": "^8.49.0",
|
||||
"jest": "^29.7.0",
|
||||
"jest-mock-extended": "^3.0.3",
|
||||
"np": "^9.0.0",
|
||||
"np": "^8.0.0",
|
||||
"ts-jest": "^29.1.1",
|
||||
"ts-mockito": "^2.6.1",
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"resolutions": {
|
||||
"np/**/got": "^14.0.0",
|
||||
"np/**/got": "^13.0.0",
|
||||
"**/semver": "^7.5.2",
|
||||
"@babel/traverse": "^7.23.2"
|
||||
},
|
||||
|
|
|
@ -10,7 +10,6 @@ program
|
|||
.description('Get a random image url from a subreddit of your choosing')
|
||||
.version('2.2')
|
||||
.option('-s, --subreddit <subreddit>', 'The subreddit to search', 'rabbits')
|
||||
.option('-j, --json', 'Output as JSON')
|
||||
.option('-q, --query-metadata', 'Include query metadata in result')
|
||||
.addOption(new Option('--sort <sort>', 'Sort by').default('hot').choices(['hot', 'new', 'top']));
|
||||
|
||||
|
@ -24,12 +23,6 @@ randomBunny(options.subreddit, options.sort)
|
|||
const result = response.Result!;
|
||||
|
||||
const outputLines: string[] = [];
|
||||
|
||||
if (options.json) {
|
||||
console.log(JSON.stringify(result));
|
||||
return;
|
||||
}
|
||||
|
||||
outputLines.push(`Archived = ${result.Archived}`);
|
||||
outputLines.push(`Downvotes = ${result.Downs}`);
|
||||
outputLines.push(`Hidden = ${result.Hidden}`);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
export default interface ICliOptions {
|
||||
subreddit: string,
|
||||
json?: boolean,
|
||||
sort: string,
|
||||
queryMetadata?: boolean,
|
||||
}
|
|
@ -90,24 +90,6 @@ describe('subreddit', () => {
|
|||
}, 5000);
|
||||
});
|
||||
|
||||
describe('json', () => {
|
||||
test('GIVEN -j is supplied, EXPECT output to be valid JSON', async () => {
|
||||
const result = await cli(['-j'], '.');
|
||||
|
||||
const json = JSON.parse(result.stdout);
|
||||
|
||||
expect(json).toBeDefined();
|
||||
}, 5000);
|
||||
|
||||
test('GIVEN --json is supplied, EXPECT output to be valid JSON', async () => {
|
||||
const result = await cli(['--json'], '.');
|
||||
|
||||
const json = JSON.parse(result.stdout);
|
||||
|
||||
expect(json).toBeDefined();
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
describe('sort', () => {
|
||||
test('GIVEN --sort is not supplied, EXPECT sort to be defaulted', async () => {
|
||||
const result = await cli(['-q'], '.');
|
||||
|
@ -134,7 +116,7 @@ describe('sort', () => {
|
|||
|
||||
expect(result.code).toBe(1);
|
||||
expect(result.stderr).toBe("error: option '--sort <sort>' argument 'invalid' is invalid. Allowed choices are hot, new, top.\n");
|
||||
}, 5000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('query-metadata', () => {
|
||||
|
|
Loading…
Reference in a new issue