Compare commits
3 commits
269e62cdee
...
b0f3c67bf1
Author | SHA1 | Date | |
---|---|---|---|
b0f3c67bf1 | |||
5ea8b72e54 | |||
bc4f024619 |
4 changed files with 65 additions and 64 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');
|
||||
});
|
||||
});
|
103
yarn.lock
103
yarn.lock
|
@ -904,15 +904,15 @@
|
|||
"@types/yargs-parser" "*"
|
||||
|
||||
"@typescript-eslint/eslint-plugin@^6.0.0":
|
||||
version "6.13.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.13.1.tgz#f98bd887bf95551203c917e734d113bf8d527a0c"
|
||||
integrity sha512-5bQDGkXaxD46bPvQt08BUz9YSaO4S0fB1LB5JHQuXTfkGPI3+UUeS387C/e9jRie5GqT8u5kFTrMvAjtX4O5kA==
|
||||
version "6.18.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.18.1.tgz#0df881a47da1c1a9774f39495f5f7052f86b72e0"
|
||||
integrity sha512-nISDRYnnIpk7VCFrGcu1rnZfM1Dh9LRHnfgdkjcbi/l7g16VYRri3TjXi9Ir4lOZSw5N/gnV/3H7jIPQ8Q4daA==
|
||||
dependencies:
|
||||
"@eslint-community/regexpp" "^4.5.1"
|
||||
"@typescript-eslint/scope-manager" "6.13.1"
|
||||
"@typescript-eslint/type-utils" "6.13.1"
|
||||
"@typescript-eslint/utils" "6.13.1"
|
||||
"@typescript-eslint/visitor-keys" "6.13.1"
|
||||
"@typescript-eslint/scope-manager" "6.18.1"
|
||||
"@typescript-eslint/type-utils" "6.18.1"
|
||||
"@typescript-eslint/utils" "6.18.1"
|
||||
"@typescript-eslint/visitor-keys" "6.18.1"
|
||||
debug "^4.3.4"
|
||||
graphemer "^1.4.0"
|
||||
ignore "^5.2.4"
|
||||
|
@ -938,21 +938,21 @@
|
|||
"@typescript-eslint/types" "5.62.0"
|
||||
"@typescript-eslint/visitor-keys" "5.62.0"
|
||||
|
||||
"@typescript-eslint/scope-manager@6.13.1":
|
||||
version "6.13.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.13.1.tgz#58c7c37c6a957d3d9f59bc4f64c2888e0cac1d70"
|
||||
integrity sha512-BW0kJ7ceiKi56GbT2KKzZzN+nDxzQK2DS6x0PiSMPjciPgd/JRQGMibyaN2cPt2cAvuoH0oNvn2fwonHI+4QUQ==
|
||||
"@typescript-eslint/scope-manager@6.18.1":
|
||||
version "6.18.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.18.1.tgz#28c31c60f6e5827996aa3560a538693cb4bd3848"
|
||||
integrity sha512-BgdBwXPFmZzaZUuw6wKiHKIovms97a7eTImjkXCZE04TGHysG+0hDQPmygyvgtkoB/aOQwSM/nWv3LzrOIQOBw==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "6.13.1"
|
||||
"@typescript-eslint/visitor-keys" "6.13.1"
|
||||
"@typescript-eslint/types" "6.18.1"
|
||||
"@typescript-eslint/visitor-keys" "6.18.1"
|
||||
|
||||
"@typescript-eslint/type-utils@6.13.1":
|
||||
version "6.13.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-6.13.1.tgz#e6e5885e387841cae9c38fc0638fd8b7561973d6"
|
||||
integrity sha512-A2qPlgpxx2v//3meMqQyB1qqTg1h1dJvzca7TugM3Yc2USDY+fsRBiojAEo92HO7f5hW5mjAUF6qobOPzlBCBQ==
|
||||
"@typescript-eslint/type-utils@6.18.1":
|
||||
version "6.18.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-6.18.1.tgz#115cf535f8b39db8301677199ce51151e2daee96"
|
||||
integrity sha512-wyOSKhuzHeU/5pcRDP2G2Ndci+4g653V43gXTpt4nbyoIOAASkGDA9JIAgbQCdCkcr1MvpSYWzxTz0olCn8+/Q==
|
||||
dependencies:
|
||||
"@typescript-eslint/typescript-estree" "6.13.1"
|
||||
"@typescript-eslint/utils" "6.13.1"
|
||||
"@typescript-eslint/typescript-estree" "6.18.1"
|
||||
"@typescript-eslint/utils" "6.18.1"
|
||||
debug "^4.3.4"
|
||||
ts-api-utils "^1.0.1"
|
||||
|
||||
|
@ -961,10 +961,10 @@
|
|||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.62.0.tgz#258607e60effa309f067608931c3df6fed41fd2f"
|
||||
integrity sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ==
|
||||
|
||||
"@typescript-eslint/types@6.13.1":
|
||||
version "6.13.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.13.1.tgz#b56f26130e7eb8fa1e429c75fb969cae6ad7bb5c"
|
||||
integrity sha512-gjeEskSmiEKKFIbnhDXUyiqVma1gRCQNbVZ1C8q7Zjcxh3WZMbzWVfGE9rHfWd1msQtPS0BVD9Jz9jded44eKg==
|
||||
"@typescript-eslint/types@6.18.1":
|
||||
version "6.18.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.18.1.tgz#91617d8080bcd99ac355d9157079970d1d49fefc"
|
||||
integrity sha512-4TuMAe+tc5oA7wwfqMtB0Y5OrREPF1GeJBAjqwgZh1lEMH5PJQgWgHGfYufVB51LtjD+peZylmeyxUXPfENLCw==
|
||||
|
||||
"@typescript-eslint/typescript-estree@5.62.0":
|
||||
version "5.62.0"
|
||||
|
@ -979,30 +979,31 @@
|
|||
semver "^7.3.7"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/typescript-estree@6.13.1":
|
||||
version "6.13.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.13.1.tgz#d01dda78d2487434d1c503853fa00291c566efa4"
|
||||
integrity sha512-sBLQsvOC0Q7LGcUHO5qpG1HxRgePbT6wwqOiGLpR8uOJvPJbfs0mW3jPA3ujsDvfiVwVlWUDESNXv44KtINkUQ==
|
||||
"@typescript-eslint/typescript-estree@6.18.1":
|
||||
version "6.18.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.18.1.tgz#a12b6440175b4cbc9d09ab3c4966c6b245215ab4"
|
||||
integrity sha512-fv9B94UAhywPRhUeeV/v+3SBDvcPiLxRZJw/xZeeGgRLQZ6rLMG+8krrJUyIf6s1ecWTzlsbp0rlw7n9sjufHA==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "6.13.1"
|
||||
"@typescript-eslint/visitor-keys" "6.13.1"
|
||||
"@typescript-eslint/types" "6.18.1"
|
||||
"@typescript-eslint/visitor-keys" "6.18.1"
|
||||
debug "^4.3.4"
|
||||
globby "^11.1.0"
|
||||
is-glob "^4.0.3"
|
||||
minimatch "9.0.3"
|
||||
semver "^7.5.4"
|
||||
ts-api-utils "^1.0.1"
|
||||
|
||||
"@typescript-eslint/utils@6.13.1":
|
||||
version "6.13.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-6.13.1.tgz#925b3a2453a71ada914ae329b7bb7e7d96634b2f"
|
||||
integrity sha512-ouPn/zVoan92JgAegesTXDB/oUp6BP1v8WpfYcqh649ejNc9Qv+B4FF2Ff626kO1xg0wWwwG48lAJ4JuesgdOw==
|
||||
"@typescript-eslint/utils@6.18.1":
|
||||
version "6.18.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-6.18.1.tgz#3451cfe2e56babb6ac657e10b6703393d4b82955"
|
||||
integrity sha512-zZmTuVZvD1wpoceHvoQpOiewmWu3uP9FuTWo8vqpy2ffsmfCE8mklRPi+vmnIYAIk9t/4kOThri2QCDgor+OpQ==
|
||||
dependencies:
|
||||
"@eslint-community/eslint-utils" "^4.4.0"
|
||||
"@types/json-schema" "^7.0.12"
|
||||
"@types/semver" "^7.5.0"
|
||||
"@typescript-eslint/scope-manager" "6.13.1"
|
||||
"@typescript-eslint/types" "6.13.1"
|
||||
"@typescript-eslint/typescript-estree" "6.13.1"
|
||||
"@typescript-eslint/scope-manager" "6.18.1"
|
||||
"@typescript-eslint/types" "6.18.1"
|
||||
"@typescript-eslint/typescript-estree" "6.18.1"
|
||||
semver "^7.5.4"
|
||||
|
||||
"@typescript-eslint/visitor-keys@5.62.0":
|
||||
|
@ -1013,12 +1014,12 @@
|
|||
"@typescript-eslint/types" "5.62.0"
|
||||
eslint-visitor-keys "^3.3.0"
|
||||
|
||||
"@typescript-eslint/visitor-keys@6.13.1":
|
||||
version "6.13.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.13.1.tgz#c4b692dcc23a4fc60685b718f10fde789d65a540"
|
||||
integrity sha512-NDhQUy2tg6XGNBGDRm1XybOHSia8mcXmlbKWoQP+nm1BIIMxa55shyJfZkHpEBN62KNPLrocSM2PdPcaLgDKMQ==
|
||||
"@typescript-eslint/visitor-keys@6.18.1":
|
||||
version "6.18.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.18.1.tgz#704d789bda2565a15475e7d22f145b8fe77443f4"
|
||||
integrity sha512-/kvt0C5lRqGoCfsbmm7/CwMqoSkY3zzHLIjdhHZQW3VFrnz7ATecOHR7nb7V+xn4286MBxfnQfQhAmCI0u+bJA==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "6.13.1"
|
||||
"@typescript-eslint/types" "6.18.1"
|
||||
eslint-visitor-keys "^3.4.1"
|
||||
|
||||
"@ungap/structured-clone@^1.2.0":
|
||||
|
@ -2068,9 +2069,9 @@ fast-levenshtein@^2.0.6:
|
|||
integrity sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==
|
||||
|
||||
fastq@^1.6.0:
|
||||
version "1.15.0"
|
||||
resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.15.0.tgz#d04d07c6a2a68fe4599fea8d2e103a937fae6b3a"
|
||||
integrity sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==
|
||||
version "1.16.0"
|
||||
resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.16.0.tgz#83b9a9375692db77a822df081edb6a9cf6839320"
|
||||
integrity sha512-ifCoaXsDrsdkWTtiNJX5uzHDsrck5TzfKKDcuFFTIrrc/BS076qgEIfoIy1VeZqViznfKiysPYTh/QeHtnIsYA==
|
||||
dependencies:
|
||||
reusify "^1.0.4"
|
||||
|
||||
|
@ -3520,6 +3521,13 @@ mimic-response@^4.0.0:
|
|||
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-4.0.0.tgz#35468b19e7c75d10f5165ea25e75a5ceea7cf70f"
|
||||
integrity sha512-e5ISH9xMYU0DzrT+jl8q2ze9D6eWBto+I8CNpe+VI+K2J/F/k3PdkdTdz4wvGVH4NTpo+NRYTVIuMQEMMcsLqg==
|
||||
|
||||
minimatch@9.0.3, minimatch@^9.0.0:
|
||||
version "9.0.3"
|
||||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.3.tgz#a6e00c3de44c3a542bfaae70abfc22420a6da825"
|
||||
integrity sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==
|
||||
dependencies:
|
||||
brace-expansion "^2.0.1"
|
||||
|
||||
minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2:
|
||||
version "3.1.2"
|
||||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
|
||||
|
@ -3527,13 +3535,6 @@ minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2:
|
|||
dependencies:
|
||||
brace-expansion "^1.1.7"
|
||||
|
||||
minimatch@^9.0.0:
|
||||
version "9.0.3"
|
||||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.3.tgz#a6e00c3de44c3a542bfaae70abfc22420a6da825"
|
||||
integrity sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==
|
||||
dependencies:
|
||||
brace-expansion "^2.0.1"
|
||||
|
||||
minimist@^1.2.0:
|
||||
version "1.2.8"
|
||||
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
|
||||
|
|
Loading…
Reference in a new issue