Compare commits
3 commits
4277c6e0a5
...
9d37bf6339
Author | SHA1 | Date | |
---|---|---|---|
9d37bf6339 | |||
5ea8b72e54 | |||
bc4f024619 |
3 changed files with 13 additions and 13 deletions
|
@ -15,7 +15,7 @@ const sortable = [
|
||||||
export default async function randomBunny(subreddit: string, sortBy: string = 'hot'): Promise<IReturnResult> {
|
export default async function randomBunny(subreddit: string, sortBy: string = 'hot'): Promise<IReturnResult> {
|
||||||
if (!sortable.includes(sortBy)) sortBy = 'hot';
|
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) => {
|
.then((res) => {
|
||||||
return res;
|
return res;
|
||||||
})
|
})
|
||||||
|
|
|
@ -70,28 +70,28 @@ describe('subreddit', () => {
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
test('GIVEN -s is supplied, EXPECT subreddit to be changed', async () => {
|
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')
|
const subreddit = result.stdout.split('\n')
|
||||||
.find(x => x && x.length > 0 && x.split(' = ')[0] == 'Subreddit')!
|
.find(x => x && x.length > 0 && x.split(' = ')[0] == 'Subreddit')!
|
||||||
.split(' = ')[1];
|
.split(' = ')[1];
|
||||||
|
|
||||||
expect(subreddit).toBe('Horses');
|
expect(subreddit).toBe('pics');
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
test('GIVEN --subreddit is supplied, EXPECT subreddit to be changed', async () => {
|
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')
|
const subreddit = result.stdout.split('\n')
|
||||||
.find(x => x && x.length > 0 && x.split(' = ')[0] == 'Subreddit')!
|
.find(x => x && x.length > 0 && x.split(' = ')[0] == 'Subreddit')!
|
||||||
.split(' = ')[1];
|
.split(' = ')[1];
|
||||||
|
|
||||||
expect(subreddit).toBe('Horses');
|
expect(subreddit).toBe('pics');
|
||||||
}, 5000);
|
}, 5000);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('sort', () => {
|
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 result = await cli(['-q'], '.');
|
||||||
|
|
||||||
const sortBy = result.stdout.split('\n')
|
const sortBy = result.stdout.split('\n')
|
||||||
|
|
|
@ -36,7 +36,7 @@ describe('randomBunny', () => {
|
||||||
expect(result.Result).toBeDefined();
|
expect(result.Result).toBeDefined();
|
||||||
expect(result.Error).toBeUndefined();
|
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 () => {
|
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.Result).toBeDefined();
|
||||||
expect(result.Error).toBeUndefined();
|
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 () => {
|
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.Result).toBeDefined();
|
||||||
expect(result.Error).toBeUndefined();
|
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 () => {
|
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!.Code).toBe(ErrorCode.FailedToFetchReddit);
|
||||||
expect(result.Error!.Message).toBe(ErrorMessages.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 () => {
|
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!.Code).toBe(ErrorCode.UnableToParseJSON);
|
||||||
expect(result.Error!.Message).toBe(ErrorMessages.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 () => {
|
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!.Code).toBe(ErrorCode.NoImageResultsFound);
|
||||||
expect(result.Error!.Message).toBe(ErrorMessages.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 () => {
|
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!.Code).toBe(ErrorCode.NoImageResultsFound);
|
||||||
expect(result.Error!.Message).toBe(ErrorMessages.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');
|
||||||
});
|
});
|
||||||
});
|
});
|
Loading…
Reference in a new issue