/* tslint:disable:no-unused-expression */
+import 'mocha'
+
import {
ServerInfo,
flushTests,
--- /dev/null
+/* 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()
+ }
+ })
+})
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
// ---------------------------------------------------------------
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 () {
language: 6,
nsfw: false,
description: 'my super description',
- tags: [ 'tag1', 'tag2' ]
+ tags: [ 'tag1', 'tag2' ],
+ channelId
}
const attaches = {
'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
language: 6,
nsfw: false,
description: 'my super description',
- tags: [ 'tag1', 'tag2' ]
+ tags: [ 'tag1', 'tag2' ],
+ channelId
}
const attaches = {
'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
language: 6,
nsfw: false,
description: 'my super description',
- tags: [ 'tag1', 'tag2' ]
+ tags: [ 'tag1', 'tag2' ],
+ channelId
}
const attaches = {
'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
language: 6,
nsfw: false,
description: 'my super description',
- tags: [ 'tag1', 'tag2' ]
+ tags: [ 'tag1', 'tag2' ],
+ channelId
}
const attaches = {
'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
language: 6,
nsfw: false,
description: 'my super description',
- tags: [ 'tag1', 'tag2' ]
+ tags: [ 'tag1', 'tag2' ],
+ channelId
}
const attaches = {
'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
language: 6,
nsfw: false,
description: 'my super description',
- tags: [ 'tag1', 'tag2' ]
+ tags: [ 'tag1', 'tag2' ],
+ channelId
}
const attaches = {
'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
language: 563,
nsfw: false,
description: 'my super description',
- tags: [ 'tag1', 'tag2' ]
+ tags: [ 'tag1', 'tag2' ],
+ channelId
}
const attaches = {
'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
licence: 4,
language: 6,
description: 'my super description',
- tags: [ 'tag1', 'tag2' ]
+ 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 a bad nsfw attribue', async function () {
+ it('Should fail with a bad nsfw attribute', async function () {
const fields = {
name: 'my super name',
category: 5,
language: 6,
nsfw: 2,
description: 'my super description',
- tags: [ 'tag1', 'tag2' ]
+ tags: [ 'tag1', 'tag2' ],
+ channelId
}
const attaches = {
'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
licence: 1,
language: 6,
nsfw: false,
- tags: [ 'tag1', 'tag2' ]
+ tags: [ 'tag1', 'tag2' ],
+ channelId
}
const attaches = {
'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
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 = {
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',
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')
language: 6,
nsfw: false,
description: 'my super description',
- tags: [ 'tag1', 't' ]
+ tags: [ 'tag1', 't' ],
+ channelId
}
const attaches = {
'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
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')
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 })
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')
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')
language: 6,
nsfw: false,
description: 'my super description',
- tags: [ 'tag1', 'tag2' ]
+ tags: [ 'tag1', 'tag2' ],
+ channelId
}
const attaches = {
'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
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
// Pod 4 makes friend with the second one
await 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 first
await makeFriendsWrapper(5)
await wait(11000)
}
})
- 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 friends
await makeFriendsWrapper(2)
expect(res.body.data.length).to.equal(3)
}
+ // Wait initial video channel requests
+ await wait(11000)
+
// Kill pod 4
servers[3].app.kill()
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) {
}
}
- // Rerun server 4
+ // Rerun server 4
const newServer = await runServer(4)
servers[3].app = newServer.app
servers[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 3
await 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.data
expect(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 3
it('Should pod 1 quit friends', async function () {
this.timeout(25000)
await wait(15000)
+ // Pod 1 remove friends
await quitFriendsWrapper(1)
- // Remove pod 1 from pod 2
const res1 = await getVideosWrapper(1)
const videos1 = res1.body.data
expect(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.data
expect(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)
const res = await getVideosWrapper(1)
const videos = res.body.data
expect(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 friends
const pod1 = friends[0]
expect(pod1.host).to.equal(servers[2].host)
expect(pod1.email).to.equal('admin3@example.com')
- 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
const pod2 = result[0]
expect(pod2.host).to.equal(servers[1].host)
expect(pod2.email).to.equal('admin2@example.com')
- 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
const pod = res.body.data[0]
expect(pod.host).to.equal('localhost:9002')
expect(pod.email).to.equal('admin2@example.com')
- expect(pod.score).to.equal(20)
+ expect(pod.score).to.be.at.least(20)
expect(dateIsValid(pod.createdAt)).to.be.true
})
updateVideo,
uploadVideo,
wait,
- webtorrentAdd
+ webtorrentAdd,
+ addVideoChannel,
+ getVideoChannelsList,
+ getUserAccessToken
} from '../utils'
+import { createUser } from '../utils/users'
const expect = chai.expect
let servers: ServerInfo[] = []
const toRemove = []
let videoUUID = ''
+ let videoChannelId: number
before(async function () {
this.timeout(120000)
// Get the access tokens
await 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 third
await makeFriends(servers[1].url, servers[1].accessToken)
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)
expect(dateIsValid(video.updatedAt)).to.be.true
expect(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.magnetUri
expect(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
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,
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 22000
await wait(60000)
expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
expect(dateIsValid(video.createdAt)).to.be.true
expect(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 Uri
if (baseMagnet[file.resolution] === undefined) {
baseMagnet[file.resolution] = file.magnet
}
}
- const file240p = video.files.find(f => f.resolution === 240)
+ const file240p = videoDetails.files.find(f => f.resolution === 240)
expect(file240p).not.to.be.undefined
expect(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.undefined
expect(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.undefined
expect(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.undefined
expect(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)
}
})
expect(dateIsValid(video1.createdAt)).to.be.true
expect(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')
expect(dateIsValid(video2.createdAt)).to.be.true
expect(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.magnetUri
expect(file2.magnetUri).to.have.lengthOf.above(2)
expect(file2.resolution).to.equal(720)
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('')
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('')
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('')
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('')
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.undefined
const torrent = await webtorrentAdd(file.magnetUri)
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 () {
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)
}
})
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')
// Avoid "duplicate torrent" errors
const 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('')
const res = await getRequestsStats(server)
const requestSchedulers = res.body
const requestScheduler = requestSchedulers.requestScheduler
- expect(requestScheduler.totalRequests).to.equal(1)
+ expect(requestScheduler.totalRequests).to.equal(3)
})
after(async function () {
expect(dateIsValid(video.createdAt)).to.be.true
expect(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.magnetUri
expect(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.uuid
const torrent = await webtorrentAdd(magnetUri)
expect(torrent.files).to.be.an('array')
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
expect(dateIsValid(video.createdAt)).to.be.true
expect(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 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 () {
expect(dateIsValid(video.createdAt)).to.be.true
expect(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)
})
expect(dateIsValid(video.createdAt)).to.be.true
expect(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)
})
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)
})
expect(dateIsValid(video.createdAt)).to.be.true
expect(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]
expect(dateIsValid(video.createdAt)).to.be.true
expect(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]
expect(dateIsValid(video.createdAt)).to.be.true
expect(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]
})
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')
--- /dev/null
+/* 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()
+ }
+ })
+})
setAccessTokensToServers,
flushAndRunMultipleServers,
killallServers,
- webtorrentAdd
+ webtorrentAdd,
+ getVideo
} from '../utils'
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].magnetUri
expect(magnetUri).to.match(/\.webm/)
const torrent = await webtorrentAdd(magnetUri)
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].magnetUri
expect(magnetUri).to.match(/\.mp4/)
const torrent = await webtorrentAdd(magnetUri)
ServerInfo,
setAccessTokensToServers,
uploadVideo,
- wait
+ wait,
+ getVideo
} from '../utils'
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')
}
export * from './users'
export * from './video-abuses'
export * from './video-blacklist'
+export * from './video-channels'
export * from './videos'
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 string
--- /dev/null
+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
+}
import { makeGetRequest } from './requests'
import { readFilePromise } from './miscs'
import { ServerInfo } from './servers'
+import { getMyUserInformation } from './users'
type VideoAttributes = {
name?: string
nsfw?: boolean
description?: string
tags?: string[]
+ channelId?: number
fixture?: 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 attributes
let attributes = {
category: 5,
licence: 4,
language: 3,
+ channelId: defaultChannelId,
nsfw: true,
description: 'my super description',
tags: [ 'tag' ],
.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())