Compare commits
3 commits
c57a288ff0
...
f6409a4960
Author | SHA1 | Date | |
---|---|---|---|
f6409a4960 | |||
5ea8b72e54 | |||
bc4f024619 |
4 changed files with 43 additions and 35 deletions
|
@ -15,7 +15,7 @@ const sortable = [
|
|||
export default async function randomBunny(subreddit: string, sortBy: string = 'hot'): Promise<IReturnResult> {
|
||||
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;
|
||||
})
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
52
yarn.lock
52
yarn.lock
|
@ -75,12 +75,12 @@
|
|||
"@jridgewell/trace-mapping" "^0.3.17"
|
||||
jsesc "^2.5.1"
|
||||
|
||||
"@babel/generator@^7.23.5":
|
||||
version "7.23.5"
|
||||
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.23.5.tgz#17d0a1ea6b62f351d281350a5f80b87a810c4755"
|
||||
integrity sha512-BPssCHrBD+0YrxviOa3QzpqwhNIXKEtOa2jQrm4FlmkC2apYgRnQcmPWiGZDlGxiNtltnUFolMe8497Esry+jA==
|
||||
"@babel/generator@^7.23.6":
|
||||
version "7.23.6"
|
||||
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.23.6.tgz#9e1fca4811c77a10580d17d26b57b036133f3c2e"
|
||||
integrity sha512-qrSfCYxYQB5owCmGLbl8XRpX1ytXlpueOb0N0UmQwA073KZxejgQTzAmJezxvpwQD9uGtK2shHdi55QT+MbjIw==
|
||||
dependencies:
|
||||
"@babel/types" "^7.23.5"
|
||||
"@babel/types" "^7.23.6"
|
||||
"@jridgewell/gen-mapping" "^0.3.2"
|
||||
"@jridgewell/trace-mapping" "^0.3.17"
|
||||
jsesc "^2.5.1"
|
||||
|
@ -191,10 +191,10 @@
|
|||
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.21.8.tgz#642af7d0333eab9c0ad70b14ac5e76dbde7bfdf8"
|
||||
integrity sha512-6zavDGdzG3gUqAdWvlLFfk+36RilI+Pwyuuh7HItyeScCWP3k6i8vKclAQ0bM/0y/Kz/xiwvxhMv9MgTJP5gmA==
|
||||
|
||||
"@babel/parser@^7.22.15", "@babel/parser@^7.23.5":
|
||||
version "7.23.5"
|
||||
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.23.5.tgz#37dee97c4752af148e1d38c34b856b2507660563"
|
||||
integrity sha512-hOOqoiNXrmGdFbhgCzu6GiURxUgM27Xwd/aPuu8RfHEZPBzL1Z54okAHAQjXfcQNwvrlkAmAp4SlRTZ45vlthQ==
|
||||
"@babel/parser@^7.22.15", "@babel/parser@^7.23.6":
|
||||
version "7.23.6"
|
||||
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.23.6.tgz#ba1c9e512bda72a47e285ae42aff9d2a635a9e3b"
|
||||
integrity sha512-Z2uID7YJ7oNvAI20O9X0bblw7Qqs8Q2hFy0R9tAfnfLkp5MW0UH9eUvnDSnFwKZ0AvgS1ucqR4KzvVHgnke1VQ==
|
||||
|
||||
"@babel/parser@^7.23.0":
|
||||
version "7.23.0"
|
||||
|
@ -309,19 +309,19 @@
|
|||
"@babel/types" "^7.22.15"
|
||||
|
||||
"@babel/traverse@^7.23.0", "@babel/traverse@^7.23.2":
|
||||
version "7.23.5"
|
||||
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.23.5.tgz#f546bf9aba9ef2b042c0e00d245990c15508e7ec"
|
||||
integrity sha512-czx7Xy5a6sapWWRx61m1Ke1Ra4vczu1mCTtJam5zRTBOonfdJ+S/B6HYmGYu3fJtr8GGET3si6IhgWVBhJ/m8w==
|
||||
version "7.23.7"
|
||||
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.23.7.tgz#9a7bf285c928cb99b5ead19c3b1ce5b310c9c305"
|
||||
integrity sha512-tY3mM8rH9jM0YHFGyfC0/xf+SB5eKUu7HPj7/k3fpi9dAlsMc5YbQvDi0Sh2QTPXqMhyaAtzAr807TIyfQrmyg==
|
||||
dependencies:
|
||||
"@babel/code-frame" "^7.23.5"
|
||||
"@babel/generator" "^7.23.5"
|
||||
"@babel/generator" "^7.23.6"
|
||||
"@babel/helper-environment-visitor" "^7.22.20"
|
||||
"@babel/helper-function-name" "^7.23.0"
|
||||
"@babel/helper-hoist-variables" "^7.22.5"
|
||||
"@babel/helper-split-export-declaration" "^7.22.6"
|
||||
"@babel/parser" "^7.23.5"
|
||||
"@babel/types" "^7.23.5"
|
||||
debug "^4.1.0"
|
||||
"@babel/parser" "^7.23.6"
|
||||
"@babel/types" "^7.23.6"
|
||||
debug "^4.3.1"
|
||||
globals "^11.1.0"
|
||||
|
||||
"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.3.3":
|
||||
|
@ -333,10 +333,10 @@
|
|||
"@babel/helper-validator-identifier" "^7.19.1"
|
||||
to-fast-properties "^2.0.0"
|
||||
|
||||
"@babel/types@^7.22.15", "@babel/types@^7.22.5", "@babel/types@^7.23.0", "@babel/types@^7.23.5":
|
||||
version "7.23.5"
|
||||
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.23.5.tgz#48d730a00c95109fa4393352705954d74fb5b602"
|
||||
integrity sha512-ON5kSOJwVO6xXVRTvOI0eOnWe7VdUcIpsovGo9U/Br4Ie4UVFQTboO2cYnDhAGU6Fp+UxSiT+pMft0SMHfuq6w==
|
||||
"@babel/types@^7.22.15", "@babel/types@^7.22.5", "@babel/types@^7.23.0", "@babel/types@^7.23.6":
|
||||
version "7.23.6"
|
||||
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.23.6.tgz#be33fdb151e1f5a56877d704492c240fc71c7ccd"
|
||||
integrity sha512-+uarb83brBzPKN38NX1MkB6vb6+mwvR6amUulqAE7ccQw1pEl+bCia9TbdG1lsnFP7lZySvUn37CHyXQdfTwzg==
|
||||
dependencies:
|
||||
"@babel/helper-string-parser" "^7.23.4"
|
||||
"@babel/helper-validator-identifier" "^7.22.20"
|
||||
|
@ -657,7 +657,15 @@
|
|||
"@jridgewell/resolve-uri" "3.1.0"
|
||||
"@jridgewell/sourcemap-codec" "1.4.14"
|
||||
|
||||
"@jridgewell/trace-mapping@^0.3.17", "@jridgewell/trace-mapping@^0.3.18", "@jridgewell/trace-mapping@^0.3.9":
|
||||
"@jridgewell/trace-mapping@^0.3.17", "@jridgewell/trace-mapping@^0.3.9":
|
||||
version "0.3.21"
|
||||
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.21.tgz#5dc1df7b3dc4a6209e503a924e1ca56097a2bb15"
|
||||
integrity sha512-SRfKmRe1KvYnxjEMtxEr+J4HIeMX5YBg/qhRHpxEIGjhX1rshcHlnFUE9K0GazhVKWM7B+nARSkV8LuvJdJ5/g==
|
||||
dependencies:
|
||||
"@jridgewell/resolve-uri" "^3.1.0"
|
||||
"@jridgewell/sourcemap-codec" "^1.4.14"
|
||||
|
||||
"@jridgewell/trace-mapping@^0.3.18":
|
||||
version "0.3.20"
|
||||
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.20.tgz#72e45707cf240fa6b081d0366f8265b0cd10197f"
|
||||
integrity sha512-R8LcPeWZol2zR8mmH3JeKQ6QRCFb7XgUhV9ZlGhHLGyg4wpPiPZNQOOWhFZhxKw8u//yTbNGI42Bx/3paXEQ+Q==
|
||||
|
@ -1680,7 +1688,7 @@ date-fns@^1.27.2:
|
|||
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c"
|
||||
integrity sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==
|
||||
|
||||
debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.4:
|
||||
debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4:
|
||||
version "4.3.4"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
|
||||
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
|
||||
|
|
Loading…
Reference in a new issue