diff --git a/src/index.ts b/src/index.ts index 29f8ecf..3d7277b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,7 @@ const sortable = [ export default async function randomBunny(subreddit: string, sortBy: string = 'hot'): Promise { if (!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?limit=100`) .then((res) => { return res; }) diff --git a/tests/cli.test.ts b/tests/cli.test.ts index aa68d3b..1b04e47 100644 --- a/tests/cli.test.ts +++ b/tests/cli.test.ts @@ -70,28 +70,28 @@ describe('subreddit', () => { }, 5000); test('GIVEN -s is supplied, EXPECT subreddit to be changed', async () => { - const result = await cli(['-s', 'horses'], '.'); + const result = await cli(['-s', 'pics'], '.'); const subreddit = result.stdout.split('\n') .find(x => x && x.length > 0 && x.split(' = ')[0] == 'Subreddit')! .split(' = ')[1]; - expect(subreddit).toBe('Horses'); + expect(subreddit).toBe('pics'); }, 5000); test('GIVEN --subreddit is supplied, EXPECT subreddit to be changed', async () => { - const result = await cli(['--subreddit', 'horses'], '.'); + const result = await cli(['--subreddit', 'pics'], '.'); const subreddit = result.stdout.split('\n') .find(x => x && x.length > 0 && x.split(' = ')[0] == 'Subreddit')! .split(' = ')[1]; - expect(subreddit).toBe('Horses'); + expect(subreddit).toBe('pics'); }, 5000); }); describe('sort', () => { - test('GIVEN --sort is not supplird, EXPECT sort to be defaulted', async () => { + test('GIVEN --sort is not supplied, EXPECT sort to be defaulted', async () => { const result = await cli(['-q'], '.'); const sortBy = result.stdout.split('\n') diff --git a/tests/index.test.ts b/tests/index.test.ts index 302fd1d..37ab315 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -36,7 +36,7 @@ describe('randomBunny', () => { expect(result.Result).toBeDefined(); expect(result.Error).toBeUndefined(); - expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json'); + expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json?limit=100'); }); test('GIVEN sortBy is NOT supplied, expect it to default to hot', async () => { @@ -68,7 +68,7 @@ describe('randomBunny', () => { expect(result.Result).toBeDefined(); expect(result.Error).toBeUndefined(); - expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/hot.json'); + expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/hot.json?limit=100'); }); test('GIVEN sortBy is NOT valid, expect it to default to hot', async () => { @@ -100,7 +100,7 @@ describe('randomBunny', () => { expect(result.Result).toBeDefined(); expect(result.Error).toBeUndefined(); - expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/hot.json'); + expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/hot.json?limit=100'); }); test('GIVEN the fetch fails, EXPECT failure result', async () => { @@ -115,7 +115,7 @@ describe('randomBunny', () => { expect(result.Error!.Code).toBe(ErrorCode.FailedToFetchReddit); expect(result.Error!.Message).toBe(ErrorMessages.FailedToFetchReddit); - expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json'); + expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json?limit=100'); }); test('GIVEN the result is NOT valid JSON, EXPECT failure result', async () => { @@ -132,7 +132,7 @@ describe('randomBunny', () => { expect(result.Error!.Code).toBe(ErrorCode.UnableToParseJSON); expect(result.Error!.Message).toBe(ErrorMessages.UnableToParseJSON); - expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json'); + expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json?limit=100'); }); test('GIVEN randomSelect does NOT find a response, EXPECT failure result', async () => { @@ -153,7 +153,7 @@ describe('randomBunny', () => { expect(result.Error!.Code).toBe(ErrorCode.NoImageResultsFound); expect(result.Error!.Message).toBe(ErrorMessages.NoImageResultsFound); - expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json'); + expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json?limit=100'); }); test('GIVEN randomSelect does NOT find a valid response, EXPECT failure result', async () => { @@ -188,6 +188,6 @@ describe('randomBunny', () => { expect(result.Error!.Code).toBe(ErrorCode.NoImageResultsFound); expect(result.Error!.Message).toBe(ErrorMessages.NoImageResultsFound); - expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json'); + expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json?limit=100'); }); }); \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 46c61c8..32dee6e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4681,9 +4681,9 @@ types-pkg-json@^1.1.0: types-json "^1.2.2" typescript@^5.0.0: - version "5.2.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.2.2.tgz#5ebb5e5a5b75f085f22bc3f8460fba308310fa78" - integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w== + version "5.3.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37" + integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw== undici-types@~5.26.4: version "5.26.5"