From 298a6a743cb630a586ee6b7d22066c152dd35e06 Mon Sep 17 00:00:00 2001 From: Keith Holliday Date: Fri, 23 Mar 2018 14:13:08 -0500 Subject: [PATCH] Added paging (#10150) * Added paging * Escaped regex * Fixed challenge side effect tests --- .../challenges/GET-challenges_user.test.js | 49 +++++++++++++++++++ .../components/challenges/findChallenges.vue | 48 ++++++++++++++---- .../client/components/challenges/sidebar.vue | 2 +- website/client/store/actions/challenges.js | 21 +++++++- .../server/controllers/api-v3/challenges.js | 43 ++++++++++++++-- 5 files changed, 145 insertions(+), 18 deletions(-) diff --git a/test/api/v3/integration/challenges/GET-challenges_user.test.js b/test/api/v3/integration/challenges/GET-challenges_user.test.js index 946a703851..b1369c3aef 100644 --- a/test/api/v3/integration/challenges/GET-challenges_user.test.js +++ b/test/api/v3/integration/challenges/GET-challenges_user.test.js @@ -227,4 +227,53 @@ describe('GET challenges/user', () => { expect(foundChallengeIndex).to.eql(1); }); }); + + context('filters and paging', () => { + let user, guild, member; + const categories = [{ + slug: 'newCat', + name: 'New Category', + }]; + + before(async () => { + let { group, groupLeader, members } = await createAndPopulateGroup({ + groupDetails: { + name: 'TestGuild', + type: 'guild', + privacy: 'public', + }, + members: 1, + }); + + user = groupLeader; + guild = group; + member = members[0]; + + for (let i = 0; i < 11; i += 1) { + await generateChallenge(user, group); // eslint-disable-line + } + }); + + it('returns public guilds filtered by category', async () => { + const categoryChallenge = await generateChallenge(user, guild, {categories}); + const challenges = await user.get(`/challenges/user?categories=${categories[0].slug}`); + + expect(challenges[0]._id).to.eql(categoryChallenge._id); + expect(challenges.length).to.eql(1); + }); + + it('paginates challenges', async () => { + const challenges = await user.get('/challenges/user'); + const challengesPaged = await user.get('/challenges/user?page=1&owned=owned'); + + expect(challenges.length).to.eql(10); + expect(challengesPaged.length).to.eql(2); + }); + + it('filters by owned', async () => { + const challenges = await member.get('/challenges/user?owned=owned'); + + expect(challenges.length).to.eql(0); + }); + }); }); diff --git a/website/client/components/challenges/findChallenges.vue b/website/client/components/challenges/findChallenges.vue index 2372e360eb..8bfe6c6e1b 100644 --- a/website/client/components/challenges/findChallenges.vue +++ b/website/client/components/challenges/findChallenges.vue @@ -17,6 +17,9 @@ .row .col-12.col-md-6(v-for='challenge in filteredChallenges', v-if='!memberOf(challenge)') challenge-item(:challenge='challenge') + .row + .col-12.text-center + button.btn.btn-secondary(@click='loadMore()') {{ $t('loadMore') }}