1
0
Fork 0

Add check params account ratings tests

This commit is contained in:
Chocobozzz 2019-04-09 11:21:36 +02:00
parent c100a6142e
commit 22834691ab
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
6 changed files with 55 additions and 25 deletions

View File

@ -1,22 +1,22 @@
import * as express from 'express' import * as express from 'express'
import { getFormattedObjects, getServerActor } from '../../helpers/utils' import { getFormattedObjects, getServerActor } from '../../helpers/utils'
import { import {
authenticate,
asyncMiddleware, asyncMiddleware,
authenticate,
commonVideosFiltersValidator, commonVideosFiltersValidator,
videoRatingValidator,
optionalAuthenticate, optionalAuthenticate,
paginationValidator, paginationValidator,
setDefaultPagination, setDefaultPagination,
setDefaultSort, setDefaultSort,
videoPlaylistsSortValidator, videoPlaylistsSortValidator,
videoRatesSortValidator videoRatesSortValidator,
videoRatingValidator
} from '../../middlewares' } from '../../middlewares'
import { import {
accountNameWithHostGetValidator, accountNameWithHostGetValidator,
accountsSortValidator, accountsSortValidator,
videosSortValidator, ensureAuthUserOwnsAccountValidator,
ensureAuthUserOwnsAccountValidator videosSortValidator
} from '../../middlewares/validators' } from '../../middlewares/validators'
import { AccountModel } from '../../models/account/account' import { AccountModel } from '../../models/account/account'
import { AccountVideoRateModel } from '../../models/account/account-video-rate' import { AccountVideoRateModel } from '../../models/account/account-video-rate'

View File

@ -22,7 +22,6 @@ import { logger } from '../../helpers/logger'
import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup'
import { Redis } from '../../lib/redis' import { Redis } from '../../lib/redis'
import { UserModel } from '../../models/account/user' import { UserModel } from '../../models/account/user'
import { AccountModel } from '../../models/account/account'
import { areValidationErrors } from './utils' import { areValidationErrors } from './utils'
import { ActorModel } from '../../models/activitypub/actor' import { ActorModel } from '../../models/activitypub/actor'

View File

@ -1,7 +1,7 @@
import * as express from 'express' import * as express from 'express'
import 'express-validator' import 'express-validator'
import { body, param, query } from 'express-validator/check' import { body, param, query } from 'express-validator/check'
import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
import { isRatingValid } from '../../../helpers/custom-validators/video-rates' import { isRatingValid } from '../../../helpers/custom-validators/video-rates'
import { doesVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' import { doesVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos'
import { logger } from '../../../helpers/logger' import { logger } from '../../../helpers/logger'

View File

@ -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 () { describe('When blocking/unblocking/removing user', function () {
it('Should fail with an incorrect id', async function () { it('Should fail with an incorrect id', async function () {
await removeUser(server.url, 'blabla', server.accessToken, 400) await removeUser(server.url, 'blabla', server.accessToken, 400)

View File

@ -140,31 +140,27 @@ describe('Test users', function () {
it('Should retrieve ratings list', async function () { it('Should retrieve ratings list', async function () {
await rateVideo(server.url, accessToken, videoId, 'like') 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 const ratings = res.body
expect(ratings.total).to.equal(1)
expect(ratings.data[0].video.id).to.equal(videoId) expect(ratings.data[0].video.id).to.equal(videoId)
expect(ratings.data[0].rating).to.equal('like') expect(ratings.data[0].rating).to.equal('like')
}) })
it('Should retrieve ratings list by rating type', async function () { 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' }) const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like')
let ratings = res.body const ratings = res.body
expect(ratings.data.length).to.equal(1) 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 res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike')
const resUser = await createUser(server.url, server.accessToken, user.username, user.password) const ratings = res.body
const userId = resUser.body.user.id expect(ratings.data.length).to.equal(0)
const userAccessToken = await userLogin(server, user) }
await getAccountRatings(server.url, server.user.username, userAccessToken, 403)
await removeUser(server.url, userId, server.accessToken)
}) })
it('Should not be able to remove the video with an incorrect token', async function () { it('Should not be able to remove the video with an incorrect token', async function () {

View File

@ -7,6 +7,7 @@ import { join } from 'path'
import { Account } from '../../models/actors' import { Account } from '../../models/actors'
import { root } from '../miscs/miscs' import { root } from '../miscs/miscs'
import { makeGetRequest } from '../requests/requests' import { makeGetRequest } from '../requests/requests'
import { VideoRateType } from '../../models/videos'
function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) { function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) {
const path = '/api/v1/accounts' const path = '/api/v1/accounts'
@ -54,9 +55,11 @@ async function checkActorFilesWereRemoved (actorUUID: string, serverNumber: numb
} }
} }
function getAccountRatings (url: string, accountName: string, accessToken: string, statusCodeExpected = 200, query = {}) { function getAccountRatings (url: string, accountName: string, accessToken: string, rating?: VideoRateType, statusCodeExpected = 200) {
const path = '/api/v1/accounts/' + accountName + '/ratings' const path = '/api/v1/accounts/' + accountName + '/ratings'
const query = rating ? { rating } : {}
return request(url) return request(url)
.get(path) .get(path)
.query(query) .query(query)