Improve check videos parameters tests

This commit is contained in:
Chocobozzz 2017-12-28 16:26:28 +01:00
parent 26d21b7867
commit 11ba2ab3f1
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
11 changed files with 333 additions and 578 deletions

View File

@ -1,7 +1,6 @@
/* tslint:disable:no-unused-expression */ /* tslint:disable:no-unused-expression */
import 'mocha' import 'mocha'
import * as request from 'supertest'
import { import {
createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,

View File

@ -1,9 +1,8 @@
/* tslint:disable:no-unused-expression */ /* tslint:disable:no-unused-expression */
import 'mocha' import 'mocha'
import * as request from 'supertest'
import { createUser, flushTests, userLogin, killallServers, runServer, ServerInfo, setAccessTokensToServers } from '../../utils' import { createUser, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, userLogin } from '../../utils'
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
import { makeGetRequest } from '../../utils/requests/requests' import { makeGetRequest } from '../../utils/requests/requests'

View File

@ -1,20 +1,12 @@
/* tslint:disable:no-unused-expression */ /* tslint:disable:no-unused-expression */
import * as request from 'supertest'
import 'mocha' import 'mocha'
import { import {
ServerInfo, createUser, flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
flushTests, uploadVideo, userLogin
runServer,
uploadVideo,
getVideosList,
createUser,
setAccessTokensToServers,
killallServers,
makePostBodyRequest,
userLogin
} from '../../utils' } from '../../utils'
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
describe('Test video abuses API validators', function () { describe('Test video abuses API validators', function () {
let server: ServerInfo let server: ServerInfo
@ -34,63 +26,42 @@ describe('Test video abuses API validators', function () {
const username = 'user1' const username = 'user1'
const password = 'my super password' const password = 'my super password'
await createUser(server.url, server.accessToken, username, password) await createUser(server.url, server.accessToken, username, password)
userAccessToken = await userLogin(server, { username, password }) userAccessToken = await userLogin(server, { username, password })
// Upload a video const res = await uploadVideo(server.url, server.accessToken, {})
const videoAttributes = {} server.video = res.body.video
await uploadVideo(server.url, server.accessToken, videoAttributes)
const res = await getVideosList(server.url)
const videos = res.body.data
server.video = videos[0]
}) })
describe('When listing video abuses', function () { describe('When listing video abuses', function () {
const path = '/api/v1/videos/abuse' const path = '/api/v1/videos/abuse'
it('Should fail with a bad start pagination', async function () { it('Should fail with a bad start pagination', async function () {
await request(server.url) await checkBadStartPagination(server.url, path, server.accessToken)
.get(path)
.query({ start: 'hello' })
.set('Authorization', 'Bearer ' + server.accessToken)
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should fail with a bad count pagination', async function () { it('Should fail with a bad count pagination', async function () {
await request(server.url) await checkBadCountPagination(server.url, path, server.accessToken)
.get(path)
.query({ count: 'hello' })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + server.accessToken)
.expect(400)
}) })
it('Should fail with an incorrect sort', async function () { it('Should fail with an incorrect sort', async function () {
await request(server.url) await checkBadSortPagination(server.url, path, server.accessToken)
.get(path)
.query({ sort: 'hello' })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + server.accessToken)
.expect(400)
}) })
it('Should fail with a non authenticated user', async function () { it('Should fail with a non authenticated user', async function () {
await request(server.url) await makeGetRequest({
.get(path) url: server.url,
.query({ sort: 'hello' }) path,
.set('Accept', 'application/json') statusCodeExpected: 401
.expect(401) })
}) })
it('Should fail with a non admin user', async function () { it('Should fail with a non admin user', async function () {
await request(server.url) await makeGetRequest({
.get(path) url: server.url,
.query({ sort: 'hello' }) path,
.set('Accept', 'application/json') token: userAccessToken,
.set('Authorization', 'Bearer ' + userAccessToken) statusCodeExpected: 403
.expect(403) })
}) })
}) })
@ -105,32 +76,33 @@ describe('Test video abuses API validators', function () {
it('Should fail with a wrong video', async function () { it('Should fail with a wrong video', async function () {
const wrongPath = '/api/v1/videos/blabla/abuse' const wrongPath = '/api/v1/videos/blabla/abuse'
const fields = {} const fields = {
reason: 'my super reason'
}
await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
}) })
it('Should fail with a non authenticated user', async function () { it('Should fail with a non authenticated user', async function () {
const fields = {}
const path = basePath + server.video.id + '/abuse' const path = basePath + server.video.id + '/abuse'
const fields = {
reason: 'my super reason'
}
await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
}) })
it('Should fail with a reason too short', async function () { it('Should fail with a reason too short', async function () {
const path = basePath + server.video.id + '/abuse'
const fields = { const fields = {
reason: 'h' reason: 'h'
} }
const path = basePath + server.video.id + '/abuse'
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
}) })
it('Should fail with a reason too big', async function () { it('Should fail with a reason too big', async function () {
const fields = {
reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
'0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
'0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
'0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
}
const path = basePath + server.video.id + '/abuse' const path = basePath + server.video.id + '/abuse'
const fields = {
reason: 'super'.repeat(61)
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
}) })
}) })

View File

@ -1,20 +1,12 @@
/* tslint:disable:no-unused-expression */ /* tslint:disable:no-unused-expression */
import 'mocha' import 'mocha'
import * as request from 'supertest'
import { import {
ServerInfo, createUser, flushTests, getBlacklistedVideosList, killallServers, makePostBodyRequest, removeVideoFromBlacklist, runServer,
flushTests, ServerInfo, setAccessTokensToServers, uploadVideo, userLogin
runServer,
uploadVideo,
getVideosList,
createUser,
setAccessTokensToServers,
killallServers,
makePostBodyRequest,
userLogin
} from '../../utils' } from '../../utils'
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
describe('Test video blacklist API validators', function () { describe('Test video blacklist API validators', function () {
let server: ServerInfo let server: ServerInfo
@ -36,14 +28,8 @@ describe('Test video blacklist API validators', function () {
await createUser(server.url, server.accessToken, username, password) await createUser(server.url, server.accessToken, username, password)
userAccessToken = await userLogin(server, { username, password }) userAccessToken = await userLogin(server, { username, password })
// Upload a video const res = await uploadVideo(server.url, server.accessToken, {})
const videoAttributes = {} server.video = res.body.video
await uploadVideo(server.url, server.accessToken, videoAttributes)
const res = await getVideosList(server.url)
const videos = res.body.data
server.video = videos[0]
}) })
describe('When adding a video in blacklist', function () { describe('When adding a video in blacklist', function () {
@ -62,66 +48,40 @@ describe('Test video blacklist API validators', function () {
}) })
it('Should fail with a non authenticated user', async function () { it('Should fail with a non authenticated user', async function () {
const fields = {}
const path = basePath + server.video + '/blacklist' const path = basePath + server.video + '/blacklist'
const fields = {}
await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
}) })
it('Should fail with a non admin user', async function () { it('Should fail with a non admin user', async function () {
const fields = {}
const path = basePath + server.video + '/blacklist' const path = basePath + server.video + '/blacklist'
const fields = {}
await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
}) })
it('Should fail with a local video', async function () { it('Should fail with a local video', async function () {
const fields = {}
const path = basePath + server.video.id + '/blacklist' const path = basePath + server.video.id + '/blacklist'
const fields = {}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 }) await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 })
}) })
}) })
describe('When removing a video in blacklist', function () { describe('When removing a video in blacklist', function () {
const basePath = '/api/v1/videos/'
it('Should fail with a non authenticated user', async function () { it('Should fail with a non authenticated user', async function () {
const path = basePath + server.video.id + '/blacklist' await removeVideoFromBlacklist(server.url, 'fake token', server.video.id, 401)
await request(server.url)
.delete(path)
.set('Authorization', 'Bearer ' + 'fake token')
.set('Accept', 'application/json')
.expect(401)
}) })
it('Should fail with a non admin user', async function () { it('Should fail with a non admin user', async function () {
const path = basePath + server.video.id + '/blacklist' await removeVideoFromBlacklist(server.url, userAccessToken, server.video.id, 403)
await request(server.url)
.delete(path)
.set('Authorization', 'Bearer ' + userAccessToken)
.set('Accept', 'application/json')
.expect(403)
}) })
it('Should fail with an incorrect id', async function () { it('Should fail with an incorrect id', async function () {
const path = basePath + 'foobar/blacklist' await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400)
await request(server.url)
.delete(path)
.set('Authorization', 'Bearer ' + server.accessToken)
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should fail with a not blacklisted video', async function () { it('Should fail with a not blacklisted video', async function () {
// The video was not added to the blacklist so it should fail // The video was not added to the blacklist so it should fail
const path = basePath + server.video.id + '/blacklist' await removeVideoFromBlacklist(server.url, server.accessToken, server.video.id, 404)
await request(server.url)
.delete(path)
.set('Authorization', 'Bearer ' + server.accessToken)
.set('Accept', 'application/json')
.expect(404)
}) })
}) })
@ -129,58 +89,23 @@ describe('Test video blacklist API validators', function () {
const basePath = '/api/v1/videos/blacklist/' const basePath = '/api/v1/videos/blacklist/'
it('Should fail with a non authenticated user', async function () { it('Should fail with a non authenticated user', async function () {
const path = basePath await getBlacklistedVideosList(server.url, 'fake token', 401)
await request(server.url)
.get(path)
.query({ sort: 'createdAt' })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + 'fake token')
.expect(401)
}) })
it('Should fail with a non admin user', async function () { it('Should fail with a non admin user', async function () {
const path = basePath await getBlacklistedVideosList(server.url, userAccessToken, 403)
await request(server.url)
.get(path)
.query({ sort: 'createdAt' })
.set('Authorization', 'Bearer ' + userAccessToken)
.set('Accept', 'application/json')
.expect(403)
}) })
it('Should fail with a bad start pagination', async function () { it('Should fail with a bad start pagination', async function () {
const path = basePath await checkBadStartPagination(server.url, basePath, server.accessToken)
await request(server.url)
.get(path)
.query({ start: 'foobar' })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + server.accessToken)
.expect(400)
}) })
it('Should fail with a bad count pagination', async function () { it('Should fail with a bad count pagination', async function () {
const path = basePath await checkBadCountPagination(server.url, basePath, server.accessToken)
await request(server.url)
.get(path)
.query({ count: 'foobar' })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + server.accessToken)
.expect(400)
}) })
it('Should fail with an incorrect sort', async function () { it('Should fail with an incorrect sort', async function () {
const path = basePath await checkBadSortPagination(server.url, basePath, server.accessToken)
await request(server.url)
.get(path)
.query({ sort: 'foobar' })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + server.accessToken)
.expect(400)
}) })
}) })

