From 22834691abb6e74d31654ffd2ebeaaaa8ef3ac7b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 9 Apr 2019 11:21:36 +0200 Subject: Add check params account ratings tests --- server/tests/api/check-params/users.ts | 32 ++++++++++++++++++++++++++++++++ server/tests/api/users/users.ts | 32 ++++++++++++++------------------ 2 files changed, 46 insertions(+), 18 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 13be8b460..f3ee99e85 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -538,6 +538,38 @@ describe('Test users API validators', function () { }) }) + describe('When retrieving my global ratings', function () { + const path = '/api/v1/accounts/user1/ratings' + + it('Should fail with a bad start pagination', async function () { + await checkBadStartPagination(server.url, path, userAccessToken) + }) + + it('Should fail with a bad count pagination', async function () { + await checkBadCountPagination(server.url, path, userAccessToken) + }) + + it('Should fail with an incorrect sort', async function () { + await checkBadSortPagination(server.url, path, userAccessToken) + }) + + it('Should fail with a unauthenticated user', async function () { + await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 }) + }) + + it('Should fail with a another user', async function () { + await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 }) + }) + + it('Should fail with a bad type', async function () { + await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 }) + }) + + it('Should succeed with the correct params', async function () { + await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 }) + }) + }) + describe('When blocking/unblocking/removing user', function () { it('Should fail with an incorrect id', async function () { await removeUser(server.url, 'blabla', server.accessToken, 400) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index bc069a7be..6e7de9c38 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -140,31 +140,27 @@ describe('Test users', function () { it('Should retrieve ratings list', async function () { await rateVideo(server.url, accessToken, videoId, 'like') - const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 200) + + const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200) const ratings = res.body + expect(ratings.total).to.equal(1) expect(ratings.data[0].video.id).to.equal(videoId) expect(ratings.data[0].rating).to.equal('like') }) it('Should retrieve ratings list by rating type', async function () { - await rateVideo(server.url, accessToken, videoId, 'like') - let res = await getAccountRatings(server.url, server.user.username, server.accessToken, 200, { rating: 'like' }) - let ratings = res.body - expect(ratings.data.length).to.equal(1) - res = await getAccountRatings(server.url, server.user.username, server.accessToken, 200, { rating: 'dislike' }) - ratings = res.body - expect(ratings.data.length).to.equal(0) - await getAccountRatings(server.url, server.user.username, server.accessToken, 400, { rating: 'invalid' }) - }) - - it('Should not access ratings list if not logged with correct user', async function () { - const user = { username: 'anuragh', password: 'passbyme' } - const resUser = await createUser(server.url, server.accessToken, user.username, user.password) - const userId = resUser.body.user.id - const userAccessToken = await userLogin(server, user) - await getAccountRatings(server.url, server.user.username, userAccessToken, 403) - await removeUser(server.url, userId, server.accessToken) + { + const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') + const ratings = res.body + expect(ratings.data.length).to.equal(1) + } + + { + const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') + const ratings = res.body + expect(ratings.data.length).to.equal(0) + } }) it('Should not be able to remove the video with an incorrect token', async function () { -- cgit v1.2.3