From cc918ac3f45e32f031cce7b6e0473e5c2c34b8ae Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 25 Apr 2018 16:15:39 +0200 Subject: Update video-channel routes (again) Use /video-channels now, it's more simple for clients --- server/tests/api/check-params/video-channels.ts | 58 ++++++++++--------------- server/tests/api/videos/video-channels.ts | 10 ++--- server/tests/api/videos/video-nsfw.ts | 4 +- server/tests/utils/videos/video-channels.ts | 14 +++--- server/tests/utils/videos/videos.ts | 3 +- 5 files changed, 37 insertions(+), 52 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 25b2dc9b9..7cda879ed 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -27,10 +27,8 @@ const expect = chai.expect describe('Test videos API validator', function () { const videoChannelPath = '/api/v1/video-channels' - const accountPath = '/api/v1/accounts/' let server: ServerInfo let accessTokenUser: string - let accountUUID: string let videoChannelUUID: string // --------------------------------------------------------------- @@ -57,7 +55,6 @@ describe('Test videos API validator', function () { { const res = await getMyUserInformation(server.url, server.accessToken) const user: User = res.body - accountUUID = user.account.uuid videoChannelUUID = user.videoChannels[0].uuid } }) @@ -92,45 +89,46 @@ describe('Test videos API validator', function () { description: 'super description', support: 'super support text' } - let path: string - - before(async function () { - path = accountPath + accountUUID + '/video-channels' - }) it('Should fail with a non authenticated user', async function () { - await makePostBodyRequest({ url: server.url, path, token: 'none', fields: baseCorrectParams, statusCodeExpected: 401 }) + await makePostBodyRequest({ + url: server.url, + path: videoChannelPath, + token: 'none', + fields: baseCorrectParams, + statusCodeExpected: 401 + }) }) it('Should fail with nothing', async function () { const fields = {} - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) it('Should fail without name', async function () { const fields = omit(baseCorrectParams, 'name') - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) it('Should fail with a long name', async function () { const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) }) - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) }) - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) it('Should fail with a long support text', async function () { const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) }) - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) it('Should succeed with the correct parameters', async function () { await makePostBodyRequest({ url: server.url, - path, + path: videoChannelPath, token: server.accessToken, fields: baseCorrectParams, statusCodeExpected: 200 @@ -146,7 +144,7 @@ describe('Test videos API validator', function () { let path: string before(async function () { - path = accountPath + accountUUID + '/video-channels/' + videoChannelUUID + path = videoChannelPath + '/' + videoChannelUUID }) it('Should fail with a non authenticated user', async function () { @@ -196,16 +194,10 @@ describe('Test videos API validator', function () { }) describe('When getting a video channel', function () { - let basePath: string - - before(async function () { - basePath = accountPath + accountUUID + '/video-channels' - }) - it('Should return the list of the video channels with nothing', async function () { const res = await makeGetRequest({ url: server.url, - path: basePath, + path: videoChannelPath, statusCodeExpected: 200 }) @@ -215,7 +207,7 @@ describe('Test videos API validator', function () { it('Should fail without a correct uuid', async function () { await makeGetRequest({ url: server.url, - path: basePath + '/coucou', + path: videoChannelPath + '/coucou', statusCodeExpected: 400 }) }) @@ -223,7 +215,7 @@ describe('Test videos API validator', function () { it('Should return 404 with an incorrect video channel', async function () { await makeGetRequest({ url: server.url, - path: basePath + '/4da6fde3-88f7-4d16-b119-108df5630b06', + path: videoChannelPath + '/4da6fde3-88f7-4d16-b119-108df5630b06', statusCodeExpected: 404 }) }) @@ -231,7 +223,7 @@ describe('Test videos API validator', function () { it('Should succeed with the correct parameters', async function () { await makeGetRequest({ url: server.url, - path: basePath + '/' + videoChannelUUID, + path: videoChannelPath + '/' + videoChannelUUID, statusCodeExpected: 200 }) }) @@ -239,30 +231,26 @@ describe('Test videos API validator', function () { describe('When deleting a video channel', function () { it('Should fail with a non authenticated user', async function () { - await deleteVideoChannel(server.url, 'coucou', accountUUID, videoChannelUUID, 401) + await deleteVideoChannel(server.url, 'coucou', videoChannelUUID, 401) }) it('Should fail with another authenticated user', async function () { - 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,videoChannelUUID, 404) + await deleteVideoChannel(server.url, accessTokenUser, videoChannelUUID, 403) }) it('Should fail with an unknown video channel id', async function () { - await deleteVideoChannel(server.url, server.accessToken, accountUUID,454554, 404) + await deleteVideoChannel(server.url, server.accessToken,454554, 404) }) it('Should succeed with the correct parameters', async function () { - await deleteVideoChannel(server.url, server.accessToken, accountUUID, videoChannelUUID) + await deleteVideoChannel(server.url, server.accessToken, videoChannelUUID) }) it('Should fail to delete the last user video channel', async function () { const res = await getVideoChannelsList(server.url, 0, 1) const lastVideoChannelUUID = res.body.data[0].uuid - await deleteVideoChannel(server.url, server.accessToken, accountUUID, lastVideoChannelUUID, 409) + await deleteVideoChannel(server.url, server.accessToken, lastVideoChannelUUID, 409) }) }) diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 04e7b8c6a..d24b8ab0b 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -63,7 +63,7 @@ describe('Test video channels', function () { description: 'super video channel description', support: 'super video channel support text' } - const res = await addVideoChannel(servers[0].url, servers[0].accessToken, accountUUID, videoChannel) + const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) videoChannelId = res.body.videoChannel.id videoChannelUUID = res.body.videoChannel.uuid @@ -130,7 +130,7 @@ describe('Test video channels', function () { support: 'video channel support text updated' } - await updateVideoChannel(servers[0].url, servers[0].accessToken, accountUUID, videoChannelId, videoChannelAttributes) + await updateVideoChannel(servers[0].url, servers[0].accessToken, videoChannelId, videoChannelAttributes) await wait(3000) }) @@ -149,7 +149,7 @@ describe('Test video channels', function () { }) it('Should get video channel', async function () { - const res = await getVideoChannel(servers[0].url, accountUUID, videoChannelId) + const res = await getVideoChannel(servers[0].url, videoChannelId) const videoChannel = res.body expect(videoChannel.displayName).to.equal('video channel updated') @@ -161,7 +161,7 @@ describe('Test video channels', function () { this.timeout(10000) for (const server of servers) { - const res = await getVideoChannelVideos(server.url, server.accessToken, accountUUID, videoChannelUUID, 0, 5) + const res = await getVideoChannelVideos(server.url, server.accessToken, videoChannelUUID, 0, 5) expect(res.body.total).to.equal(1) expect(res.body.data).to.be.an('array') expect(res.body.data).to.have.lengthOf(1) @@ -170,7 +170,7 @@ describe('Test video channels', function () { }) it('Should delete video channel', async function () { - await deleteVideoChannel(servers[0].url, servers[0].accessToken, accountUUID, videoChannelId) + await deleteVideoChannel(servers[0].url, servers[0].accessToken, videoChannelId) }) it('Should have video channel deleted', async function () { diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 8901f38f9..b8c85f45b 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -39,7 +39,7 @@ describe('Test video NSFW policy', function () { getVideosListWithToken(server.url, token), searchVideoWithToken(server.url, 'n', token), getAccountVideos(server.url, token, accountUUID, 0, 5), - getVideoChannelVideos(server.url, token, accountUUID, videoChannelUUID, 0, 5) + getVideoChannelVideos(server.url, token, videoChannelUUID, 0, 5) ]) } @@ -47,7 +47,7 @@ describe('Test video NSFW policy', function () { getVideosList(server.url), searchVideo(server.url, 'n'), getAccountVideos(server.url, undefined, accountUUID, 0, 5), - getVideoChannelVideos(server.url, undefined, accountUUID, videoChannelUUID, 0, 5) + getVideoChannelVideos(server.url, undefined, videoChannelUUID, 0, 5) ]) }) } diff --git a/server/tests/utils/videos/video-channels.ts b/server/tests/utils/videos/video-channels.ts index 0b4fa89b7..978e21b19 100644 --- a/server/tests/utils/videos/video-channels.ts +++ b/server/tests/utils/videos/video-channels.ts @@ -34,11 +34,10 @@ function getAccountVideoChannelsList (url: string, accountId: number | string, s function addVideoChannel ( url: string, token: string, - accountId: number | string, videoChannelAttributesArg: VideoChannelAttributes, expectedStatus = 200 ) { - const path = '/api/v1/accounts/' + accountId + '/video-channels/' + const path = '/api/v1/video-channels/' // Default attributes let attributes = { @@ -59,13 +58,12 @@ function addVideoChannel ( function updateVideoChannel ( url: string, token: string, - accountId: number | string, channelId: number | string, attributes: VideoChannelAttributes, expectedStatus = 204 ) { const body = {} - const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId + const path = '/api/v1/video-channels/' + channelId if (attributes.name) body['name'] = attributes.name if (attributes.description) body['description'] = attributes.description @@ -79,8 +77,8 @@ function updateVideoChannel ( .expect(expectedStatus) } -function deleteVideoChannel (url: string, token: string, accountId: number | string, channelId: number | string, expectedStatus = 204) { - const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId +function deleteVideoChannel (url: string, token: string, channelId: number | string, expectedStatus = 204) { + const path = '/api/v1/video-channels/' + channelId return request(url) .delete(path) @@ -89,8 +87,8 @@ function deleteVideoChannel (url: string, token: string, accountId: number | str .expect(expectedStatus) } -function getVideoChannel (url: string, accountId: number | string, channelId: number | string) { - const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId +function getVideoChannel (url: string, channelId: number | string) { + const path = '/api/v1/video-channels/' + channelId return request(url) .get(path) diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index d1d8c07df..870dfd21f 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts @@ -186,13 +186,12 @@ function getAccountVideos (url: string, accessToken: string, accountId: number | function getVideoChannelVideos ( url: string, accessToken: string, - accountId: number | string, videoChannelId: number | string, start: number, count: number, sort?: string ) { - const path = '/api/v1/accounts/' + accountId + '/video-channels/' + videoChannelId + '/videos' + const path = '/api/v1/video-channels/' + videoChannelId + '/videos' return makeGetRequest({ url, -- cgit v1.2.3