Compare commits

...

3 commits

Author SHA1 Message Date
RenovateBot d5692bd537 Update dependency typescript to v5.3.3
All checks were successful
continuous-integration/drone/push Build is passing
2024-01-15 00:03:05 +00:00
Ethan Lane 5ea8b72e54 Add higher limit on json (#139)
All checks were successful
continuous-integration/drone/push Build is passing
# Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

- Add higher limit on the json result
    - This will fix the tests not always fetching an image from r/rabbits, as not every post in the top is a single image

#125

## Type of change

Please delete options that are not relevant.

- [x] Bug fix (non-breaking change which fixes an issue)

# How Has This Been Tested?

Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration.

# Checklist

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that provde my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules

Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/random-bunny/pulls/139
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2024-01-12 17:48:37 +00:00
Ethan Lane bc4f024619 Fix tests (#136)
Some checks failed
continuous-integration/drone/push Build is failing
# Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

#125

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

# How Has This Been Tested?

Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration.

# Checklist

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that provde my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules

Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/random-bunny/pulls/136
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2024-01-09 19:00:52 +00:00
4 changed files with 16 additions and 16 deletions

View file

@ -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;
}) })

View file

@ -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')

View file

@ -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');
}); });
}); });

View file

@ -4681,9 +4681,9 @@ types-pkg-json@^1.1.0:
types-json "^1.2.2" types-json "^1.2.2"
typescript@^5.0.0: typescript@^5.0.0:
version "5.2.2" version "5.3.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.2.2.tgz#5ebb5e5a5b75f085f22bc3f8460fba308310fa78" resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"
integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w== integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==
undici-types@~5.26.4: undici-types@~5.26.4:
version "5.26.5" version "5.26.5"