View File

@ -1,22 +1,15 @@
/* tslint:disable:no-unused-expression */ /* tslint:disable:no-unused-expression */
import * as request from 'supertest'
import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
const expect = chai.expect import { omit } from 'lodash'
import 'mocha'
import { import {
ServerInfo, createUser, deleteVideoChannel, flushTests, getAccountVideoChannelsList, getVideoChannelsList, immutableAssign, killallServers,
flushTests, makeGetRequest, makePostBodyRequest, makePutBodyRequest, runServer, ServerInfo, setAccessTokensToServers, userLogin
runServer,
makePutBodyRequest,
setAccessTokensToServers,
killallServers,
makePostBodyRequest,
getVideoChannelsList,
createUser,
userLogin
} from '../../utils' } from '../../utils'
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
const expect = chai.expect
describe('Test videos API validator', function () { describe('Test videos API validator', function () {
const path = '/api/v1/videos/channels' const path = '/api/v1/videos/channels'
@ -39,64 +32,41 @@ describe('Test videos API validator', function () {
password: 'fake_password' password: 'fake_password'
} }
await createUser(server.url, server.accessToken, user.username, user.password) await createUser(server.url, server.accessToken, user.username, user.password)
accessTokenUser = await userLogin(server, user) accessTokenUser = await userLogin(server, user)
}) })
describe('When listing a video channels', function () { describe('When listing a video channels', function () {
it('Should fail with a bad start pagination', async function () { it('Should fail with a bad start pagination', async function () {
await request(server.url) await checkBadStartPagination(server.url, path, server.accessToken)
.get(path)
.query({ start: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should fail with a bad count pagination', async function () { it('Should fail with a bad count pagination', async function () {
await request(server.url) await checkBadCountPagination(server.url, path, server.accessToken)
.get(path)
.query({ count: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should fail with an incorrect sort', async function () { it('Should fail with an incorrect sort', async function () {
await request(server.url) await checkBadSortPagination(server.url, path, server.accessToken)
.get(path)
.query({ sort: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
}) })
describe('When listing account video channels', function () { describe('When listing account video channels', function () {
it('Should fail with bad account', async function () { it('Should fail with bad account', async function () {
const path = '/api/v1/videos/accounts/hello/channels' await getAccountVideoChannelsList(server.url, 'hello', 400)
await request(server.url)
.get(path)
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should fail with a unknown account', async function () { it('Should fail with a unknown account', async function () {
const path = '/api/v1/videos/accounts/156/channels' await getAccountVideoChannelsList(server.url, 154, 404)
await request(server.url)
.get(path)
.set('Accept', 'application/json')
.expect(404)
}) })
}) })
describe('When adding a video channel', function () { describe('When adding a video channel', function () {
const baseCorrectParams = {
name: 'hello',
description: 'super description'
}
it('Should fail with a non authenticated user', async function () { it('Should fail with a non authenticated user', async function () {
const fields = { await makePostBodyRequest({ url: server.url, path, token: 'none', fields: baseCorrectParams, statusCodeExpected: 401 })
name: 'hello',
description: 'super description'
}
await makePostBodyRequest({ url: server.url, path, token: 'none', fields, statusCodeExpected: 401 })
}) })
it('Should fail with nothing', async function () { it('Should fail with nothing', async function () {
@ -105,45 +75,37 @@ describe('Test videos API validator', function () {
}) })
it('Should fail without name', async function () { it('Should fail without name', async function () {
const fields = { const fields = omit(baseCorrectParams, 'name')
description: 'super description'
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
}) })
it('Should fail with a long name', async function () { it('Should fail with a long name', async function () {
const fields = { const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
description: 'super description'
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
}) })
it('Should fail with a long description', async function () { it('Should fail with a long description', async function () {
const fields = { const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
name: 'hello',
description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
}) })
it('Should succeed with the correct parameters', async function () { it('Should succeed with the correct parameters', async function () {
const fields = { await makePostBodyRequest({
name: 'hello', url: server.url,
description: 'super description' path,
} token: server.accessToken,
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) fields: baseCorrectParams,
statusCodeExpected: 204
})
}) })
}) })
describe('When updating a video channel', function () { describe('When updating a video channel', function () {
const baseCorrectParams = {
name: 'hello',
description: 'super description'
}
let videoChannelId let videoChannelId
before(async function () { before(async function () {
@ -152,60 +114,41 @@ describe('Test videos API validator', function () {
}) })
it('Should fail with a non authenticated user', async function () { it('Should fail with a non authenticated user', async function () {
const fields = { await makePutBodyRequest({
name: 'hello', url: server.url,
description: 'super description' path: path + '/' + videoChannelId,
} token: 'hi',
await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: 'hi', fields, statusCodeExpected: 401 }) fields: baseCorrectParams,
statusCodeExpected: 401
})
}) })
it('Should fail with another authenticated user', async function () { it('Should fail with another authenticated user', async function () {
const fields = {
name: 'hello',
description: 'super description'
}
await makePutBodyRequest({ await makePutBodyRequest({
url: server.url, url: server.url,
path: path + '/' + videoChannelId, path: path + '/' + videoChannelId,
token: accessTokenUser, token: accessTokenUser,
fields, fields: baseCorrectParams,
statusCodeExpected: 403 statusCodeExpected: 403
}) })
}) })
it('Should fail with a long name', async function () { it('Should fail with a long name', async function () {
const fields = { const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
description: 'super description'
}
await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
}) })
it('Should fail with a long description', async function () { it('Should fail with a long description', async function () {
const fields = { const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
name: 'hello',
description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
}
await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
}) })
it('Should succeed with the correct parameters', async function () { it('Should succeed with the correct parameters', async function () {
const fields = {
name: 'hello 2',
description: 'super description 2'
}
await makePutBodyRequest({ await makePutBodyRequest({
url: server.url, url: server.url,
path: path + '/' + videoChannelId, path: path + '/' + videoChannelId,
token: server.accessToken, token: server.accessToken,
fields, fields: baseCorrectParams,
statusCodeExpected: 204 statusCodeExpected: 204
}) })
}) })
@ -220,34 +163,37 @@ describe('Test videos API validator', function () {
}) })
it('Should return the list of the video channels with nothing', async function () { it('Should return the list of the video channels with nothing', async function () {
const res = await request(server.url) const res = await makeGetRequest({
.get(path) url: server.url,
.set('Accept', 'application/json') path,
.expect(200) statusCodeExpected: 200
.expect('Content-Type', /json/) })
expect(res.body.data).to.be.an('array') expect(res.body.data).to.be.an('array')
}) })
it('Should fail without a correct uuid', async function () { it('Should fail without a correct uuid', async function () {
await request(server.url) await makeGetRequest({
.get(path + '/coucou') url: server.url,
.set('Accept', 'application/json') path: path + '/coucou',
.expect(400) statusCodeExpected: 400
})
}) })
it('Should return 404 with an incorrect video channel', async function () { it('Should return 404 with an incorrect video channel', async function () {
await request(server.url) await makeGetRequest({
.get(path + '/4da6fde3-88f7-4d16-b119-108df5630b06') url: server.url,
.set('Accept', 'application/json') path: path + '/4da6fde3-88f7-4d16-b119-108df5630b06',
.expect(404) statusCodeExpected: 404
})
}) })
it('Should succeed with the correct parameters', async function () { it('Should succeed with the correct parameters', async function () {
await request(server.url) await makeGetRequest({
.get(path + '/' + videoChannelId) url: server.url,
.set('Accept', 'application/json') path: path + '/' + videoChannelId,
.expect(200) statusCodeExpected: 200
})
}) })
}) })
@ -260,42 +206,26 @@ describe('Test videos API validator', function () {
}) })
it('Should fail with a non authenticated user', async function () { it('Should fail with a non authenticated user', async function () {
await request(server.url) await deleteVideoChannel(server.url, 'coucou', videoChannelId, 401)
.delete(path + '/' + videoChannelId)
.set('Authorization', 'Bearer coucou')
.expect(401)
}) })
it('Should fail with another authenticated user', async function () { it('Should fail with another authenticated user', async function () {
await request(server.url) await deleteVideoChannel(server.url, accessTokenUser, videoChannelId, 403)
.delete(path + '/' + videoChannelId)
.set('Authorization', 'Bearer ' + accessTokenUser)
.expect(403)
}) })
it('Should fail with an unknown id', async function () { it('Should fail with an unknown id', async function () {
await request(server.url) await deleteVideoChannel(server.url, server.accessToken, 454554, 404)
.delete(path + '/454554')
.set('Authorization', 'Bearer ' + server.accessToken)
.expect(404)
}) })
it('Should succeed with the correct parameters', async function () { it('Should succeed with the correct parameters', async function () {
await request(server.url) await deleteVideoChannel(server.url, server.accessToken, videoChannelId)
.delete(path + '/' + videoChannelId)
.set('Authorization', 'Bearer ' + server.accessToken)
.expect(204)
}) })
it('Should fail to delete the last user video channel', async function () { it('Should fail to delete the last user video channel', async function () {
const res = await getVideoChannelsList(server.url, 0, 1) const res = await getVideoChannelsList(server.url, 0, 1)
videoChannelId = res.body.data[0].id videoChannelId = res.body.data[0].id
await request(server.url) await deleteVideoChannel(server.url, server.accessToken, videoChannelId, 409)
.delete(path + '/' + videoChannelId)
.set('Authorization', 'Bearer ' + server.accessToken)
.expect(409
)
}) })
}) })

View File

@ -1,8 +1,11 @@
/* tslint:disable:no-unused-expression */ /* tslint:disable:no-unused-expression */
import 'mocha' import 'mocha'
import * as request from 'supertest' import {
import { flushTests, killallServers, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils' flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
uploadVideo
} from '../../utils'
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
import { addVideoCommentThread } from '../../utils/videos/video-comments' import { addVideoCommentThread } from '../../utils/videos/video-comments'
describe('Test video comments API validator', function () { describe('Test video comments API validator', function () {
@ -38,57 +41,52 @@ describe('Test video comments API validator', function () {
describe('When listing video comment threads', function () { describe('When listing video comment threads', function () {
it('Should fail with a bad start pagination', async function () { it('Should fail with a bad start pagination', async function () {
await request(server.url) await checkBadStartPagination(server.url, pathThread, server.accessToken)
.get(pathThread)
.query({ start: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should fail with a bad count pagination', async function () { it('Should fail with a bad count pagination', async function () {
await request(server.url) await checkBadCountPagination(server.url, pathThread, server.accessToken)
.get(pathThread)
.query({ count: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should fail with an incorrect sort', async function () { it('Should fail with an incorrect sort', async function () {
await request(server.url) await checkBadSortPagination(server.url, pathThread, server.accessToken)
.get(pathThread)
.query({ sort: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should fail with an incorrect video', async function () { it('Should fail with an incorrect video', async function () {
await request(server.url) await makeGetRequest({
.get('/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads') url: server.url,
.set('Accept', 'application/json') path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
.expect(404) statusCodeExpected: 404
})
}) })
}) })
describe('When listing comments of a thread', function () { describe('When listing comments of a thread', function () {
it('Should fail with an incorrect video', async function () { it('Should fail with an incorrect video', async function () {
await request(server.url) await makeGetRequest({
.get('/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId) url: server.url,
.set('Accept', 'application/json') path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
.expect(404) statusCodeExpected: 404
})
}) })
it('Should fail with an incorrect thread id', async function () { it('Should fail with an incorrect thread id', async function () {
await request(server.url) await makeGetRequest({
.get('/api/v1/videos/' + videoUUID + '/comment-threads/156') url: server.url,
.set('Accept', 'application/json') path: '/api/v1/videos/' + videoUUID + '/comment-threads/156',
.expect(404) statusCodeExpected: 404
})
}) })
it('Should success with the correct params', async function () { it('Should success with the correct params', async function () {
await request(server.url) await makeGetRequest({
.get('/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId) url: server.url,
.set('Accept', 'application/json') path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId,
.expect(200) statusCodeExpected: 200
})
}) })
}) })

View File

@ -1,64 +1,23 @@
/* tslint:disable:no-unused-expression */ /* tslint:disable:no-unused-expression */
import * as request from 'supertest'
import { join } from 'path'
import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
const expect = chai.expect import { omit } from 'lodash'
import 'mocha'
import { import { join } from 'path'
ServerInfo,
flushTests,
runServer,
getVideosList,
makePutBodyRequest,
setAccessTokensToServers,
killallServers,
makePostUploadRequest,
getMyUserInformation,
createUser,
userLogin
} from '../../utils'
import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
import {
createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest,
makeGetRequest, makePostUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin
} from '../../utils'
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
const expect = chai.expect
describe('Test videos API validator', function () { describe('Test videos API validator', function () {
const path = '/api/v1/videos/' const path = '/api/v1/videos/'
let server: ServerInfo let server: ServerInfo
let channelId: number let channelId: number
function getCompleteVideoUploadAttributes () {
return {
name: 'my super name',
category: 5,
licence: 1,
language: 6,
nsfw: false,
description: 'my super description',
tags: [ 'tag1', 'tag2' ],
privacy: VideoPrivacy.PUBLIC,
channelId
}
}
function getCompleteVideoUpdateAttributes () {
return {
name: 'my super name',
category: 5,
licence: 2,
language: 6,
nsfw: false,
description: 'my super description',
privacy: VideoPrivacy.PUBLIC,
tags: [ 'tag1', 'tag2' ]
}
}
function getVideoUploadAttaches () {
return {
'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
}
}
// --------------------------------------------------------------- // ---------------------------------------------------------------
before(async function () { before(async function () {
@ -76,60 +35,38 @@ describe('Test videos API validator', function () {
describe('When listing a video', function () { describe('When listing a video', function () {
it('Should fail with a bad start pagination', async function () { it('Should fail with a bad start pagination', async function () {
await request(server.url) await checkBadStartPagination(server.url, path)
.get(path)
.query({ start: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should fail with a bad count pagination', async function () { it('Should fail with a bad count pagination', async function () {
await request(server.url) await checkBadCountPagination(server.url, path)
.get(path)
.query({ count: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should fail with an incorrect sort', async function () { it('Should fail with an incorrect sort', async function () {
await request(server.url) await checkBadSortPagination(server.url, path)
.get(path)
.query({ sort: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
}) })
describe('When searching a video', function () { describe('When searching a video', function () {
it('Should fail with nothing', async function () { it('Should fail with nothing', async function () {
await request(server.url) await makeGetRequest({
.get(join(path, 'search')) url: server.url,
.set('Accept', 'application/json') path: join(path, 'search'),
.expect(400) statusCodeExpected: 400
})
}) })
it('Should fail with a bad start pagination', async function () { it('Should fail with a bad start pagination', async function () {
await request(server.url) await checkBadStartPagination(server.url, join(path, 'search', 'test'))
.get(join(path, 'search', 'test'))
.query({ start: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should fail with a bad count pagination', async function () { it('Should fail with a bad count pagination', async function () {
await request(server.url) await checkBadCountPagination(server.url, join(path, 'search', 'test'))
.get(join(path, 'search', 'test'))
.query({ count: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should fail with an incorrect sort', async function () { it('Should fail with an incorrect sort', async function () {
await request(server.url) await checkBadSortPagination(server.url, join(path, 'search', 'test'))
.get(join(path, 'search', 'test'))
.query({ sort: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
}) })
@ -137,34 +74,39 @@ describe('Test videos API validator', function () {
const path = '/api/v1/users/me/videos' const path = '/api/v1/users/me/videos'
it('Should fail with a bad start pagination', async function () { it('Should fail with a bad start pagination', async function () {
await request(server.url) await checkBadStartPagination(server.url, path, server.accessToken)
.get(path)
.set('Authorization', 'Bearer ' + server.accessToken)
.query({ start: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should fail with a bad count pagination', async function () { it('Should fail with a bad count pagination', async function () {
await request(server.url) await checkBadCountPagination(server.url, path, server.accessToken)
.get(path)
.set('Authorization', 'Bearer ' + server.accessToken)
.query({ count: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should fail with an incorrect sort', async function () { it('Should fail with an incorrect sort', async function () {
await request(server.url) await checkBadSortPagination(server.url, path, server.accessToken)
.get(path)
.set('Authorization', 'Bearer ' + server.accessToken)
.query({ sort: 'hello' })
.set('Accept', 'application/json')
.expect(400)
}) })
}) })
describe('When adding a video', function () { describe('When adding a video', function () {
let baseCorrectParams
const baseCorrectAttaches = {
'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
}
before(function () {
// Put in before to have channelId
baseCorrectParams = {
name: 'my super name',
category: 5,
licence: 1,
language: 6,
nsfw: false,
description: 'my super description',
tags: [ 'tag1', 'tag2' ],
privacy: VideoPrivacy.PUBLIC,
channelId
}
})
it('Should fail with nothing', async function () { it('Should fail with nothing', async function () {
const fields = {} const fields = {}
const attaches = {} const attaches = {}
@ -172,84 +114,72 @@ describe('Test videos API validator', function () {
}) })
it('Should fail without name', async function () { it('Should fail without name', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = omit(baseCorrectParams, 'name')
delete fields.name const attaches = baseCorrectAttaches
const attaches = getVideoUploadAttaches()
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
it('Should fail with a long name', async function () { it('Should fail with a long name', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
fields.name = 'My very very very very very very very very very very very very very very very very very ' + const attaches = baseCorrectAttaches
'very very very very very very very very very very very very very very very very long long' +
'very very very very very very very very very very very very very very very very long name'
const attaches = getVideoUploadAttaches
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
it('Should fail with a bad category', async function () { it('Should fail with a bad category', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = immutableAssign(baseCorrectParams, { category: 125 })
fields.category = 125 const attaches = baseCorrectAttaches
const attaches = getVideoUploadAttaches
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
it('Should fail with a bad licence', async function () { it('Should fail with a bad licence', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = immutableAssign(baseCorrectParams, { licence: 125 })
fields.licence = 125 const attaches = baseCorrectAttaches
const attaches = getVideoUploadAttaches()
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
it('Should fail with a bad language', async function () { it('Should fail with a bad language', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = immutableAssign(baseCorrectParams, { language: 125 })
fields.language = 563 const attaches = baseCorrectAttaches
const attaches = getVideoUploadAttaches()
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
it('Should fail without nsfw attribute', async function () { it('Should fail without nsfw attribute', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = omit(baseCorrectParams, 'nsfw')
delete fields.nsfw const attaches = baseCorrectAttaches
const attaches = getVideoUploadAttaches()
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
it('Should fail with a bad nsfw attribute', async function () { it('Should fail with a bad nsfw attribute', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
fields.nsfw = 2 as any const attaches = baseCorrectAttaches
const attaches = getVideoUploadAttaches()
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
it('Should fail with a long description', async function () { it('Should fail with a long description', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) })
fields.description = 'my super description which is very very very very very very very very very very very very long'.repeat(35) const attaches = baseCorrectAttaches
const attaches = getVideoUploadAttaches()
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
it('Should fail without a channel', async function () { it('Should fail without a channel', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = omit(baseCorrectParams, 'channelId')
delete fields.channelId const attaches = baseCorrectAttaches
const attaches = getVideoUploadAttaches()
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
it('Should fail with a bad channel', async function () { it('Should fail with a bad channel', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
fields.channelId = 545454 const attaches = baseCorrectAttaches
const attaches = getVideoUploadAttaches()
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
@ -264,45 +194,41 @@ describe('Test videos API validator', function () {
const res = await getMyUserInformation(server.url, accessTokenUser) const res = await getMyUserInformation(server.url, accessTokenUser)
const customChannelId = res.body.videoChannels[0].id const customChannelId = res.body.videoChannels[0].id
const fields = getCompleteVideoUploadAttributes() const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
fields.channelId = customChannelId const attaches = baseCorrectAttaches
const attaches = getVideoUploadAttaches()
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
it('Should fail with too many tags', async function () { it('Should fail with too many tags', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
fields.tags = [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] const attaches = baseCorrectAttaches
const attaches = getVideoUploadAttaches()
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
it('Should fail with a tag length too low', async function () { it('Should fail with a tag length too low', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
fields.tags = [ 'tag1', 't' ] const attaches = baseCorrectAttaches
const attaches = getVideoUploadAttaches()
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
it('Should fail with a tag length too big', async function () { it('Should fail with a tag length too big', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
fields.tags = [ 'my_super_tag_too_long_long_long_long_long_long', 'tag1' ] const attaches = baseCorrectAttaches
const attaches = getVideoUploadAttaches()
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
it('Should fail without an input file', async function () { it('Should fail without an input file', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = baseCorrectParams
const attaches = {} const attaches = {}
await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
}) })
it('Should fail without an incorrect input file', async function () { it('Should fail without an incorrect input file', async function () {
const fields = getCompleteVideoUploadAttributes() const fields = baseCorrectParams
const attaches = { const attaches = {
'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
} }
@ -312,41 +238,63 @@ describe('Test videos API validator', function () {
it('Should succeed with the correct parameters', async function () { it('Should succeed with the correct parameters', async function () {
this.timeout(10000) this.timeout(10000)
const fields = getCompleteVideoUploadAttributes() const fields = baseCorrectParams
const attaches = getVideoUploadAttaches()
await makePostUploadRequest({ {
url: server.url, const attaches = baseCorrectAttaches
path: path + '/upload', await makePostUploadRequest({
token: server.accessToken, url: server.url,
fields, path: path + '/upload',
attaches, token: server.accessToken,
statusCodeExpected: 200 fields,
}) attaches,
statusCodeExpected: 200
})
}
attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.mp4') {
await makePostUploadRequest({ const attaches = immutableAssign(baseCorrectAttaches, {
url: server.url, videofile: join(__dirname, '..', 'fixtures', 'video_short.mp4')
path: path + '/upload', })
token: server.accessToken,
fields,
attaches,
statusCodeExpected: 200
})
attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.ogv') await makePostUploadRequest({
await makePostUploadRequest({ url: server.url,
url: server.url, path: path + '/upload',
path: path + '/upload', token: server.accessToken,
token: server.accessToken, fields,
fields, attaches,
attaches, statusCodeExpected: 200
statusCodeExpected: 200 })
}) }
{
const attaches = immutableAssign(baseCorrectAttaches, {
videofile: join(__dirname, '..', 'fixtures', 'video_short.ogv')
})
await makePostUploadRequest({
url: server.url,
path: path + '/upload',
token: server.accessToken,
fields,
attaches,
statusCodeExpected: 200
})
}
}) })
}) })
describe('When updating a video', function () { describe('When updating a video', function () {
const baseCorrectParams = {
name: 'my super name',
category: 5,
licence: 2,
language: 6,
nsfw: false,
description: 'my super description',
privacy: VideoPrivacy.PUBLIC,
tags: [ 'tag1', 'tag2' ]
}
let videoId let videoId
before(async function () { before(async function () {
@ -360,12 +308,12 @@ describe('Test videos API validator', function () {
}) })
it('Should fail without a valid uuid', async function () { it('Should fail without a valid uuid', async function () {
const fields = getCompleteVideoUpdateAttributes() const fields = baseCorrectParams
await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
}) })
it('Should fail with an unknown id', async function () { it('Should fail with an unknown id', async function () {
const fields = getCompleteVideoUpdateAttributes() const fields = baseCorrectParams
await makePutBodyRequest({ await makePutBodyRequest({
url: server.url, url: server.url,
@ -377,64 +325,55 @@ describe('Test videos API validator', function () {
}) })
it('Should fail with a long name', async function () { it('Should fail with a long name', async function () {
const fields = getCompleteVideoUpdateAttributes() const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
fields.name = 'My very very very very very very very very very very very very very very very very long'.repeat(3)
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
}) })
it('Should fail with a bad category', async function () { it('Should fail with a bad category', async function () {
const fields = getCompleteVideoUpdateAttributes() const fields = immutableAssign(baseCorrectParams, { category: 125 })
fields.category = 128
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
}) })
it('Should fail with a bad licence', async function () { it('Should fail with a bad licence', async function () {
const fields = getCompleteVideoUpdateAttributes() const fields = immutableAssign(baseCorrectParams, { licence: 125 })
fields.licence = 128
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
}) })
it('Should fail with a bad language', async function () { it('Should fail with a bad language', async function () {
const fields = getCompleteVideoUpdateAttributes() const fields = immutableAssign(baseCorrectParams, { language: 125 })
fields.language = 896
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
}) })
it('Should fail with a bad nsfw attribute', async function () { it('Should fail with a bad nsfw attribute', async function () {
const fields = getCompleteVideoUpdateAttributes() const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
fields.nsfw = (-4 as any)
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
}) })
it('Should fail with a long description', async function () { it('Should fail with a long description', async function () {
const fields = getCompleteVideoUpdateAttributes() const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) })
fields.description = 'my super description which is very very very very very very very very very very very very very long'.repeat(35)
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
}) })
it('Should fail with too many tags', async function () { it('Should fail with too many tags', async function () {
const fields = getCompleteVideoUpdateAttributes() const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
fields.tags = [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ]
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
}) })
it('Should fail with a tag length too low', async function () { it('Should fail with a tag length too low', async function () {
const fields = getCompleteVideoUpdateAttributes() const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
fields.tags = [ 'tag1', 't' ]
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
}) })
it('Should fail with a tag length too big', async function () { it('Should fail with a tag length too big', async function () {
const fields = getCompleteVideoUpdateAttributes() const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
fields.tags = [ 'my_super_tag_too_long_long_long_long', 'tag1' ]
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
}) })
@ -444,7 +383,7 @@ describe('Test videos API validator', function () {
it('Should fail with a video of another server') it('Should fail with a video of another server')
it('Should succeed with the correct parameters', async function () { it('Should succeed with the correct parameters', async function () {
const fields = getCompleteVideoUpdateAttributes() const fields = baseCorrectParams
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
}) })
@ -452,28 +391,22 @@ describe('Test videos API validator', function () {
describe('When getting a video', function () { describe('When getting a video', function () {
it('Should return the list of the videos with nothing', async function () { it('Should return the list of the videos with nothing', async function () {
const res = await request(server.url) const res = await makeGetRequest({
.get(path) url: server.url,
.set('Accept', 'application/json') path,
.expect(200) statusCodeExpected: 200
.expect('Content-Type', /json/) })
expect(res.body.data).to.be.an('array') expect(res.body.data).to.be.an('array')
expect(res.body.data.length).to.equal(3) expect(res.body.data.length).to.equal(3)
}) })
it('Should fail without a correct uuid', async function () { it('Should fail without a correct uuid', async function () {
await request(server.url) await getVideo(server.url, 'coucou', 400)
.get(path + 'coucou')
.set('Accept', 'application/json')
.expect(400)
}) })
it('Should return 404 with an incorrect video', async function () { it('Should return 404 with an incorrect video', async function () {
await request(server.url) await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
.get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
.set('Accept', 'application/json')
.expect(404)
}) })
it('Should succeed with the correct parameters') it('Should succeed with the correct parameters')
@ -530,24 +463,19 @@ describe('Test videos API validator', function () {
describe('When removing a video', function () { describe('When removing a video', function () {
it('Should have 404 with nothing', async function () { it('Should have 404 with nothing', async function () {
await request(server.url) await makeDeleteRequest({
.delete(path) url: server.url,
.set('Authorization', 'Bearer ' + server.accessToken) path,
.expect(400) statusCodeExpected: 400
})
}) })
it('Should fail without a correct uuid', async function () { it('Should fail without a correct uuid', async function () {
await request(server.url) await removeVideo(server.url, server.accessToken, 'hello', 400)
.delete(path + 'hello')
.set('Authorization', 'Bearer ' + server.accessToken)
.expect(400)
}) })
it('Should fail with a video which does not exist', async function () { it('Should fail with a video which does not exist', async function () {
await request(server.url) await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
.delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
.set('Authorization', 'Bearer ' + server.accessToken)
.expect(404)
}) })
it('Should fail with a video of another user') it('Should fail with a video of another user')

View File

@ -4,32 +4,13 @@ import * as chai from 'chai'
import 'mocha' import 'mocha'
import { UserRole } from '../../../../shared/index' import { UserRole } from '../../../../shared/index'
import { import {
createUser, createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoRating, getUserInformation, getUsersList,
flushTests, getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo, registerUser, removeUser, removeVideo,
getBlacklistedVideosList, runServer, ServerInfo, serverLogin, updateMyUser, updateUser, uploadVideo
getMyUserInformation,
getUserInformation,
getUsersList,
getUsersListPaginationAndSort,
getMyUserVideoRating,
getVideosList,
killallServers,
login,
serverLogin,
makePutBodyRequest,
rateVideo,
registerUser,
removeUser,
removeVideo,
runServer,
ServerInfo,
updateMyUser,
updateUser,
uploadVideo
} from '../../utils/index' } from '../../utils/index'
import { follow } from '../../utils/server/follows' import { follow } from '../../utils/server/follows'
import { getMyVideos } from '../../utils/videos/videos'
import { setAccessTokensToServers } from '../../utils/users/login' import { setAccessTokensToServers } from '../../utils/users/login'
import { getMyVideos } from '../../utils/videos/videos'
const expect = chai.expect const expect = chai.expect
@ -387,14 +368,22 @@ describe('Test users', function () {
}) })
it('Should update my password', async function () { it('Should update my password', async function () {
await updateMyUser(server.url, accessTokenUser, 'new password') await updateMyUser({
url: server.url,
accessToken: accessTokenUser,
newPassword: 'new password'
})
server.user.password = 'new password' server.user.password = 'new password'
await login(server.url, server.client, server.user, 200) await login(server.url, server.client, server.user, 200)
}) })
it('Should be able to change the NSFW display attribute', async function () { it('Should be able to change the NSFW display attribute', async function () {
await updateMyUser(server.url, accessTokenUser, undefined, true) await updateMyUser({
url: server.url,
accessToken: accessTokenUser,
displayNSFW: true
})
const res = await getMyUserInformation(server.url, accessTokenUser) const res = await getMyUserInformation(server.url, accessTokenUser)
const user = res.body const user = res.body
@ -416,7 +405,11 @@ describe('Test users', function () {
}) })
it('Should be able to change the autoPlayVideo attribute', async function () { it('Should be able to change the autoPlayVideo attribute', async function () {
await updateMyUser(server.url, accessTokenUser, undefined, undefined, undefined, false) await updateMyUser({
url: server.url,
accessToken: accessTokenUser,
autoPlayVideo: false
})
const res = await getMyUserInformation(server.url, accessTokenUser) const res = await getMyUserInformation(server.url, accessTokenUser)
const user = res.body const user = res.body
@ -425,7 +418,11 @@ describe('Test users', function () {
}) })
it('Should be able to change the email display attribute', async function () { it('Should be able to change the email display attribute', async function () {
await updateMyUser(server.url, accessTokenUser, undefined, undefined, 'updated@example.com') await updateMyUser({
url: server.url,
accessToken: accessTokenUser,
email: 'updated@example.com'
})
const res = await getMyUserInformation(server.url, accessTokenUser) const res = await getMyUserInformation(server.url, accessTokenUser)
const user = res.body const user = res.body
@ -447,7 +444,14 @@ describe('Test users', function () {
}) })
it('Should be able to update another user', async function () { it('Should be able to update another user', async function () {
await updateUser(server.url, userId, accessToken, 'updated2@example.com', 42, UserRole.MODERATOR) await updateUser({
url: server.url,
userId,
accessToken,
email: 'updated2@example.com',
videoQuota: 42,
role: UserRole.MODERATOR
})
const res = await getUserInformation(server.url, accessToken, userId) const res = await getUserInformation(server.url, accessToken, userId)
const user = res.body const user = res.body

View File

@ -10,7 +10,7 @@ function addVideoToBlacklist (url: string, token: string, videoId: number, speci
.expect(specialStatus) .expect(specialStatus)
} }
function removeVideoFromBlacklist (url: string, token: string, videoId: number, specialStatus = 204) { function removeVideoFromBlacklist (url: string, token: string, videoId: number | string, specialStatus = 204) {
const path = '/api/v1/videos/' + videoId + '/blacklist' const path = '/api/v1/videos/' + videoId + '/blacklist'
return request(url) return request(url)

View File

@ -20,13 +20,13 @@ function getVideoChannelsList (url: string, start: number, count: number, sort?:
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
} }
function getAccountVideoChannelsList (url: string, accountId: number | string) { function getAccountVideoChannelsList (url: string, accountId: number | string, specialStatus = 200) {
const path = '/api/v1/videos/accounts/' + accountId + '/channels' const path = '/api/v1/videos/accounts/' + accountId + '/channels'
return request(url) return request(url)
.get(path) .get(path)
.set('Accept', 'application/json') .set('Accept', 'application/json')
.expect(200) .expect(specialStatus)
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
} }

View File

@ -143,7 +143,7 @@ function getVideosListSort (url: string, sort: string) {
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
} }
function removeVideo (url: string, token: string, id: number, expectedStatus = 204) { function removeVideo (url: string, token: string, id: number | string, expectedStatus = 204) {
const path = '/api/v1/videos' const path = '/api/v1/videos'
return request(url) return request(url)