ActivityPub-federated video streaming platform using P2P directly in your web browser
Add video channel tests
Chocobozzz5f04dd2f7439
diff --git a/server/tests/api/check-params/remotes.ts b/server/tests/api/check-params/remotes.tsindex 9456ae6652..6d17474425 100644--- a/server/tests/api/check-params/remotes.ts+++ b/server/tests/api/check-params/remotes.ts@@ -1,5 +1,7 @@/* tslint:disable:no-unused-expression */+import 'mocha'+import {ServerInfo,flushTests,diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.tsnew file mode 100644index 0000000000..b99b5eda8b--- /dev/null+++ b/server/tests/api/check-params/video-channels.ts@@ -0,0 +1,310 @@+/* 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 {+ ServerInfo,+ flushTests,+ runServer,+ makePutBodyRequest,+ setAccessTokensToServers,+ killallServers,+ getMyUserInformation,+ makePostBodyRequest,+ getVideoChannelsList,+ createUser,+ getUserAccessToken+} from '../../utils'++describe('Test videos API validator', function () {+ const path = '/api/v1/videos/channels'+ let server: ServerInfo+ let channelId: number+ let accessTokenUser: string++ // ---------------------------------------------------------------++ before(async function () {+ this.timeout(20000)++ await flushTests()++ server = await runServer(1)++ await setAccessTokensToServers([ server ])++ const res = await getMyUserInformation(server.url, server.accessToken)+ channelId = res.body.videoChannels[0].id++ const user = {+ username: 'fake',+ password: 'fake_password'+ }+ await createUser(server.url, server.accessToken, user.username, user.password)++ accessTokenUser = await getUserAccessToken(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)+ })++ 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)+ })++ it('Should fail with an incorrect sort', async function () {+ await request(server.url)+ .get(path)+ .query({ sort: 'hello' })+ .set('Accept', 'application/json')+ .expect(400)+ })+ })++ describe('When listing author video channels', function () {+ it('Should fail with bad author', async function () {+ const path = '/api/v1/videos/authors/hello/channels'++ await request(server.url)+ .get(path)+ .set('Accept', 'application/json')+ .expect(400)+ })++ it('Should fail with a unknown author', async function () {+ const path = '/api/v1/videos/authors/156/channels'++ await request(server.url)+ .get(path)+ .set('Accept', 'application/json')+ .expect(404)+ })+ })++ describe('When adding a video channel', function () {++ 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 })+ })++ it('Should fail with nothing', async function () {+ const fields = {}+ await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })+ })++ it('Should fail without name', async function () {+ const fields = {+ description: 'super description'+ }+ await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })+ })++ it('Should fail with a long name', async function () {+ const fields = {+ name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' ++ 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',+ description: 'super description'+ }+ 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'+ }+ 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 })+ })+ })++ describe('When updating a video channel', function () {+ let videoChannelId++ before(async function () {+ const res = await getVideoChannelsList(server.url, 0, 1)+ videoChannelId = res.body.data[0].id+ })++ 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 })+ })++ 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,+ statusCodeExpected: 403+ })+ })++ it('Should fail with a long name', async function () {+ const fields = {+ name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' ++ 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',+ description: 'super description'+ }+ 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'+ }+ 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,+ statusCodeExpected: 204+ })+ })+ })++ describe('When getting a video channel', function () {+ let videoChannelId: number++ before(async function () {+ const res = await getVideoChannelsList(server.url, 0, 1)+ videoChannelId = res.body.data[0].id+ })++ 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/)++ 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)+ })++ 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)+ })++ it('Should succeed with the correct parameters', async function () {+ await request(server.url)+ .get(path + '/' + videoChannelId)+ .set('Accept', 'application/json')+ .expect(200)+ })+ })++ describe('When deleting a video channel', function () {+ let videoChannelId: number++ before(async function () {+ const res = await getVideoChannelsList(server.url, 0, 1)+ videoChannelId = res.body.data[0].id+ })++ it('Should fail with a non authenticated user', async function () {+ await request(server.url)+ .delete(path + '/' + videoChannelId)+ .set('Authorization', 'Bearer coucou')+ .expect(401)+ })++ it('Should fail with another authenticated user', async function () {+ await request(server.url)+ .delete(path + '/' + videoChannelId)+ .set('Authorization', 'Bearer ' + accessTokenUser)+ .expect(403)+ })++ it('Should fail with an unknown id', async function () {+ await request(server.url)+ .delete(path + '/454554')+ .set('Authorization', 'Bearer ' + server.accessToken)+ .expect(404)+ })++ it('Should succeed with the correct parameters', async function () {+ await request(server.url)+ .delete(path + '/' + videoChannelId)+ .set('Authorization', 'Bearer ' + server.accessToken)+ .expect(204)+ })++ 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+ )+ })+ })++ after(async function () {+ killallServers([ server ])++ // Keep the logs if the test failed+ if (this['ok']) {+ await flushTests()+ }+ })+})diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.tsindex af75d33c1a..167b45b61e 100644--- a/server/tests/api/check-params/videos.ts+++ b/server/tests/api/check-params/videos.ts@@ -14,12 +14,16 @@ import {makePutBodyRequest,setAccessTokensToServers,killallServers,- makePostUploadRequest+ makePostUploadRequest,+ getMyUserInformation,+ createUser,+ getUserAccessToken} from '../../utils'describe('Test videos API validator', function () {const path = '/api/v1/videos/'let server: ServerInfo+ let channelId: number// ---------------------------------------------------------------@@ -31,6 +35,9 @@ describe('Test videos API validator', function () {server = await runServer(1)await setAccessTokensToServers([ server ])++ const res = await getMyUserInformation(server.url, server.accessToken)+ channelId = res.body.videoChannels[0].id})describe('When listing a video', function () {@@ -106,7 +113,8 @@ describe('Test videos API validator', function () {language: 6,nsfw: false,description: 'my super description',- tags: [ 'tag1', 'tag2' ]+ tags: [ 'tag1', 'tag2' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')@@ -122,7 +130,8 @@ describe('Test videos API validator', function () {language: 6,nsfw: false,description: 'my super description',- tags: [ 'tag1', 'tag2' ]+ tags: [ 'tag1', 'tag2' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')@@ -137,7 +146,8 @@ describe('Test videos API validator', function () {language: 6,nsfw: false,description: 'my super description',- tags: [ 'tag1', 'tag2' ]+ tags: [ 'tag1', 'tag2' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')@@ -153,7 +163,8 @@ describe('Test videos API validator', function () {language: 6,nsfw: false,description: 'my super description',- tags: [ 'tag1', 'tag2' ]+ tags: [ 'tag1', 'tag2' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')@@ -168,7 +179,8 @@ describe('Test videos API validator', function () {language: 6,nsfw: false,description: 'my super description',- tags: [ 'tag1', 'tag2' ]+ tags: [ 'tag1', 'tag2' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')@@ -184,7 +196,8 @@ describe('Test videos API validator', function () {language: 6,nsfw: false,description: 'my super description',- tags: [ 'tag1', 'tag2' ]+ tags: [ 'tag1', 'tag2' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')@@ -200,7 +213,8 @@ describe('Test videos API validator', function () {language: 563,nsfw: false,description: 'my super description',- tags: [ 'tag1', 'tag2' ]+ tags: [ 'tag1', 'tag2' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')@@ -215,7 +229,8 @@ describe('Test videos API validator', function () {licence: 4,language: 6,description: 'my super description',- tags: [ 'tag1', 'tag2' ]+ tags: [ 'tag1', 'tag2' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')@@ -223,7 +238,7 @@ describe('Test videos API validator', function () {await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })})- it('Should fail with a bad nsfw attribue', async function () {+ it('Should fail with a bad nsfw attribute', async function () {const fields = {name: 'my super name',category: 5,@@ -231,7 +246,8 @@ describe('Test videos API validator', function () {language: 6,nsfw: 2,description: 'my super description',- tags: [ 'tag1', 'tag2' ]+ tags: [ 'tag1', 'tag2' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')@@ -246,7 +262,8 @@ describe('Test videos API validator', function () {licence: 1,language: 6,nsfw: false,- tags: [ 'tag1', 'tag2' ]+ tags: [ 'tag1', 'tag2' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')@@ -264,6 +281,23 @@ describe('Test videos API validator', function () {description: 'my super description which is 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 very very' +'very very very very very very very very very very very very very very very long',+ tags: [ 'tag1', 'tag2' ],+ channelId+ }+ const attaches = {+ 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')+ }+ await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })+ })++ it('Should fail without a channel', async function () {+ const fields = {+ name: 'my super name',+ category: 5,+ licence: 1,+ language: 6,+ nsfw: false,+ description: 'my super description',tags: [ 'tag1', 'tag2' ]}const attaches = {@@ -272,6 +306,50 @@ describe('Test videos API validator', function () {await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })})+ it('Should fail with a bad channel', async function () {+ const fields = {+ name: 'my super name',+ category: 5,+ licence: 1,+ language: 6,+ nsfw: false,+ description: 'my super description',+ tags: [ 'tag1', 'tag2' ],+ channelId: 545454+ }+ const attaches = {+ 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')+ }+ await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })+ })++ it('Should fail with another user channel', async function () {+ const user = {+ username: 'fake',+ password: 'fake_password'+ }+ await createUser(server.url, server.accessToken, user.username, user.password)++ const accessTokenUser = await getUserAccessToken(server, user)+ const res = await getMyUserInformation(server.url, accessTokenUser)+ const channelId = res.body.videoChannels[0].id++ const fields = {+ name: 'my super name',+ category: 5,+ licence: 1,+ language: 6,+ nsfw: false,+ description: 'my super description',+ tags: [ 'tag1', 'tag2' ],+ channelId+ }+ const attaches = {+ 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')+ }+ await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })+ })+it('Should fail with too many tags', async function () {const fields = {name: 'my super name',@@ -280,7 +358,8 @@ describe('Test videos API validator', function () {language: 6,nsfw: false,description: 'my super description',- tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]+ tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')@@ -296,7 +375,8 @@ describe('Test videos API validator', function () {language: 6,nsfw: false,description: 'my super description',- tags: [ 'tag1', 't' ]+ tags: [ 'tag1', 't' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')@@ -312,7 +392,8 @@ describe('Test videos API validator', function () {language: 6,nsfw: false,description: 'my super description',- tags: [ 'my_super_tag_too_long', 'tag1' ]+ tags: [ 'my_super_tag_too_long', 'tag1' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')@@ -328,7 +409,8 @@ describe('Test videos API validator', function () {language: 6,nsfw: false,description: 'my super description',- tags: [ 'tag1', 'tag2' ]+ tags: [ 'tag1', 'tag2' ],+ channelId}const attaches = {}await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })@@ -342,7 +424,8 @@ describe('Test videos API validator', function () {language: 6,nsfw: false,description: 'my super description',- tags: [ 'tag1', 'tag2' ]+ tags: [ 'tag1', 'tag2' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')@@ -358,7 +441,8 @@ describe('Test videos API validator', function () {language: 6,nsfw: false,description: 'my super description',- tags: [ 'tag1', 'tag2' ]+ tags: [ 'tag1', 'tag2' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_too_long.webm')@@ -376,7 +460,8 @@ describe('Test videos API validator', function () {language: 6,nsfw: false,description: 'my super description',- tags: [ 'tag1', 'tag2' ]+ tags: [ 'tag1', 'tag2' ],+ channelId}const attaches = {'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')diff --git a/server/tests/api/friends-advanced.ts b/server/tests/api/friends-advanced.tsindex dc5c83c5ee..fbfdf227e3 100644--- a/server/tests/api/friends-advanced.ts+++ b/server/tests/api/friends-advanced.ts@@ -72,7 +72,7 @@ describe('Test advanced friends', function () {await setAccessTokensToServers(servers)})- it('Should make friends with two pod each in a different group', async function () {+ it('Should not make friends with two different groups', async function () {this.timeout(20000)// Pod 3 makes friend with the first one@@ -81,7 +81,7 @@ describe('Test advanced friends', function () {// Pod 4 makes friend with the second oneawait makeFriendsWrapper(4)- // Now if the fifth wants to make friends with the third et the first+ // Now if the fifth wants to make friends with the third and the firstawait makeFriendsWrapper(5)await wait(11000)@@ -104,8 +104,8 @@ describe('Test advanced friends', function () {}})- it('Should make friends with the pods 1, 2, 3', async function () {- this.timeout(150000)+ it('Should remove bad pod and new pod should not become friend with it', async function () {+ this.timeout(200000)// Pods 1, 2, 3 and 4 become friendsawait makeFriendsWrapper(2)@@ -119,6 +119,9 @@ describe('Test advanced friends', function () {expect(res.body.data.length).to.equal(3)}+ // Wait initial video channel requests+ await wait(11000)+// Kill pod 4servers[3].app.kill()@@ -133,6 +136,16 @@ describe('Test advanced friends', function () {await wait(11000)+ await uploadVideoWrapper(1)+ await uploadVideoWrapper(2)++ await wait(11000)++ await uploadVideoWrapper(1)+ await uploadVideoWrapper(2)++ await wait(11000)+serverNumbersToTest = [ 1, 2 ]for (const i of serverNumbersToTest) {@@ -147,31 +160,39 @@ describe('Test advanced friends', function () {}}- // Rerun server 4+ // Rerun server 4const newServer = await runServer(4)servers[3].app = newServer.appservers[3].app- const res1 = await getFriendsListWrapper(4)-// Pod 4 didn't know pod 1 and 2 removed it+ const res1 = await getFriendsListWrapper(4)expect(res1.body.data.length).to.equal(3)+ // Pod 3 didn't upload video, it's still friend with pod 3+ const res2 = await getFriendsListWrapper(3)+ expect(res2.body.data.length).to.equal(3)+// Pod 6 asks pod 1, 2 and 3await makeFriendsWrapper(6)await wait(11000)- const res2 = await getFriendsListWrapper(6)+ const res3 = await getFriendsListWrapper(6)// Pod 4 should not be our friend- const friends = res2.body.data+ const friends = res3.body.dataexpect(friends.length).to.equal(3)for (const pod of friends) {expect(pod.host).not.equal(servers[3].host)}})+ // Pod 1 is friend with : 2 3 6+ // Pod 2 is friend with : 1 3 6+ // Pod 3 is friend with : 1 2 4 6+ // Pod 4 is friend with : 1 2 3+ // Pod 6 is friend with : 1 2 3it('Should pod 1 quit friends', async function () {this.timeout(25000)@@ -180,21 +201,26 @@ describe('Test advanced friends', function () {await wait(15000)+ // Pod 1 remove friendsawait quitFriendsWrapper(1)- // Remove pod 1 from pod 2const res1 = await getVideosWrapper(1)const videos1 = res1.body.dataexpect(videos1).to.be.an('array')- expect(videos1.length).to.equal(2)+ expect(videos1.length).to.equal(4)const res2 = await getVideosWrapper(2)const videos2 = res2.body.dataexpect(videos2).to.be.an('array')- expect(videos2.length).to.equal(3)+ expect(videos2.length).to.equal(5)})- it('Should make friends between pod 1 and 2 and exchange their videos', async function () {+ // Pod 1 is friend with nothing+ // Pod 2 is friend with : 3 6+ // Pod 3 is friend with : 2 4 6+ // Pod 4 is friend with : 2 3+ // Pod 6 is friend with : 2 3+ it('Should make friends between pod 1, 2, 3 and 6 and exchange their videos', async function () {this.timeout(20000)await makeFriendsWrapper(1)@@ -204,10 +230,15 @@ describe('Test advanced friends', function () {const res = await getVideosWrapper(1)const videos = res.body.dataexpect(videos).to.be.an('array')- expect(videos.length).to.equal(5)+ expect(videos.length).to.equal(9)})- it('Should allow pod 6 to quit pod 1 & 2 and be friend with pod 3', async function () {+ // Pod 1 is friend with : 2 3 6+ // Pod 2 is friend with : 1 3 6+ // Pod 3 is friend with : 1 2 4 6+ // Pod 4 is friend with : 2 3+ // Pod 6 is friend with : 1 2 3+ it('Should allow pod 6 to quit pod 1, 2 and 3 and be friend with pod 3', async function () {this.timeout(30000)// Pod 3 should have 4 friendsdiff --git a/server/tests/api/friends-basic.ts b/server/tests/api/friends-basic.tsindex efca4fda23..31e180631f 100644--- a/server/tests/api/friends-basic.ts+++ b/server/tests/api/friends-basic.ts@@ -87,7 +87,7 @@ describe('Test basic friends', function () {const pod1 = friends[0]expect(pod1.host).to.equal(servers[2].host)expect(pod1.email).to.equal('[email protected]')- expect(pod1.score).to.equal(20)+ expect(pod1.score).to.be.at.least(20)expect(dateIsValid(pod1.createdAt)).to.be.true// Same here, the third pod should have the second pod as a friend@@ -99,7 +99,7 @@ describe('Test basic friends', function () {const pod2 = result[0]expect(pod2.host).to.equal(servers[1].host)expect(pod2.email).to.equal('[email protected]')- expect(pod2.score).to.equal(20)+ expect(pod2.score).to.be.at.least(20)expect(dateIsValid(pod2.createdAt)).to.be.true// Finally the first pod make friend with the second pod@@ -133,7 +133,7 @@ describe('Test basic friends', function () {const pod = res.body.data[0]expect(pod.host).to.equal('localhost:9002')expect(pod.email).to.equal('[email protected]')- expect(pod.score).to.equal(20)+ expect(pod.score).to.be.at.least(20)expect(dateIsValid(pod.createdAt)).to.be.true})diff --git a/server/tests/api/multiple-pods.ts b/server/tests/api/multiple-pods.tsindex e0ccb30582..fe4e4a036b 100644--- a/server/tests/api/multiple-pods.ts+++ b/server/tests/api/multiple-pods.ts@@ -19,8 +19,12 @@ import {updateVideo,uploadVideo,wait,- webtorrentAdd+ webtorrentAdd,+ addVideoChannel,+ getVideoChannelsList,+ getUserAccessToken} from '../utils'+import { createUser } from '../utils/users'const expect = chai.expect@@ -28,6 +32,7 @@ describe('Test multiple pods', function () {let servers: ServerInfo[] = []const toRemove = []let videoUUID = ''+ let videoChannelId: numberbefore(async function () {this.timeout(120000)@@ -37,6 +42,14 @@ describe('Test multiple pods', function () {// Get the access tokensawait setAccessTokensToServers(servers)+ const videoChannel = {+ name: 'my channel',+ description: 'super channel'+ }+ await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)+ const channelRes = await getVideoChannelsList(servers[0].url, 0, 1)+ videoChannelId = channelRes.body.data[0].id+// The second pod make friend with the thirdawait makeFriends(servers[1].url, servers[1].accessToken)@@ -69,6 +82,7 @@ describe('Test multiple pods', function () {nsfw: true,description: 'my super description for pod 1',tags: [ 'tag1p1', 'tag2p1' ],+ channelId: videoChannelId,fixture: 'video_short1.webm'}await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)@@ -101,21 +115,30 @@ describe('Test multiple pods', function () {expect(dateIsValid(video.updatedAt)).to.be.trueexpect(video.author).to.equal('root')- expect(video.files).to.have.lengthOf(1)+ const res2 = await getVideo(server.url, video.uuid)+ const videoDetails = res2.body++ expect(videoDetails.channel.name).to.equal('my channel')+ expect(videoDetails.channel.description).to.equal('super channel')+ expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true+ expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true+ expect(videoDetails.files).to.have.lengthOf(1)- const file = video.files[0]+ const file = videoDetails.files[0]const magnetUri = file.magnetUriexpect(file.magnetUri).to.have.lengthOf.above(2)- expect(file.torrentUrl).to.equal(`http://${video.podHost}/static/torrents/${video.uuid}-${file.resolution}.torrent`)- expect(file.fileUrl).to.equal(`http://${video.podHost}/static/webseed/${video.uuid}-${file.resolution}.webm`)+ expect(file.torrentUrl).to.equal(`http://${videoDetails.podHost}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)+ expect(file.fileUrl).to.equal(`http://${videoDetails.podHost}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)expect(file.resolution).to.equal(720)expect(file.resolutionLabel).to.equal('720p')expect(file.size).to.equal(572456)if (server.url !== 'http://localhost:9001') {expect(video.isLocal).to.be.false+ expect(videoDetails.channel.isLocal).to.be.false} else {expect(video.isLocal).to.be.true+ expect(videoDetails.channel.isLocal).to.be.true}// All pods should have the same magnet Uri@@ -133,6 +156,13 @@ describe('Test multiple pods', function () {it('Should upload the video on pod 2 and propagate on each pod', async function () {this.timeout(120000)+ const user = {+ username: 'user1',+ password: 'super_password'+ }+ await createUser(servers[1].url, servers[1].accessToken, user.username, user.password)+ const userAccessToken = await getUserAccessToken(servers[1], user)+const videoAttributes = {name: 'my super name for pod 2',category: 4,@@ -143,7 +173,7 @@ describe('Test multiple pods', function () {tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],fixture: 'video_short2.webm'}- await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)+ await uploadVideo(servers[1].url, userAccessToken, videoAttributes)// Transcoding, so wait more than 22000await wait(60000)@@ -172,20 +202,27 @@ describe('Test multiple pods', function () {expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])expect(dateIsValid(video.createdAt)).to.be.trueexpect(dateIsValid(video.updatedAt)).to.be.true- expect(video.author).to.equal('root')+ expect(video.author).to.equal('user1')++ if (server.url !== 'http://localhost:9002') {+ expect(video.isLocal).to.be.false+ } else {+ expect(video.isLocal).to.be.true+ }- expect(video.files).to.have.lengthOf(4)+ const res2 = await getVideo(server.url, video.uuid)+ const videoDetails = res2.body++ expect(videoDetails.channel.name).to.equal('Default user1 channel')+ expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true+ expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true++ expect(videoDetails.files).to.have.lengthOf(4)// Check common attributes- for (const file of video.files) {+ for (const file of videoDetails.files) {expect(file.magnetUri).to.have.lengthOf.above(2)- if (server.url !== 'http://localhost:9002') {- expect(video.isLocal).to.be.false- } else {- expect(video.isLocal).to.be.true- }-// All pods should have the same magnet Uriif (baseMagnet[file.resolution] === undefined) {baseMagnet[file.resolution] = file.magnet@@ -194,27 +231,27 @@ describe('Test multiple pods', function () {}}- const file240p = video.files.find(f => f.resolution === 240)+ const file240p = videoDetails.files.find(f => f.resolution === 240)expect(file240p).not.to.be.undefinedexpect(file240p.resolutionLabel).to.equal('240p')expect(file240p.size).to.be.above(180000).and.below(200000)- const file360p = video.files.find(f => f.resolution === 360)+ const file360p = videoDetails.files.find(f => f.resolution === 360)expect(file360p).not.to.be.undefinedexpect(file360p.resolutionLabel).to.equal('360p')expect(file360p.size).to.be.above(270000).and.below(290000)- const file480p = video.files.find(f => f.resolution === 480)+ const file480p = videoDetails.files.find(f => f.resolution === 480)expect(file480p).not.to.be.undefinedexpect(file480p.resolutionLabel).to.equal('480p')expect(file480p.size).to.be.above(380000).and.below(400000)- const file720p = video.files.find(f => f.resolution === 720)+ const file720p = videoDetails.files.find(f => f.resolution === 720)expect(file720p).not.to.be.undefinedexpect(file720p.resolutionLabel).to.equal('720p')expect(file720p.size).to.be.above(700000).and.below(7200000)- const test = await testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath)+ const test = await testVideoImage(server.url, 'video_short2.webm', videoDetails.thumbnailPath)expect(test).to.equal(true)}})@@ -284,9 +321,11 @@ describe('Test multiple pods', function () {expect(dateIsValid(video1.createdAt)).to.be.trueexpect(dateIsValid(video1.updatedAt)).to.be.true- expect(video1.files).to.have.lengthOf(1)+ const res2 = await getVideo(server.url, video1.id)+ const video1Details = res2.body+ expect(video1Details.files).to.have.lengthOf(1)- const file1 = video1.files[0]+ const file1 = video1Details.files[0]expect(file1.magnetUri).to.have.lengthOf.above(2)expect(file1.resolution).to.equal(720)expect(file1.resolutionLabel).to.equal('720p')@@ -308,9 +347,12 @@ describe('Test multiple pods', function () {expect(dateIsValid(video2.createdAt)).to.be.trueexpect(dateIsValid(video2.updatedAt)).to.be.true- expect(video2.files).to.have.lengthOf(1)+ const res3 = await getVideo(server.url, video2.id)+ const video2Details = res3.body- const file2 = video2.files[0]+ expect(video2Details.files).to.have.lengthOf(1)++ const file2 = video2Details.files[0]const magnetUri2 = file2.magnetUriexpect(file2.magnetUri).to.have.lengthOf.above(2)expect(file2.resolution).to.equal(720)@@ -352,7 +394,10 @@ describe('Test multiple pods', function () {toRemove.push(res.body.data[2])toRemove.push(res.body.data[3])- const torrent = await webtorrentAdd(video.files[0].magnetUri)+ const res2 = await getVideo(servers[2].url, video.id)+ const videoDetails = res2.body++ const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)expect(torrent.files).to.be.an('array')expect(torrent.files.length).to.equal(1)expect(torrent.files[0].path).to.exist.and.to.not.equal('')@@ -365,8 +410,10 @@ describe('Test multiple pods', function () {const res = await getVideosList(servers[0].url)const video = res.body.data[1]+ const res2 = await getVideo(servers[0].url, video.id)+ const videoDetails = res2.body- const torrent = await webtorrentAdd(video.files[0].magnetUri)+ const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)expect(torrent.files).to.be.an('array')expect(torrent.files.length).to.equal(1)expect(torrent.files[0].path).to.exist.and.to.not.equal('')@@ -379,8 +426,10 @@ describe('Test multiple pods', function () {const res = await getVideosList(servers[1].url)const video = res.body.data[2]+ const res2 = await getVideo(servers[1].url, video.id)+ const videoDetails = res2.body- const torrent = await webtorrentAdd(video.files[0].magnetUri)+ const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)expect(torrent.files).to.be.an('array')expect(torrent.files.length).to.equal(1)expect(torrent.files[0].path).to.exist.and.to.not.equal('')@@ -393,8 +442,10 @@ describe('Test multiple pods', function () {const res = await getVideosList(servers[0].url)const video = res.body.data[3]+ const res2 = await getVideo(servers[0].url, video.id)+ const videoDetails = res2.body- const torrent = await webtorrentAdd(video.files[0].magnetUri)+ const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)expect(torrent.files).to.be.an('array')expect(torrent.files.length).to.equal(1)expect(torrent.files[0].path).to.exist.and.to.not.equal('')@@ -407,7 +458,10 @@ describe('Test multiple pods', function () {const res = await getVideosList(servers[0].url)const video = res.body.data.find(v => v.name === 'my super name for pod 2')- const file = video.files.find(f => f.resolution === 360)+ const res2 = await getVideo(servers[0].url, video.id)+ const videoDetails = res2.body++ const file = videoDetails.files.find(f => f.resolution === 360)expect(file).not.to.be.undefinedconst torrent = await webtorrentAdd(file.magnetUri)@@ -425,14 +479,14 @@ describe('Test multiple pods', function () {before(async function () {const res1 = await getVideosList(servers[0].url)- remoteVideosPod1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.id)+ remoteVideosPod1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid)const res2 = await getVideosList(servers[1].url)- remoteVideosPod2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.id)+ remoteVideosPod2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid)const res3 = await getVideosList(servers[2].url)- localVideosPod3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.id)- remoteVideosPod3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.id)+ localVideosPod3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid)+ remoteVideosPod3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid)})it('Should view multiple videos on owned servers', async function () {@@ -452,8 +506,11 @@ describe('Test multiple pods', function () {const res = await getVideosList(server.url)const videos = res.body.data- expect(videos.find(video => video.views === 3)).to.be.an('object')- expect(videos.find(video => video.views === 1)).to.be.an('object')+ const video0 = videos.find(v => v.uuid === localVideosPod3[0])+ const video1 = videos.find(v => v.uuid === localVideosPod3[1])++ expect(video0.views).to.equal(4)+ expect(video1.views).to.equal(2)}})@@ -573,7 +630,10 @@ describe('Test multiple pods', function () {expect(videoUpdated.tags).to.deep.equal([ 'tag_up_1', 'tag_up_2' ])expect(dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true- const file = videoUpdated.files[0]+ const res2 = await getVideo(server.url, videoUpdated.uuid)+ const videoUpdatedDetails = res2.body++ const file = videoUpdatedDetails .files[0]expect(file.magnetUri).to.have.lengthOf.above(2)expect(file.resolution).to.equal(720)expect(file.resolutionLabel).to.equal('720p')@@ -584,7 +644,7 @@ describe('Test multiple pods', function () {// Avoid "duplicate torrent" errorsconst refreshWebTorrent = true- const torrent = await webtorrentAdd(videoUpdated.files[0].magnetUri, refreshWebTorrent)+ const torrent = await webtorrentAdd(videoUpdatedDetails .files[0].magnetUri, refreshWebTorrent)expect(torrent.files).to.be.an('array')expect(torrent.files.length).to.equal(1)expect(torrent.files[0].path).to.exist.and.to.not.equal('')diff --git a/server/tests/api/request-schedulers.ts b/server/tests/api/request-schedulers.tsindex 2e91e7c614..c136d1cea9 100644--- a/server/tests/api/request-schedulers.ts+++ b/server/tests/api/request-schedulers.ts@@ -68,7 +68,7 @@ describe('Test requests schedulers stats', function () {const res = await getRequestsStats(server)const requestSchedulers = res.bodyconst requestScheduler = requestSchedulers.requestScheduler- expect(requestScheduler.totalRequests).to.equal(1)+ expect(requestScheduler.totalRequests).to.equal(3)})after(async function () {diff --git a/server/tests/api/single-pod.ts b/server/tests/api/single-pod.tsindex 71017b2b30..d3a9824364 100644--- a/server/tests/api/single-pod.ts+++ b/server/tests/api/single-pod.ts@@ -122,22 +122,25 @@ describe('Test a single pod', function () {expect(dateIsValid(video.createdAt)).to.be.trueexpect(dateIsValid(video.updatedAt)).to.be.true- expect(video.files).to.have.lengthOf(1)+ const res2 = await getVideo(server.url, res.body.data[0].id)+ const videoDetails = res2.body- const file = video.files[0]+ expect(videoDetails.files).to.have.lengthOf(1)++ const file = videoDetails.files[0]const magnetUri = file.magnetUriexpect(file.magnetUri).to.have.lengthOf.above(2)- expect(file.torrentUrl).to.equal(`${server.url}/static/torrents/${video.uuid}-${file.resolution}.torrent`)- expect(file.fileUrl).to.equal(`${server.url}/static/webseed/${video.uuid}-${file.resolution}.webm`)+ expect(file.torrentUrl).to.equal(`${server.url}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)+ expect(file.fileUrl).to.equal(`${server.url}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)expect(file.resolution).to.equal(720)expect(file.resolutionLabel).to.equal('720p')expect(file.size).to.equal(218910)- const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)+ const test = await testVideoImage(server.url, 'video_short.webm', videoDetails.thumbnailPath)expect(test).to.equal(true)- videoId = video.id- videoUUID = video.uuid+ videoId = videoDetails.id+ videoUUID = videoDetails.uuidconst torrent = await webtorrentAdd(magnetUri)expect(torrent.files).to.be.an('array')@@ -167,6 +170,10 @@ describe('Test a single pod', function () {expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])expect(dateIsValid(video.createdAt)).to.be.trueexpect(dateIsValid(video.updatedAt)).to.be.true+ expect(video.channel.name).to.equal('Default root channel')+ expect(video.channel.isLocal).to.be.true+ expect(dateIsValid(video.channel.createdAt)).to.be.true+ expect(dateIsValid(video.channel.updatedAt)).to.be.trueexpect(video.files).to.have.lengthOf(1)@@ -200,7 +207,7 @@ describe('Test a single pod', function () {const res = await getVideo(server.url, videoId)const video = res.body- expect(video.views).to.equal(2)+ expect(video.views).to.equal(3)})it('Should search the video by name by default', async function () {@@ -227,14 +234,6 @@ describe('Test a single pod', function () {expect(dateIsValid(video.createdAt)).to.be.trueexpect(dateIsValid(video.updatedAt)).to.be.true- expect(video.files).to.have.lengthOf(1)-- const file = video.files[0]- expect(file.magnetUri).to.have.lengthOf.above(2)- expect(file.resolution).to.equal(720)- expect(file.resolutionLabel).to.equal('720p')- expect(file.size).to.equal(218910)-const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)expect(test).to.equal(true)})@@ -289,14 +288,6 @@ describe('Test a single pod', function () {expect(dateIsValid(video.createdAt)).to.be.trueexpect(dateIsValid(video.updatedAt)).to.be.true- expect(video.files).to.have.lengthOf(1)-- const file = video.files[0]- expect(file.magnetUri).to.have.lengthOf.above(2)- expect(file.resolution).to.equal(720)- expect(file.resolutionLabel).to.equal('720p')- expect(file.size).to.equal(218910)-const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)expect(test).to.equal(true)})@@ -493,10 +484,13 @@ describe('Test a single pod', function () {it('Should search the right magnetUri video', async function () {const video = videosListBase[0]- const res = await searchVideoWithPagination(server.url, encodeURIComponent(video.files[0].magnetUri), 'magnetUri', 0, 15)+ const res = await getVideo(server.url, video.id)+ const videoDetails = res.body- const videos = res.body.data- expect(res.body.total).to.equal(1)+ const res2 = await searchVideoWithPagination(server.url, encodeURIComponent(videoDetails.files[0].magnetUri), 'magnetUri', 0, 15)++ const videos = res2.body.data+ expect(res2.body.total).to.equal(1)expect(videos.length).to.equal(1)expect(videos[0].name).to.equal(video.name)})@@ -566,6 +560,11 @@ describe('Test a single pod', function () {expect(dateIsValid(video.createdAt)).to.be.trueexpect(dateIsValid(video.updatedAt)).to.be.true+ expect(video.channel.name).to.equal('Default root channel')+ expect(video.channel.isLocal).to.be.true+ expect(dateIsValid(video.channel.createdAt)).to.be.true+ expect(dateIsValid(video.channel.updatedAt)).to.be.true+expect(video.files).to.have.lengthOf(1)const file = video.files[0]@@ -610,6 +609,11 @@ describe('Test a single pod', function () {expect(dateIsValid(video.createdAt)).to.be.trueexpect(dateIsValid(video.updatedAt)).to.be.true+ expect(video.channel.name).to.equal('Default root channel')+ expect(video.channel.isLocal).to.be.true+ expect(dateIsValid(video.channel.createdAt)).to.be.true+ expect(dateIsValid(video.channel.updatedAt)).to.be.true+expect(video.files).to.have.lengthOf(1)const file = video.files[0]@@ -645,6 +649,11 @@ describe('Test a single pod', function () {expect(dateIsValid(video.createdAt)).to.be.trueexpect(dateIsValid(video.updatedAt)).to.be.true+ expect(video.channel.name).to.equal('Default root channel')+ expect(video.channel.isLocal).to.be.true+ expect(dateIsValid(video.channel.createdAt)).to.be.true+ expect(dateIsValid(video.channel.updatedAt)).to.be.true+expect(video.files).to.have.lengthOf(1)const file = video.files[0]diff --git a/server/tests/api/users.ts b/server/tests/api/users.tsindex 04c68d4ea9..dbf0801f3f 100644--- a/server/tests/api/users.ts+++ b/server/tests/api/users.ts@@ -72,7 +72,7 @@ describe('Test users', function () {})it('Should not login with an invalid password', async function () {- const user = { username: server.user.username, password: 'mewthree' }+ const user = { username: server.user.username, password: 'mew_three' }const res = await login(server.url, server.client, user, 400)expect(res.body.error).to.equal('invalid_grant')diff --git a/server/tests/api/video-channels.ts b/server/tests/api/video-channels.tsnew file mode 100644index 0000000000..95b202e2f6--- /dev/null+++ b/server/tests/api/video-channels.ts@@ -0,0 +1,141 @@+/* tslint:disable:no-unused-expression */++import { keyBy } from 'lodash'+import { join } from 'path'+import 'mocha'+import * as chai from 'chai'+const expect = chai.expect++import {+ ServerInfo,+ flushTests,+ runServer,+ setAccessTokensToServers,+ killallServers,+ getMyUserInformation,+ getVideoChannelsList,+ addVideoChannel,+ getAuthorVideoChannelsList,+ updateVideoChannel,+ deleteVideoChannel,+ getVideoChannel+} from '../utils'+import { User } from '../../../shared'++describe('Test a video channels', function () {+ let server: ServerInfo+ let userInfo: User+ let videoChannelId: number++ before(async function () {+ this.timeout(120000)++ await flushTests()++ server = await runServer(1)++ await setAccessTokensToServers([ server ])+ })++ it('Should have one video channel (created with root)', async () => {+ const res = await getVideoChannelsList(server.url, 0, 2)++ expect(res.body.total).to.equal(1)+ expect(res.body.data).to.be.an('array')+ expect(res.body.data).to.have.lengthOf(1)+ })++ it('Should create another video channel', async () => {+ const videoChannel = {+ name: 'second video channel',+ description: 'super video channel description'+ }+ await addVideoChannel(server.url, server.accessToken, videoChannel)+ })++ it('Should have two video channels when getting my information', async () => {+ const res = await getMyUserInformation(server.url, server.accessToken)+ userInfo = res.body++ expect(userInfo.videoChannels).to.be.an('array')+ expect(userInfo.videoChannels).to.have.lengthOf(2)++ const videoChannels = userInfo.videoChannels+ expect(videoChannels[0].name).to.equal('Default root channel')+ expect(videoChannels[1].name).to.equal('second video channel')+ expect(videoChannels[1].description).to.equal('super video channel description')+ })++ it('Should have two video channels when getting author channels', async () => {+ const res = await getAuthorVideoChannelsList(server.url, userInfo.author.uuid)++ expect(res.body.total).to.equal(2)+ expect(res.body.data).to.be.an('array')+ expect(res.body.data).to.have.lengthOf(2)++ const videoChannels = res.body.data+ expect(videoChannels[0].name).to.equal('Default root channel')+ expect(videoChannels[1].name).to.equal('second video channel')+ expect(videoChannels[1].description).to.equal('super video channel description')++ videoChannelId = videoChannels[1].id+ })++ it('Should list video channels', async () => {+ const res = await getVideoChannelsList(server.url, 1, 1, '-name')++ expect(res.body.total).to.equal(2)+ expect(res.body.data).to.be.an('array')+ expect(res.body.data).to.have.lengthOf(1)+ expect(res.body.data[0].name).to.equal('Default root channel')+ })++ it('Should update video channel', async () => {+ const videoChannelAttributes = {+ name: 'video channel updated',+ description: 'video channel description updated'+ }++ await updateVideoChannel(server.url, server.accessToken, videoChannelId, videoChannelAttributes)+ })++ it('Should have video channel updated', async () => {+ const res = await getVideoChannelsList(server.url, 0, 1, '-name')++ expect(res.body.total).to.equal(2)+ expect(res.body.data).to.be.an('array')+ expect(res.body.data).to.have.lengthOf(1)+ expect(res.body.data[0].name).to.equal('video channel updated')+ expect(res.body.data[0].description).to.equal('video channel description updated')+ })++ it('Should get video channel', async () => {+ const res = await getVideoChannel(server.url, videoChannelId)++ const videoChannel = res.body+ expect(videoChannel.name).to.equal('video channel updated')+ expect(videoChannel.description).to.equal('video channel description updated')+ })++ it('Should delete video channel', async () => {+ await deleteVideoChannel(server.url, server.accessToken, videoChannelId)+ })++ it('Should have video channel deleted', async () => {+ const res = await getVideoChannelsList(server.url, 0, 10)++ expect(res.body.total).to.equal(1)+ expect(res.body.data).to.be.an('array')+ expect(res.body.data).to.have.lengthOf(1)+ expect(res.body.data[0].name).to.equal('Default root channel')+ })++ after(async function () {+ killallServers([ server ])++ // Keep the logs if the test failed+ if (this['ok']) {+ await flushTests()+ }+ })+})diff --git a/server/tests/api/video-transcoder.ts b/server/tests/api/video-transcoder.tsindex 22d89724bc..cafcc037df 100644--- a/server/tests/api/video-transcoder.ts+++ b/server/tests/api/video-transcoder.ts@@ -13,7 +13,8 @@ import {setAccessTokensToServers,flushAndRunMultipleServers,killallServers,- webtorrentAdd+ webtorrentAdd,+ getVideo} from '../utils'describe('Test video transcoding', function () {@@ -42,9 +43,12 @@ describe('Test video transcoding', function () {const res = await getVideosList(servers[0].url)const video = res.body.data[0]- expect(video.files).to.have.lengthOf(1)- const magnetUri = video.files[0].magnetUri+ const res2 = await getVideo(servers[0].url, video.id)+ const videoDetails = res2.body+ expect(videoDetails.files).to.have.lengthOf(1)++ const magnetUri = videoDetails.files[0].magnetUriexpect(magnetUri).to.match(/\.webm/)const torrent = await webtorrentAdd(magnetUri)@@ -68,9 +72,12 @@ describe('Test video transcoding', function () {const res = await getVideosList(servers[1].url)const video = res.body.data[0]- expect(video.files).to.have.lengthOf(4)+ const res2 = await getVideo(servers[1].url, video.id)+ const videoDetails = res2.body++ expect(videoDetails.files).to.have.lengthOf(4)- const magnetUri = video.files[0].magnetUri+ const magnetUri = videoDetails.files[0].magnetUriexpect(magnetUri).to.match(/\.mp4/)const torrent = await webtorrentAdd(magnetUri)diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.tsindex 7e1d3f658d..4358f28e30 100644--- a/server/tests/cli/update-host.ts+++ b/server/tests/cli/update-host.ts@@ -13,7 +13,8 @@ import {ServerInfo,setAccessTokensToServers,uploadVideo,- wait+ wait,+ getVideo} from '../utils'describe('Test update host scripts', function () {@@ -55,13 +56,16 @@ describe('Test update host scripts', function () {expect(videos).to.have.lengthOf(2)for (const video of videos) {- expect(video.files).to.have.lengthOf(4)+ const res2 = await getVideo(server.url, video.id)+ const videoDetails = res2.body- for (const file of video.files) {+ expect(videoDetails.files).to.have.lengthOf(4)++ for (const file of videoDetails.files) {expect(file.magnetUri).to.contain('localhost%3A9002%2Ftracker%2Fsocket')expect(file.magnetUri).to.contain('localhost%3A9002%2Fstatic%2Fwebseed%2F')- const torrent = await parseTorrentVideo(server, video.uuid, file.resolution)+ const torrent = await parseTorrentVideo(server, videoDetails.uuid, file.resolution)expect(torrent.announce[0]).to.equal('ws://localhost:9002/tracker/socket')expect(torrent.urlList[0]).to.contain('http://localhost:9002/static/webseed')}diff --git a/server/tests/utils/index.ts b/server/tests/utils/index.tsindex 90ee2d515c..4325e4c941 100644--- a/server/tests/utils/index.ts+++ b/server/tests/utils/index.ts@@ -11,4 +11,5 @@ export * from './services'export * from './users'export * from './video-abuses'export * from './video-blacklist'+export * from './video-channels'export * from './videos'diff --git a/server/tests/utils/login.ts b/server/tests/utils/login.tsindex c9d4aed444..22d37c46f4 100644--- a/server/tests/utils/login.ts+++ b/server/tests/utils/login.ts@@ -32,7 +32,7 @@ async function loginAndGetAccessToken (server: Server) {return res.body.access_token as string}-async function getUserAccessToken (server, user) {+async function getUserAccessToken (server: Server, user: User) {const res = await login(server.url, server.client, user, 200)return res.body.access_token as stringdiff --git a/server/tests/utils/video-channels.ts b/server/tests/utils/video-channels.tsnew file mode 100644index 0000000000..5b436b1835--- /dev/null+++ b/server/tests/utils/video-channels.ts@@ -0,0 +1,95 @@+import * as request from 'supertest'++type VideoChannelAttributes = {+ name?: string+ description?: string+}++function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {+ const path = '/api/v1/videos/channels'++ const req = request(url)+ .get(path)+ .query({ start: start })+ .query({ count: count })++ if (sort) req.query({ sort })++ return req.set('Accept', 'application/json')+ .expect(200)+ .expect('Content-Type', /json/)+}++function getAuthorVideoChannelsList (url: string, authorId: number | string) {+ const path = '/api/v1/videos/authors/' + authorId + '/channels'++ return request(url)+ .get(path)+ .set('Accept', 'application/json')+ .expect(200)+ .expect('Content-Type', /json/)+}++function addVideoChannel (url: string, token: string, videoChannelAttributesArg: VideoChannelAttributes, expectedStatus = 204) {+ const path = '/api/v1/videos/channels'++ // Default attributes+ let attributes = {+ name: 'my super video channel',+ description: 'my super channel description'+ }+ attributes = Object.assign(attributes, videoChannelAttributesArg)++ return request(url)+ .post(path)+ .send(attributes)+ .set('Accept', 'application/json')+ .set('Authorization', 'Bearer ' + token)+ .expect(expectedStatus)+}++function updateVideoChannel (url: string, token: string, channelId: number, attributes: VideoChannelAttributes, expectedStatus = 204) {+ const body = {}+ const path = '/api/v1/videos/channels/' + channelId++ if (attributes.name) body['name'] = attributes.name+ if (attributes.description) body['description'] = attributes.description++ return request(url)+ .put(path)+ .send(body)+ .set('Accept', 'application/json')+ .set('Authorization', 'Bearer ' + token)+ .expect(expectedStatus)+}++function deleteVideoChannel (url: string, token: string, channelId: number, expectedStatus = 204) {+ const path = '/api/v1/videos/channels/'++ return request(url)+ .delete(path + channelId)+ .set('Accept', 'application/json')+ .set('Authorization', 'Bearer ' + token)+ .expect(expectedStatus)+}++function getVideoChannel (url: string, channelId: number) {+ const path = '/api/v1/videos/channels/' + channelId++ return request(url)+ .get(path)+ .set('Accept', 'application/json')+ .expect(200)+ .expect('Content-Type', /json/)+}++// ---------------------------------------------------------------------------++export {+ getVideoChannelsList,+ getAuthorVideoChannelsList,+ addVideoChannel,+ updateVideoChannel,+ deleteVideoChannel,+ getVideoChannel+}diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.tsindex 2a9a236ca5..08fa48da6c 100644--- a/server/tests/utils/videos.ts+++ b/server/tests/utils/videos.ts@@ -6,6 +6,7 @@ import * as parseTorrent from 'parse-torrent'import { makeGetRequest } from './requests'import { readFilePromise } from './miscs'import { ServerInfo } from './servers'+import { getMyUserInformation } from './users'type VideoAttributes = {name?: string@@ -15,6 +16,7 @@ type VideoAttributes = {nsfw?: booleandescription?: stringtags?: string[]+ channelId?: numberfixture?: string}@@ -162,8 +164,14 @@ async function testVideoImage (url: string, imageName: string, imagePath: string}}-function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 204) {+async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 204) {const path = '/api/v1/videos/upload'+ let defaultChannelId = '1'++ try {+ const res = await getMyUserInformation(url, accessToken)+ defaultChannelId = res.body.videoChannels[0].id+ } catch (e) { /* empty */ }// Default attributeslet attributes = {@@ -171,6 +179,7 @@ function uploadVideo (url: string, accessToken: string, videoAttributesArg: Videcategory: 5,licence: 4,language: 3,+ channelId: defaultChannelId,nsfw: true,description: 'my super description',tags: [ 'tag' ],@@ -187,6 +196,7 @@ function uploadVideo (url: string, accessToken: string, videoAttributesArg: Vide.field('licence', attributes.licence.toString()).field('nsfw', JSON.stringify(attributes.nsfw)).field('description', attributes.description)+ .field('channelId', attributes.channelId)if (attributes.language !== undefined) {req.field('language', attributes.language.toString())