From 6b738c7a31591a83fdcd9c78b6b1f98e543c378b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 25 Apr 2018 10:21:38 +0200 Subject: Video channel API routes refractor --- server/tests/api/check-params/video-channels.ts | 73 ++++++++++--------------- server/tests/api/check-params/videos.ts | 73 ++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 47 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index acb6bdd57..25b2dc9b9 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -7,7 +7,7 @@ import { createUser, deleteVideoChannel, flushTests, - getAccountVideoChannelsList, + getAccountVideoChannelsList, getMyUserInformation, getVideoChannelsList, immutableAssign, killallServers, @@ -21,6 +21,7 @@ import { } from '../../utils' import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' import { getAccountsList } from '../../utils/users/accounts' +import { User } from '../../../../shared/models/users' const expect = chai.expect @@ -29,6 +30,8 @@ describe('Test videos API validator', function () { const accountPath = '/api/v1/accounts/' let server: ServerInfo let accessTokenUser: string + let accountUUID: string + let videoChannelUUID: string // --------------------------------------------------------------- @@ -45,8 +48,18 @@ describe('Test videos API validator', function () { username: 'fake', password: 'fake_password' } - await createUser(server.url, server.accessToken, user.username, user.password) - accessTokenUser = await userLogin(server, user) + + { + await createUser(server.url, server.accessToken, user.username, user.password) + accessTokenUser = await userLogin(server, user) + } + + { + const res = await getMyUserInformation(server.url, server.accessToken) + const user: User = res.body + accountUUID = user.account.uuid + videoChannelUUID = user.videoChannels[0].uuid + } }) describe('When listing a video channels', function () { @@ -74,18 +87,15 @@ describe('Test videos API validator', function () { }) describe('When adding a video channel', function () { - let path: string - const baseCorrectParams = { name: 'hello', description: 'super description', support: 'super support text' } + let path: string before(async function () { - const res = await getAccountsList(server.url) - const accountId = res.body.data[0].id - path = accountPath + accountId + '/video-channels' + path = accountPath + accountUUID + '/video-channels' }) it('Should fail with a non authenticated user', async function () { @@ -129,21 +139,14 @@ describe('Test videos API validator', function () { }) describe('When updating a video channel', function () { - let path: string - const baseCorrectParams = { name: 'hello', description: 'super description' } + let path: string before(async function () { - const res1 = await getVideoChannelsList(server.url, 0, 1) - const videoChannelId = res1.body.data[0].id - - const res2 = await getAccountsList(server.url) - const accountId = res2.body.data[0].id - - path = accountPath + accountId + '/video-channels/' + videoChannelId + path = accountPath + accountUUID + '/video-channels/' + videoChannelUUID }) it('Should fail with a non authenticated user', async function () { @@ -194,16 +197,9 @@ describe('Test videos API validator', function () { describe('When getting a video channel', function () { let basePath: string - let videoChannelId: number before(async function () { - const res1 = await getVideoChannelsList(server.url, 0, 1) - videoChannelId = res1.body.data[0].id - - const res2 = await getAccountsList(server.url) - const accountId = res2.body.data[0].id - - basePath = accountPath + accountId + '/video-channels' + basePath = accountPath + accountUUID + '/video-channels' }) it('Should return the list of the video channels with nothing', async function () { @@ -235,49 +231,38 @@ describe('Test videos API validator', function () { it('Should succeed with the correct parameters', async function () { await makeGetRequest({ url: server.url, - path: basePath + '/' + videoChannelId, + path: basePath + '/' + videoChannelUUID, statusCodeExpected: 200 }) }) }) describe('When deleting a video channel', function () { - let videoChannelId: number - let accountId: number - - before(async function () { - const res1 = await getVideoChannelsList(server.url, 0, 1) - videoChannelId = res1.body.data[0].id - - const res2 = await getAccountsList(server.url) - accountId = res2.body.data[0].id - }) - it('Should fail with a non authenticated user', async function () { - await deleteVideoChannel(server.url, 'coucou', accountId, videoChannelId, 401) + await deleteVideoChannel(server.url, 'coucou', accountUUID, videoChannelUUID, 401) }) it('Should fail with another authenticated user', async function () { - await deleteVideoChannel(server.url, accessTokenUser, accountId, videoChannelId, 403) + await deleteVideoChannel(server.url, accessTokenUser, accountUUID, videoChannelUUID, 403) }) it('Should fail with an unknown account id', async function () { - await deleteVideoChannel(server.url, server.accessToken, 454554,videoChannelId, 404) + await deleteVideoChannel(server.url, server.accessToken, 454554,videoChannelUUID, 404) }) it('Should fail with an unknown video channel id', async function () { - await deleteVideoChannel(server.url, server.accessToken, accountId,454554, 404) + await deleteVideoChannel(server.url, server.accessToken, accountUUID,454554, 404) }) it('Should succeed with the correct parameters', async function () { - await deleteVideoChannel(server.url, server.accessToken, accountId, videoChannelId) + await deleteVideoChannel(server.url, server.accessToken, accountUUID, videoChannelUUID) }) 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 + const lastVideoChannelUUID = res.body.data[0].uuid - await deleteVideoChannel(server.url, server.accessToken, accountId, videoChannelId, 409) + await deleteVideoChannel(server.url, server.accessToken, accountUUID, lastVideoChannelUUID, 409) }) }) diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index da41f515b..850ad12e0 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -10,6 +10,7 @@ import { makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin } from '../../utils' import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' +import { getAccountsList } from '../../utils/users/accounts' const expect = chai.expect @@ -17,7 +18,9 @@ describe('Test videos API validator', function () { const path = '/api/v1/videos/' let server: ServerInfo let userAccessToken = '' + let accountUUID: string let channelId: number + let channelUUID: string let videoId // --------------------------------------------------------------- @@ -36,8 +39,12 @@ describe('Test videos API validator', function () { await createUser(server.url, server.accessToken, username, password) userAccessToken = await userLogin(server, { username, password }) - const res = await getMyUserInformation(server.url, server.accessToken) - channelId = res.body.videoChannels[0].id + { + const res = await getMyUserInformation(server.url, server.accessToken) + channelId = res.body.videoChannels[ 0 ].id + channelUUID = res.body.videoChannels[ 0 ].uuid + accountUUID = res.body.account.uuid + } }) describe('When listing a video', function () { @@ -52,6 +59,10 @@ describe('Test videos API validator', function () { it('Should fail with an incorrect sort', async function () { await checkBadSortPagination(server.url, path) }) + + it('Should success with the correct parameters', async function () { + await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) + }) }) describe('When searching a video', function () { @@ -75,6 +86,10 @@ describe('Test videos API validator', function () { it('Should fail with an incorrect sort', async function () { await checkBadSortPagination(server.url, join(path, 'search', 'test')) }) + + it('Should success with the correct parameters', async function () { + await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) + }) }) describe('When listing my videos', function () { @@ -91,6 +106,58 @@ describe('Test videos API validator', function () { it('Should fail with an incorrect sort', async function () { await checkBadSortPagination(server.url, path, server.accessToken) }) + + it('Should success with the correct parameters', async function () { + await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 }) + }) + }) + + describe('When listing account videos', function () { + let path: string + + before(async function () { + path = '/api/v1/accounts/' + accountUUID + '/videos' + }) + + it('Should fail with a bad start pagination', async function () { + await checkBadStartPagination(server.url, path, server.accessToken) + }) + + it('Should fail with a bad count pagination', async function () { + await checkBadCountPagination(server.url, path, server.accessToken) + }) + + it('Should fail with an incorrect sort', async function () { + await checkBadSortPagination(server.url, path, server.accessToken) + }) + + it('Should success with the correct parameters', async function () { + await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) + }) + }) + + describe('When listing video channel videos', function () { + let path: string + + before(async function () { + path = '/api/v1/accounts/' + accountUUID + '/video-channels/' + channelUUID + '/videos' + }) + + it('Should fail with a bad start pagination', async function () { + await checkBadStartPagination(server.url, path, server.accessToken) + }) + + it('Should fail with a bad count pagination', async function () { + await checkBadCountPagination(server.url, path, server.accessToken) + }) + + it('Should fail with an incorrect sort', async function () { + await checkBadSortPagination(server.url, path, server.accessToken) + }) + + it('Should success with the correct parameters', async function () { + await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) + }) }) describe('When adding a video', function () { @@ -112,7 +179,7 @@ describe('Test videos API validator', function () { support: 'my super support text', tags: [ 'tag1', 'tag2' ], privacy: VideoPrivacy.PUBLIC, - channelId + channelId: channelId } }) -- cgit v1.2.3