Compare commits

..

1 commit

Author SHA1 Message Date
9bb8b6c23c Update dependency @types/node to v20.11.0
All checks were successful
continuous-integration/drone/push Build is passing
2024-01-15 00:02:25 +00:00
5 changed files with 317 additions and 487 deletions

View file

@ -43,13 +43,13 @@
"eslint": "^8.49.0", "eslint": "^8.49.0",
"jest": "^29.7.0", "jest": "^29.7.0",
"jest-mock-extended": "^3.0.3", "jest-mock-extended": "^3.0.3",
"np": "^9.0.0", "np": "^8.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"
}, },
"resolutions": { "resolutions": {
"np/**/got": "^14.0.0", "np/**/got": "^13.0.0",
"**/semver": "^7.5.2", "**/semver": "^7.5.2",
"@babel/traverse": "^7.23.2" "@babel/traverse": "^7.23.2"
}, },

View file

@ -10,7 +10,6 @@ program
.description('Get a random image url from a subreddit of your choosing') .description('Get a random image url from a subreddit of your choosing')
.version('2.2') .version('2.2')
.option('-s, --subreddit <subreddit>', 'The subreddit to search', 'rabbits') .option('-s, --subreddit <subreddit>', 'The subreddit to search', 'rabbits')
.option('-j, --json', 'Output as JSON')
.option('-q, --query-metadata', 'Include query metadata in result') .option('-q, --query-metadata', 'Include query metadata in result')
.addOption(new Option('--sort <sort>', 'Sort by').default('hot').choices(['hot', 'new', 'top'])); .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 result = response.Result!;
const outputLines: string[] = []; const outputLines: string[] = [];
if (options.json) {
console.log(JSON.stringify(result));
return;
}
outputLines.push(`Archived = ${result.Archived}`); outputLines.push(`Archived = ${result.Archived}`);
outputLines.push(`Downvotes = ${result.Downs}`); outputLines.push(`Downvotes = ${result.Downs}`);
outputLines.push(`Hidden = ${result.Hidden}`); outputLines.push(`Hidden = ${result.Hidden}`);

View file

@ -1,6 +1,5 @@
export default interface ICliOptions { export default interface ICliOptions {
subreddit: string, subreddit: string,
json?: boolean,
sort: string, sort: string,
queryMetadata?: boolean, queryMetadata?: boolean,
} }

View file

@ -90,24 +90,6 @@ describe('subreddit', () => {
}, 5000); }, 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', () => { describe('sort', () => {
test('GIVEN --sort is not supplied, EXPECT sort to be defaulted', async () => { test('GIVEN --sort is not supplied, EXPECT sort to be defaulted', async () => {
const result = await cli(['-q'], '.'); const result = await cli(['-q'], '.');
@ -134,7 +116,7 @@ describe('sort', () => {
expect(result.code).toBe(1); expect(result.code).toBe(1);
expect(result.stderr).toBe("error: option '--sort <sort>' argument 'invalid' is invalid. Allowed choices are hot, new, top.\n"); expect(result.stderr).toBe("error: option '--sort <sort>' argument 'invalid' is invalid. Allowed choices are hot, new, top.\n");
}, 5000); });
}); });
describe('query-metadata', () => { describe('query-metadata', () => {

772
yarn.lock

File diff suppressed because it is too large Load diff