diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/accounts.ts | 10 | ||||
-rw-r--r-- | server/middlewares/validators/users.ts | 1 | ||||
-rw-r--r-- | server/middlewares/validators/videos/video-rates.ts | 2 | ||||
-rw-r--r-- | server/tests/api/check-params/users.ts | 32 | ||||
-rw-r--r-- | server/tests/api/users/users.ts | 32 |
5 files changed, 52 insertions, 25 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index aa01ea1eb..8d4db1e75 100644 --- a/server/controllers/api/accounts.ts +++ b/server/controllers/api/accounts.ts | |||
@@ -1,22 +1,22 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { getFormattedObjects, getServerActor } from '../../helpers/utils' | 2 | import { getFormattedObjects, getServerActor } from '../../helpers/utils' |
3 | import { | 3 | import { |
4 | authenticate, | ||
5 | asyncMiddleware, | 4 | asyncMiddleware, |
5 | authenticate, | ||
6 | commonVideosFiltersValidator, | 6 | commonVideosFiltersValidator, |
7 | videoRatingValidator, | ||
8 | optionalAuthenticate, | 7 | optionalAuthenticate, |
9 | paginationValidator, | 8 | paginationValidator, |
10 | setDefaultPagination, | 9 | setDefaultPagination, |
11 | setDefaultSort, | 10 | setDefaultSort, |
12 | videoPlaylistsSortValidator, | 11 | videoPlaylistsSortValidator, |
13 | videoRatesSortValidator | 12 | videoRatesSortValidator, |
13 | videoRatingValidator | ||
14 | } from '../../middlewares' | 14 | } from '../../middlewares' |
15 | import { | 15 | import { |
16 | accountNameWithHostGetValidator, | 16 | accountNameWithHostGetValidator, |
17 | accountsSortValidator, | 17 | accountsSortValidator, |
18 | videosSortValidator, | 18 | ensureAuthUserOwnsAccountValidator, |
19 | ensureAuthUserOwnsAccountValidator | 19 | videosSortValidator |
20 | } from '../../middlewares/validators' | 20 | } from '../../middlewares/validators' |
21 | import { AccountModel } from '../../models/account/account' | 21 | import { AccountModel } from '../../models/account/account' |
22 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' | 22 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' |
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 35f41c450..eceded1c4 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -22,7 +22,6 @@ import { logger } from '../../helpers/logger' | |||
22 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' | 22 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' |
23 | import { Redis } from '../../lib/redis' | 23 | import { Redis } from '../../lib/redis' |
24 | import { UserModel } from '../../models/account/user' | 24 | import { UserModel } from '../../models/account/user' |
25 | import { AccountModel } from '../../models/account/account' | ||
26 | import { areValidationErrors } from './utils' | 25 | import { areValidationErrors } from './utils' |
27 | import { ActorModel } from '../../models/activitypub/actor' | 26 | import { ActorModel } from '../../models/activitypub/actor' |
28 | 27 | ||
diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts index e79d80e97..204b4a78d 100644 --- a/server/middlewares/validators/videos/video-rates.ts +++ b/server/middlewares/validators/videos/video-rates.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body, param, query } from 'express-validator/check' | 3 | import { body, param, query } from 'express-validator/check' |
4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' |
5 | import { isRatingValid } from '../../../helpers/custom-validators/video-rates' | 5 | import { isRatingValid } from '../../../helpers/custom-validators/video-rates' |
6 | import { doesVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' | 6 | import { doesVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' |
7 | import { logger } from '../../../helpers/logger' | 7 | import { logger } from '../../../helpers/logger' |
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 () { | |||
538 | }) | 538 | }) |
539 | }) | 539 | }) |
540 | 540 | ||
541 | describe('When retrieving my global ratings', function () { | ||
542 | const path = '/api/v1/accounts/user1/ratings' | ||
543 | |||
544 | it('Should fail with a bad start pagination', async function () { | ||
545 | await checkBadStartPagination(server.url, path, userAccessToken) | ||
546 | }) | ||
547 | |||
548 | it('Should fail with a bad count pagination', async function () { | ||
549 | await checkBadCountPagination(server.url, path, userAccessToken) | ||
550 | }) | ||
551 | |||
552 | it('Should fail with an incorrect sort', async function () { | ||
553 | await checkBadSortPagination(server.url, path, userAccessToken) | ||
554 | }) | ||
555 | |||
556 | it('Should fail with a unauthenticated user', async function () { | ||
557 | await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 }) | ||
558 | }) | ||
559 | |||
560 | it('Should fail with a another user', async function () { | ||
561 | await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 }) | ||
562 | }) | ||
563 | |||
564 | it('Should fail with a bad type', async function () { | ||
565 | await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 }) | ||
566 | }) | ||
567 | |||
568 | it('Should succeed with the correct params', async function () { | ||
569 | await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 }) | ||
570 | }) | ||
571 | }) | ||
572 | |||
541 | describe('When blocking/unblocking/removing user', function () { | 573 | describe('When blocking/unblocking/removing user', function () { |
542 | it('Should fail with an incorrect id', async function () { | 574 | it('Should fail with an incorrect id', async function () { |
543 | await removeUser(server.url, 'blabla', server.accessToken, 400) | 575 | 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 () { | |||
140 | 140 | ||
141 | it('Should retrieve ratings list', async function () { | 141 | it('Should retrieve ratings list', async function () { |
142 | await rateVideo(server.url, accessToken, videoId, 'like') | 142 | await rateVideo(server.url, accessToken, videoId, 'like') |
143 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 200) | 143 | |
144 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200) | ||
144 | const ratings = res.body | 145 | const ratings = res.body |
145 | 146 | ||
147 | expect(ratings.total).to.equal(1) | ||
146 | expect(ratings.data[0].video.id).to.equal(videoId) | 148 | expect(ratings.data[0].video.id).to.equal(videoId) |
147 | expect(ratings.data[0].rating).to.equal('like') | 149 | expect(ratings.data[0].rating).to.equal('like') |
148 | }) | 150 | }) |
149 | 151 | ||
150 | it('Should retrieve ratings list by rating type', async function () { | 152 | it('Should retrieve ratings list by rating type', async function () { |
151 | await rateVideo(server.url, accessToken, videoId, 'like') | 153 | { |
152 | let res = await getAccountRatings(server.url, server.user.username, server.accessToken, 200, { rating: 'like' }) | 154 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') |
153 | let ratings = res.body | 155 | const ratings = res.body |
154 | expect(ratings.data.length).to.equal(1) | 156 | expect(ratings.data.length).to.equal(1) |
155 | res = await getAccountRatings(server.url, server.user.username, server.accessToken, 200, { rating: 'dislike' }) | 157 | } |
156 | ratings = res.body | 158 | |
157 | expect(ratings.data.length).to.equal(0) | 159 | { |
158 | await getAccountRatings(server.url, server.user.username, server.accessToken, 400, { rating: 'invalid' }) | 160 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') |
159 | }) | 161 | const ratings = res.body |
160 | 162 | expect(ratings.data.length).to.equal(0) | |
161 | it('Should not access ratings list if not logged with correct user', async function () { | 163 | } |
162 | const user = { username: 'anuragh', password: 'passbyme' } | ||
163 | const resUser = await createUser(server.url, server.accessToken, user.username, user.password) | ||
164 | const userId = resUser.body.user.id | ||
165 | const userAccessToken = await userLogin(server, user) | ||
166 | await getAccountRatings(server.url, server.user.username, userAccessToken, 403) | ||
167 | await removeUser(server.url, userId, server.accessToken) | ||
168 | }) | 164 | }) |
169 | 165 | ||
170 | it('Should not be able to remove the video with an incorrect token', async function () { | 166 | it('Should not be able to remove the video with an incorrect token', async function () { |