From 11ba2ab3f1e3ec29b3765fa0c1ff4ed410c851a9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 28 Dec 2017 16:26:28 +0100 Subject: [PATCH] Improve check videos parameters tests --- server/tests/api/check-params/follows.ts | 1 - server/tests/api/check-params/jobs.ts | 3 +- server/tests/api/check-params/video-abuses.ts | 84 ++-- .../tests/api/check-params/video-blacklist.ts | 109 +---- .../tests/api/check-params/video-channels.ts | 206 ++++------ .../tests/api/check-params/video-comments.ts | 64 ++- server/tests/api/check-params/videos.ts | 374 +++++++----------- server/tests/api/users/users.ts | 60 +-- server/tests/utils/videos/video-blacklist.ts | 2 +- server/tests/utils/videos/video-channels.ts | 4 +- server/tests/utils/videos/videos.ts | 2 +- 11 files changed, 332 insertions(+), 577 deletions(-) diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index d5fcb7477..e54f139f0 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts @@ -1,7 +1,6 @@ /* tslint:disable:no-unused-expression */ import 'mocha' -import * as request from 'supertest' import { createUser, flushTests, killallServers, makeDeleteRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts index 46b05cb4e..b12818bb1 100644 --- a/server/tests/api/check-params/jobs.ts +++ b/server/tests/api/check-params/jobs.ts @@ -1,9 +1,8 @@ /* tslint:disable:no-unused-expression */ 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 { makeGetRequest } from '../../utils/requests/requests' diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts index e994ccd49..68e2ce786 100644 --- a/server/tests/api/check-params/video-abuses.ts +++ b/server/tests/api/check-params/video-abuses.ts @@ -1,20 +1,12 @@ /* tslint:disable:no-unused-expression */ -import * as request from 'supertest' import 'mocha' import { - ServerInfo, - flushTests, - runServer, - uploadVideo, - getVideosList, - createUser, - setAccessTokensToServers, - killallServers, - makePostBodyRequest, - userLogin + createUser, flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, + uploadVideo, userLogin } from '../../utils' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' describe('Test video abuses API validators', function () { let server: ServerInfo @@ -34,63 +26,42 @@ describe('Test video abuses API validators', function () { const username = 'user1' const password = 'my super password' await createUser(server.url, server.accessToken, username, password) - userAccessToken = await userLogin(server, { username, password }) - // Upload a video - const videoAttributes = {} - await uploadVideo(server.url, server.accessToken, videoAttributes) - - const res = await getVideosList(server.url) - const videos = res.body.data - server.video = videos[0] + const res = await uploadVideo(server.url, server.accessToken, {}) + server.video = res.body.video }) describe('When listing video abuses', function () { const path = '/api/v1/videos/abuse' it('Should fail with a bad start pagination', async function () { - await request(server.url) - .get(path) - .query({ start: 'hello' }) - .set('Authorization', 'Bearer ' + server.accessToken) - .set('Accept', 'application/json') - .expect(400) + await checkBadStartPagination(server.url, path, server.accessToken) }) it('Should fail with a bad count pagination', async function () { - await request(server.url) - .get(path) - .query({ count: 'hello' }) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400) + await checkBadCountPagination(server.url, path, server.accessToken) }) it('Should fail with an incorrect sort', async function () { - await request(server.url) - .get(path) - .query({ sort: 'hello' }) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400) + await checkBadSortPagination(server.url, path, server.accessToken) }) it('Should fail with a non authenticated user', async function () { - await request(server.url) - .get(path) - .query({ sort: 'hello' }) - .set('Accept', 'application/json') - .expect(401) + await makeGetRequest({ + url: server.url, + path, + statusCodeExpected: 401 + }) }) it('Should fail with a non admin user', async function () { - await request(server.url) - .get(path) - .query({ sort: 'hello' }) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + userAccessToken) - .expect(403) + await makeGetRequest({ + url: server.url, + path, + token: userAccessToken, + statusCodeExpected: 403 + }) }) }) @@ -105,32 +76,33 @@ describe('Test video abuses API validators', function () { it('Should fail with a wrong video', async function () { 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 }) }) it('Should fail with a non authenticated user', async function () { - const fields = {} const path = basePath + server.video.id + '/abuse' + const fields = { + reason: 'my super reason' + } await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) }) it('Should fail with a reason too short', async function () { + const path = basePath + server.video.id + '/abuse' const fields = { reason: 'h' } - const path = basePath + server.video.id + '/abuse' await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a reason too big', async function () { + const path = basePath + server.video.id + '/abuse' const fields = { - reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + - '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + - '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + - '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + reason: 'super'.repeat(61) } - const path = basePath + server.video.id + '/abuse' await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) }) diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index c8b457182..6cd13d23f 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts @@ -1,20 +1,12 @@ /* tslint:disable:no-unused-expression */ import 'mocha' -import * as request from 'supertest' import { - ServerInfo, - flushTests, - runServer, - uploadVideo, - getVideosList, - createUser, - setAccessTokensToServers, - killallServers, - makePostBodyRequest, - userLogin + createUser, flushTests, getBlacklistedVideosList, killallServers, makePostBodyRequest, removeVideoFromBlacklist, runServer, + ServerInfo, setAccessTokensToServers, uploadVideo, userLogin } from '../../utils' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' describe('Test video blacklist API validators', function () { let server: ServerInfo @@ -36,14 +28,8 @@ describe('Test video blacklist API validators', function () { await createUser(server.url, server.accessToken, username, password) userAccessToken = await userLogin(server, { username, password }) - // Upload a video - const videoAttributes = {} - await uploadVideo(server.url, server.accessToken, videoAttributes) - - const res = await getVideosList(server.url) - - const videos = res.body.data - server.video = videos[0] + const res = await uploadVideo(server.url, server.accessToken, {}) + server.video = res.body.video }) 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 () { - const fields = {} const path = basePath + server.video + '/blacklist' + const fields = {} await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) }) it('Should fail with a non admin user', async function () { - const fields = {} const path = basePath + server.video + '/blacklist' + const fields = {} await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) }) it('Should fail with a local video', async function () { - const fields = {} const path = basePath + server.video.id + '/blacklist' + const fields = {} await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 }) }) }) describe('When removing a video in blacklist', function () { - const basePath = '/api/v1/videos/' - it('Should fail with a non authenticated user', async function () { - const path = basePath + server.video.id + '/blacklist' - - await request(server.url) - .delete(path) - .set('Authorization', 'Bearer ' + 'fake token') - .set('Accept', 'application/json') - .expect(401) + await removeVideoFromBlacklist(server.url, 'fake token', server.video.id, 401) }) it('Should fail with a non admin user', async function () { - const path = basePath + server.video.id + '/blacklist' - - await request(server.url) - .delete(path) - .set('Authorization', 'Bearer ' + userAccessToken) - .set('Accept', 'application/json') - .expect(403) + await removeVideoFromBlacklist(server.url, userAccessToken, server.video.id, 403) }) it('Should fail with an incorrect id', async function () { - const path = basePath + 'foobar/blacklist' - - await request(server.url) - .delete(path) - .set('Authorization', 'Bearer ' + server.accessToken) - .set('Accept', 'application/json') - .expect(400) + await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400) }) it('Should fail with a not blacklisted video', async function () { // The video was not added to the blacklist so it should fail - const path = basePath + server.video.id + '/blacklist' - - await request(server.url) - .delete(path) - .set('Authorization', 'Bearer ' + server.accessToken) - .set('Accept', 'application/json') - .expect(404) + await removeVideoFromBlacklist(server.url, server.accessToken, server.video.id, 404) }) }) @@ -129,58 +89,23 @@ describe('Test video blacklist API validators', function () { const basePath = '/api/v1/videos/blacklist/' it('Should fail with a non authenticated user', async function () { - const path = basePath - - await request(server.url) - .get(path) - .query({ sort: 'createdAt' }) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + 'fake token') - .expect(401) + await getBlacklistedVideosList(server.url, 'fake token', 401) }) it('Should fail with a non admin user', async function () { - const path = basePath - - await request(server.url) - .get(path) - .query({ sort: 'createdAt' }) - .set('Authorization', 'Bearer ' + userAccessToken) - .set('Accept', 'application/json') - .expect(403) + await getBlacklistedVideosList(server.url, userAccessToken, 403) }) it('Should fail with a bad start pagination', async function () { - const path = basePath - - await request(server.url) - .get(path) - .query({ start: 'foobar' }) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400) + await checkBadStartPagination(server.url, basePath, server.accessToken) }) it('Should fail with a bad count pagination', async function () { - const path = basePath - - await request(server.url) - .get(path) - .query({ count: 'foobar' }) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400) + await checkBadCountPagination(server.url, basePath, server.accessToken) }) it('Should fail with an incorrect sort', async function () { - const path = basePath - - await request(server.url) - .get(path) - .query({ sort: 'foobar' }) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400) + await checkBadSortPagination(server.url, basePath, server.accessToken) }) }) diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index bf464152b..22e98d110 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -1,22 +1,15 @@ /* tslint:disable:no-unused-expression */ -import * as request from 'supertest' -import 'mocha' import * as chai from 'chai' -const expect = chai.expect - +import { omit } from 'lodash' +import 'mocha' import { - ServerInfo, - flushTests, - runServer, - makePutBodyRequest, - setAccessTokensToServers, - killallServers, - makePostBodyRequest, - getVideoChannelsList, - createUser, - userLogin + createUser, deleteVideoChannel, flushTests, getAccountVideoChannelsList, getVideoChannelsList, immutableAssign, killallServers, + makeGetRequest, makePostBodyRequest, makePutBodyRequest, 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 () { const path = '/api/v1/videos/channels' @@ -39,64 +32,41 @@ describe('Test videos API validator', function () { password: 'fake_password' } await createUser(server.url, server.accessToken, user.username, user.password) - accessTokenUser = await userLogin(server, user) }) describe('When listing a video channels', function () { it('Should fail with a bad start pagination', async function () { - await request(server.url) - .get(path) - .query({ start: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadStartPagination(server.url, path, server.accessToken) }) it('Should fail with a bad count pagination', async function () { - await request(server.url) - .get(path) - .query({ count: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadCountPagination(server.url, path, server.accessToken) }) it('Should fail with an incorrect sort', async function () { - await request(server.url) - .get(path) - .query({ sort: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadSortPagination(server.url, path, server.accessToken) }) }) describe('When listing account video channels', function () { it('Should fail with bad account', async function () { - const path = '/api/v1/videos/accounts/hello/channels' - - await request(server.url) - .get(path) - .set('Accept', 'application/json') - .expect(400) + await getAccountVideoChannelsList(server.url, 'hello', 400) }) it('Should fail with a unknown account', async function () { - const path = '/api/v1/videos/accounts/156/channels' - - await request(server.url) - .get(path) - .set('Accept', 'application/json') - .expect(404) + await getAccountVideoChannelsList(server.url, 154, 404) }) }) describe('When adding a video channel', function () { + const baseCorrectParams = { + name: 'hello', + description: 'super description' + } it('Should fail with a non authenticated user', async function () { - const fields = { - name: 'hello', - description: 'super description' - } - await makePostBodyRequest({ url: server.url, path, token: 'none', fields, statusCodeExpected: 401 }) + await makePostBodyRequest({ url: server.url, path, token: 'none', fields: baseCorrectParams, statusCodeExpected: 401 }) }) it('Should fail with nothing', async function () { @@ -105,45 +75,37 @@ describe('Test videos API validator', function () { }) it('Should fail without name', async function () { - const fields = { - description: 'super description' - } + const fields = omit(baseCorrectParams, 'name') await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long name', async function () { - const fields = { - name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + - 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + - 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + - 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + - 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long', - description: 'super description' - } + const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) }) await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { - const fields = { - name: 'hello', - description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + - 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' + - 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + - 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description' - } + const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) }) await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should succeed with the correct parameters', async function () { - const fields = { - name: 'hello', - description: 'super description' - } - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) + await makePostBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields: baseCorrectParams, + statusCodeExpected: 204 + }) }) }) describe('When updating a video channel', function () { + const baseCorrectParams = { + name: 'hello', + description: 'super description' + } + let videoChannelId before(async function () { @@ -152,60 +114,41 @@ describe('Test videos API validator', function () { }) it('Should fail with a non authenticated user', async function () { - const fields = { - name: 'hello', - description: 'super description' - } - await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: 'hi', fields, statusCodeExpected: 401 }) + await makePutBodyRequest({ + url: server.url, + path: path + '/' + videoChannelId, + token: 'hi', + fields: baseCorrectParams, + statusCodeExpected: 401 + }) }) it('Should fail with another authenticated user', async function () { - const fields = { - name: 'hello', - description: 'super description' - } await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: accessTokenUser, - fields, + fields: baseCorrectParams, statusCodeExpected: 403 }) }) it('Should fail with a long name', async function () { - const fields = { - name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + - 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + - 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + - 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + - 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long', - description: 'super description' - } + const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) }) await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { - const fields = { - name: 'hello', - description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + - 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' + - 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' + - 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description' - } + const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) }) await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields }) }) it('Should succeed with the correct parameters', async function () { - const fields = { - name: 'hello 2', - description: 'super description 2' - } await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, - fields, + fields: baseCorrectParams, 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 () { - const res = await request(server.url) - .get(path) - .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) + const res = await makeGetRequest({ + url: server.url, + path, + statusCodeExpected: 200 + }) expect(res.body.data).to.be.an('array') }) it('Should fail without a correct uuid', async function () { - await request(server.url) - .get(path + '/coucou') - .set('Accept', 'application/json') - .expect(400) + await makeGetRequest({ + url: server.url, + path: path + '/coucou', + statusCodeExpected: 400 + }) }) it('Should return 404 with an incorrect video channel', async function () { - await request(server.url) - .get(path + '/4da6fde3-88f7-4d16-b119-108df5630b06') - .set('Accept', 'application/json') - .expect(404) + await makeGetRequest({ + url: server.url, + path: path + '/4da6fde3-88f7-4d16-b119-108df5630b06', + statusCodeExpected: 404 + }) }) it('Should succeed with the correct parameters', async function () { - await request(server.url) - .get(path + '/' + videoChannelId) - .set('Accept', 'application/json') - .expect(200) + await makeGetRequest({ + url: server.url, + path: path + '/' + videoChannelId, + statusCodeExpected: 200 + }) }) }) @@ -260,42 +206,26 @@ describe('Test videos API validator', function () { }) it('Should fail with a non authenticated user', async function () { - await request(server.url) - .delete(path + '/' + videoChannelId) - .set('Authorization', 'Bearer coucou') - .expect(401) + await deleteVideoChannel(server.url, 'coucou', videoChannelId, 401) }) it('Should fail with another authenticated user', async function () { - await request(server.url) - .delete(path + '/' + videoChannelId) - .set('Authorization', 'Bearer ' + accessTokenUser) - .expect(403) + await deleteVideoChannel(server.url, accessTokenUser, videoChannelId, 403) }) it('Should fail with an unknown id', async function () { - await request(server.url) - .delete(path + '/454554') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(404) + await deleteVideoChannel(server.url, server.accessToken, 454554, 404) }) it('Should succeed with the correct parameters', async function () { - await request(server.url) - .delete(path + '/' + videoChannelId) - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(204) + await deleteVideoChannel(server.url, server.accessToken, videoChannelId) }) it('Should fail to delete the last user video channel', async function () { const res = await getVideoChannelsList(server.url, 0, 1) videoChannelId = res.body.data[0].id - await request(server.url) - .delete(path + '/' + videoChannelId) - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(409 - ) + await deleteVideoChannel(server.url, server.accessToken, videoChannelId, 409) }) }) diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index f3832bd2c..cdb48a276 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -1,8 +1,11 @@ /* tslint:disable:no-unused-expression */ import 'mocha' -import * as request from 'supertest' -import { flushTests, killallServers, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils' +import { + 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' 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 () { it('Should fail with a bad start pagination', async function () { - await request(server.url) - .get(pathThread) - .query({ start: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadStartPagination(server.url, pathThread, server.accessToken) + }) it('Should fail with a bad count pagination', async function () { - await request(server.url) - .get(pathThread) - .query({ count: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadCountPagination(server.url, pathThread, server.accessToken) + }) it('Should fail with an incorrect sort', async function () { - await request(server.url) - .get(pathThread) - .query({ sort: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadSortPagination(server.url, pathThread, server.accessToken) + }) it('Should fail with an incorrect video', async function () { - await request(server.url) - .get('/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads') - .set('Accept', 'application/json') - .expect(404) + await makeGetRequest({ + url: server.url, + path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads', + statusCodeExpected: 404 + }) }) }) describe('When listing comments of a thread', function () { it('Should fail with an incorrect video', async function () { - await request(server.url) - .get('/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId) - .set('Accept', 'application/json') - .expect(404) + await makeGetRequest({ + url: server.url, + path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId, + statusCodeExpected: 404 + }) }) it('Should fail with an incorrect thread id', async function () { - await request(server.url) - .get('/api/v1/videos/' + videoUUID + '/comment-threads/156') - .set('Accept', 'application/json') - .expect(404) + await makeGetRequest({ + url: server.url, + path: '/api/v1/videos/' + videoUUID + '/comment-threads/156', + statusCodeExpected: 404 + }) }) it('Should success with the correct params', async function () { - await request(server.url) - .get('/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId) - .set('Accept', 'application/json') - .expect(200) + await makeGetRequest({ + url: server.url, + path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId, + statusCodeExpected: 200 + }) }) }) diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index b0c850f0c..b9484afc4 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -1,64 +1,23 @@ /* tslint:disable:no-unused-expression */ -import * as request from 'supertest' -import { join } from 'path' -import 'mocha' import * as chai from 'chai' -const expect = chai.expect - +import { omit } from 'lodash' +import 'mocha' +import { join } from 'path' +import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' import { - ServerInfo, - flushTests, - runServer, - getVideosList, - makePutBodyRequest, - setAccessTokensToServers, - killallServers, - makePostUploadRequest, - getMyUserInformation, - createUser, - userLogin + createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest, + makeGetRequest, makePostUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin } from '../../utils' -import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' + +const expect = chai.expect describe('Test videos API validator', function () { const path = '/api/v1/videos/' let server: ServerInfo 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 () { @@ -76,60 +35,38 @@ describe('Test videos API validator', function () { describe('When listing a video', function () { it('Should fail with a bad start pagination', async function () { - await request(server.url) - .get(path) - .query({ start: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadStartPagination(server.url, path) }) it('Should fail with a bad count pagination', async function () { - await request(server.url) - .get(path) - .query({ count: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadCountPagination(server.url, path) }) it('Should fail with an incorrect sort', async function () { - await request(server.url) - .get(path) - .query({ sort: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadSortPagination(server.url, path) }) }) describe('When searching a video', function () { + it('Should fail with nothing', async function () { - await request(server.url) - .get(join(path, 'search')) - .set('Accept', 'application/json') - .expect(400) + await makeGetRequest({ + url: server.url, + path: join(path, 'search'), + statusCodeExpected: 400 + }) }) it('Should fail with a bad start pagination', async function () { - await request(server.url) - .get(join(path, 'search', 'test')) - .query({ start: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadStartPagination(server.url, join(path, 'search', 'test')) }) it('Should fail with a bad count pagination', async function () { - await request(server.url) - .get(join(path, 'search', 'test')) - .query({ count: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadCountPagination(server.url, join(path, 'search', 'test')) }) it('Should fail with an incorrect sort', async function () { - await request(server.url) - .get(join(path, 'search', 'test')) - .query({ sort: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadSortPagination(server.url, join(path, 'search', 'test')) }) }) @@ -137,34 +74,39 @@ describe('Test videos API validator', function () { const path = '/api/v1/users/me/videos' it('Should fail with a bad start pagination', async function () { - await request(server.url) - .get(path) - .set('Authorization', 'Bearer ' + server.accessToken) - .query({ start: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadStartPagination(server.url, path, server.accessToken) }) it('Should fail with a bad count pagination', async function () { - await request(server.url) - .get(path) - .set('Authorization', 'Bearer ' + server.accessToken) - .query({ count: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadCountPagination(server.url, path, server.accessToken) }) it('Should fail with an incorrect sort', async function () { - await request(server.url) - .get(path) - .set('Authorization', 'Bearer ' + server.accessToken) - .query({ sort: 'hello' }) - .set('Accept', 'application/json') - .expect(400) + await checkBadSortPagination(server.url, path, server.accessToken) }) }) 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 () { const fields = {} const attaches = {} @@ -172,84 +114,72 @@ describe('Test videos API validator', function () { }) it('Should fail without name', async function () { - const fields = getCompleteVideoUploadAttributes() - delete fields.name + const fields = omit(baseCorrectParams, 'name') + const attaches = baseCorrectAttaches - const attaches = getVideoUploadAttaches() await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a long name', async function () { - const fields = getCompleteVideoUploadAttributes() - fields.name = 'My very very very very very very very very very very very very very very very very very ' + - '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 fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) + const attaches = baseCorrectAttaches - const attaches = getVideoUploadAttaches await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a bad category', async function () { - const fields = getCompleteVideoUploadAttributes() - fields.category = 125 + const fields = immutableAssign(baseCorrectParams, { category: 125 }) + const attaches = baseCorrectAttaches - const attaches = getVideoUploadAttaches await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a bad licence', async function () { - const fields = getCompleteVideoUploadAttributes() - fields.licence = 125 + const fields = immutableAssign(baseCorrectParams, { licence: 125 }) + const attaches = baseCorrectAttaches - const attaches = getVideoUploadAttaches() await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a bad language', async function () { - const fields = getCompleteVideoUploadAttributes() - fields.language = 563 + const fields = immutableAssign(baseCorrectParams, { language: 125 }) + const attaches = baseCorrectAttaches - const attaches = getVideoUploadAttaches() await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail without nsfw attribute', async function () { - const fields = getCompleteVideoUploadAttributes() - delete fields.nsfw + const fields = omit(baseCorrectParams, 'nsfw') + const attaches = baseCorrectAttaches - const attaches = getVideoUploadAttaches() await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a bad nsfw attribute', async function () { - const fields = getCompleteVideoUploadAttributes() - fields.nsfw = 2 as any + const fields = immutableAssign(baseCorrectParams, { nsfw: 2 }) + const attaches = baseCorrectAttaches - const attaches = getVideoUploadAttaches() await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a long description', async function () { - const fields = getCompleteVideoUploadAttributes() - fields.description = 'my super description which is very very very very very very very very very very very very long'.repeat(35) + const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) }) + const attaches = baseCorrectAttaches - const attaches = getVideoUploadAttaches() await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail without a channel', async function () { - const fields = getCompleteVideoUploadAttributes() - delete fields.channelId + const fields = omit(baseCorrectParams, 'channelId') + const attaches = baseCorrectAttaches - const attaches = getVideoUploadAttaches() await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a bad channel', async function () { - const fields = getCompleteVideoUploadAttributes() - fields.channelId = 545454 + const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) + const attaches = baseCorrectAttaches - const attaches = getVideoUploadAttaches() 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 customChannelId = res.body.videoChannels[0].id - const fields = getCompleteVideoUploadAttributes() - fields.channelId = customChannelId + const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) + const attaches = baseCorrectAttaches - const attaches = getVideoUploadAttaches() await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with too many tags', async function () { - const fields = getCompleteVideoUploadAttributes() - fields.tags = [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] + const fields = immutableAssign(baseCorrectParams, { 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 }) }) it('Should fail with a tag length too low', async function () { - const fields = getCompleteVideoUploadAttributes() - fields.tags = [ 'tag1', 't' ] + const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) + const attaches = baseCorrectAttaches - const attaches = getVideoUploadAttaches() await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a tag length too big', async function () { - const fields = getCompleteVideoUploadAttributes() - fields.tags = [ 'my_super_tag_too_long_long_long_long_long_long', 'tag1' ] + const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) + const attaches = baseCorrectAttaches - const attaches = getVideoUploadAttaches() await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail without an input file', async function () { - const fields = getCompleteVideoUploadAttributes() + const fields = baseCorrectParams const attaches = {} await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail without an incorrect input file', async function () { - const fields = getCompleteVideoUploadAttributes() + const fields = baseCorrectParams const attaches = { '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 () { this.timeout(10000) - const fields = getCompleteVideoUploadAttributes() - const attaches = getVideoUploadAttaches() - - await makePostUploadRequest({ - url: server.url, - path: path + '/upload', - token: server.accessToken, - fields, - attaches, - statusCodeExpected: 200 - }) + const fields = baseCorrectParams + + { + const attaches = baseCorrectAttaches + await makePostUploadRequest({ + url: server.url, + path: path + '/upload', + token: server.accessToken, + fields, + attaches, + statusCodeExpected: 200 + }) + } - attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.mp4') - await makePostUploadRequest({ - url: server.url, - path: path + '/upload', - token: server.accessToken, - fields, - attaches, - statusCodeExpected: 200 - }) + { + const attaches = immutableAssign(baseCorrectAttaches, { + videofile: join(__dirname, '..', 'fixtures', 'video_short.mp4') + }) + + await makePostUploadRequest({ + url: server.url, + path: path + '/upload', + token: server.accessToken, + fields, + attaches, + statusCodeExpected: 200 + }) + } - attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.ogv') - await makePostUploadRequest({ - url: server.url, - path: path + '/upload', - token: server.accessToken, - fields, - attaches, - 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 () { + 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 before(async function () { @@ -360,12 +308,12 @@ describe('Test videos API validator', 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 }) }) it('Should fail with an unknown id', async function () { - const fields = getCompleteVideoUpdateAttributes() + const fields = baseCorrectParams await makePutBodyRequest({ url: server.url, @@ -377,64 +325,55 @@ describe('Test videos API validator', function () { }) it('Should fail with a long name', async function () { - const fields = getCompleteVideoUpdateAttributes() - fields.name = 'My very very very very very very very very very very very very very very very very long'.repeat(3) + const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) }) it('Should fail with a bad category', async function () { - const fields = getCompleteVideoUpdateAttributes() - fields.category = 128 + const fields = immutableAssign(baseCorrectParams, { category: 125 }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) }) it('Should fail with a bad licence', async function () { - const fields = getCompleteVideoUpdateAttributes() - fields.licence = 128 + const fields = immutableAssign(baseCorrectParams, { licence: 125 }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) }) it('Should fail with a bad language', async function () { - const fields = getCompleteVideoUpdateAttributes() - fields.language = 896 + const fields = immutableAssign(baseCorrectParams, { language: 125 }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) }) it('Should fail with a bad nsfw attribute', async function () { - const fields = getCompleteVideoUpdateAttributes() - fields.nsfw = (-4 as any) + const fields = immutableAssign(baseCorrectParams, { nsfw: 2 }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { - const fields = getCompleteVideoUpdateAttributes() - fields.description = 'my super description which is very very very very very very very very very very very very very long'.repeat(35) + const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) }) it('Should fail with too many tags', async function () { - const fields = getCompleteVideoUpdateAttributes() - fields.tags = [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] + const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) }) it('Should fail with a tag length too low', async function () { - const fields = getCompleteVideoUpdateAttributes() - fields.tags = [ 'tag1', 't' ] + const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) }) it('Should fail with a tag length too big', async function () { - const fields = getCompleteVideoUpdateAttributes() - fields.tags = [ 'my_super_tag_too_long_long_long_long', 'tag1' ] + const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) 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 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 }) }) @@ -452,28 +391,22 @@ describe('Test videos API validator', function () { describe('When getting a video', function () { it('Should return the list of the videos with nothing', async function () { - const res = await request(server.url) - .get(path) - .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) + const res = await makeGetRequest({ + url: server.url, + path, + statusCodeExpected: 200 + }) expect(res.body.data).to.be.an('array') expect(res.body.data.length).to.equal(3) }) it('Should fail without a correct uuid', async function () { - await request(server.url) - .get(path + 'coucou') - .set('Accept', 'application/json') - .expect(400) + await getVideo(server.url, 'coucou', 400) }) it('Should return 404 with an incorrect video', async function () { - await request(server.url) - .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06') - .set('Accept', 'application/json') - .expect(404) + await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) }) it('Should succeed with the correct parameters') @@ -530,24 +463,19 @@ describe('Test videos API validator', function () { describe('When removing a video', function () { it('Should have 404 with nothing', async function () { - await request(server.url) - .delete(path) - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400) + await makeDeleteRequest({ + url: server.url, + path, + statusCodeExpected: 400 + }) }) it('Should fail without a correct uuid', async function () { - await request(server.url) - .delete(path + 'hello') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400) + await removeVideo(server.url, server.accessToken, 'hello', 400) }) it('Should fail with a video which does not exist', async function () { - await request(server.url) - .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(404) + await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) }) it('Should fail with a video of another user') diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index ec164cadc..b7ec3bc0f 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -4,32 +4,13 @@ import * as chai from 'chai' import 'mocha' import { UserRole } from '../../../../shared/index' import { - createUser, - flushTests, - getBlacklistedVideosList, - getMyUserInformation, - getUserInformation, - getUsersList, - getUsersListPaginationAndSort, - getMyUserVideoRating, - getVideosList, - killallServers, - login, - serverLogin, - makePutBodyRequest, - rateVideo, - registerUser, - removeUser, - removeVideo, - runServer, - ServerInfo, - updateMyUser, - updateUser, - uploadVideo + createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoRating, getUserInformation, getUsersList, + getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo, registerUser, removeUser, removeVideo, + runServer, ServerInfo, serverLogin, updateMyUser, updateUser, uploadVideo } from '../../utils/index' import { follow } from '../../utils/server/follows' -import { getMyVideos } from '../../utils/videos/videos' import { setAccessTokensToServers } from '../../utils/users/login' +import { getMyVideos } from '../../utils/videos/videos' const expect = chai.expect @@ -387,14 +368,22 @@ describe('Test users', 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' await login(server.url, server.client, server.user, 200) }) 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 user = res.body @@ -416,7 +405,11 @@ describe('Test users', 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 user = res.body @@ -425,7 +418,11 @@ describe('Test users', 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 user = res.body @@ -447,7 +444,14 @@ describe('Test users', 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 user = res.body diff --git a/server/tests/utils/videos/video-blacklist.ts b/server/tests/utils/videos/video-blacklist.ts index 3a499f46a..aa0d232b6 100644 --- a/server/tests/utils/videos/video-blacklist.ts +++ b/server/tests/utils/videos/video-blacklist.ts @@ -10,7 +10,7 @@ function addVideoToBlacklist (url: string, token: string, videoId: number, speci .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' return request(url) diff --git a/server/tests/utils/videos/video-channels.ts b/server/tests/utils/videos/video-channels.ts index 0fb80d331..062ca8f4d 100644 --- a/server/tests/utils/videos/video-channels.ts +++ b/server/tests/utils/videos/video-channels.ts @@ -20,13 +20,13 @@ function getVideoChannelsList (url: string, start: number, count: number, sort?: .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' return request(url) .get(path) .set('Accept', 'application/json') - .expect(200) + .expect(specialStatus) .expect('Content-Type', /json/) } diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index fefee4878..166253ffc 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts @@ -143,7 +143,7 @@ function getVideosListSort (url: string, sort: string) { .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' return request(url) -- 2.41.0