]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-channels.ts
Update the api documentation
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-channels.ts
CommitLineData
5f04dd2f
C
1/* tslint:disable:no-unused-expression */
2
5f04dd2f 3import * as chai from 'chai'
2422c46b
C
4import 'mocha'
5import { User } from '../../../../shared/index'
6import { doubleFollow, flushAndRunMultipleServers, uploadVideo, wait } from '../../utils'
5f04dd2f 7import {
2422c46b
C
8 addVideoChannel,
9 deleteVideoChannel,
5f04dd2f 10 flushTests,
2422c46b 11 getAccountVideoChannelsList,
5f04dd2f 12 getMyUserInformation,
2422c46b 13 getVideoChannel,
5f04dd2f 14 getVideoChannelsList,
2422c46b
C
15 killallServers,
16 ServerInfo,
17 setAccessTokensToServers,
18 updateVideoChannel
c5d31dba 19} from '../../utils/index'
5f04dd2f 20
2422c46b
C
21const expect = chai.expect
22
23describe('Test video channels', function () {
24 let servers: ServerInfo[]
5f04dd2f
C
25 let userInfo: User
26 let videoChannelId: number
27
28 before(async function () {
e212f887 29 this.timeout(30000)
5f04dd2f
C
30
31 await flushTests()
32
2422c46b
C
33 servers = await flushAndRunMultipleServers(2)
34
35 await setAccessTokensToServers(servers)
36 await doubleFollow(servers[0], servers[1])
5f04dd2f 37
2422c46b 38 await wait(5000)
5f04dd2f
C
39 })
40
41 it('Should have one video channel (created with root)', async () => {
2422c46b 42 const res = await getVideoChannelsList(servers[0].url, 0, 2)
5f04dd2f
C
43
44 expect(res.body.total).to.equal(1)
45 expect(res.body.data).to.be.an('array')
46 expect(res.body.data).to.have.lengthOf(1)
47 })
48
2422c46b
C
49 it('Should create another video channel', async function () {
50 this.timeout(10000)
51
5f04dd2f
C
52 const videoChannel = {
53 name: 'second video channel',
2422c46b
C
54 description: 'super video channel description',
55 support: 'super video channel support text'
5f04dd2f 56 }
2422c46b
C
57 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
58 videoChannelId = res.body.videoChannel.id
59
60 // The channel is 1 is propagated to servers 2
61 await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: videoChannelId })
62
63 await wait(3000)
5f04dd2f
C
64 })
65
66 it('Should have two video channels when getting my information', async () => {
2422c46b 67 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
5f04dd2f
C
68 userInfo = res.body
69
70 expect(userInfo.videoChannels).to.be.an('array')
71 expect(userInfo.videoChannels).to.have.lengthOf(2)
72
73 const videoChannels = userInfo.videoChannels
7bc29171
C
74 expect(videoChannels[0].displayName).to.equal('Default root channel')
75 expect(videoChannels[1].displayName).to.equal('second video channel')
5f04dd2f 76 expect(videoChannels[1].description).to.equal('super video channel description')
2422c46b 77 expect(videoChannels[1].support).to.equal('super video channel support text')
5f04dd2f
C
78 })
79
2422c46b
C
80 it('Should have two video channels when getting account channels on server 1', async function () {
81 const res = await getAccountVideoChannelsList(servers[0].url, userInfo.account.uuid)
5f04dd2f
C
82 expect(res.body.total).to.equal(2)
83 expect(res.body.data).to.be.an('array')
84 expect(res.body.data).to.have.lengthOf(2)
85
86 const videoChannels = res.body.data
7bc29171
C
87 expect(videoChannels[0].displayName).to.equal('Default root channel')
88 expect(videoChannels[1].displayName).to.equal('second video channel')
5f04dd2f 89 expect(videoChannels[1].description).to.equal('super video channel description')
2422c46b
C
90 expect(videoChannels[1].support).to.equal('super video channel support text')
91 })
92
93 it('Should have one video channel when getting account channels on server 2', async function () {
94 const res = await getAccountVideoChannelsList(servers[1].url, userInfo.account.uuid)
95 expect(res.body.total).to.equal(1)
96 expect(res.body.data).to.be.an('array')
97 expect(res.body.data).to.have.lengthOf(1)
5f04dd2f 98
2422c46b
C
99 const videoChannels = res.body.data
100 expect(videoChannels[0].displayName).to.equal('second video channel')
101 expect(videoChannels[0].description).to.equal('super video channel description')
102 expect(videoChannels[0].support).to.equal('super video channel support text')
5f04dd2f
C
103 })
104
2422c46b
C
105 it('Should list video channels', async function () {
106 const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name')
5f04dd2f
C
107
108 expect(res.body.total).to.equal(2)
109 expect(res.body.data).to.be.an('array')
110 expect(res.body.data).to.have.lengthOf(1)
7bc29171 111 expect(res.body.data[0].displayName).to.equal('Default root channel')
5f04dd2f
C
112 })
113
2422c46b
C
114 it('Should update video channel', async function () {
115 this.timeout(5000)
116
5f04dd2f
C
117 const videoChannelAttributes = {
118 name: 'video channel updated',
2422c46b
C
119 description: 'video channel description updated',
120 support: 'video channel support text updated'
5f04dd2f
C
121 }
122
2422c46b
C
123 await updateVideoChannel(servers[0].url, servers[0].accessToken, videoChannelId, videoChannelAttributes)
124
125 await wait(3000)
5f04dd2f
C
126 })
127
2422c46b
C
128 it('Should have video channel updated', async function () {
129 for (const server of servers) {
130 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
5f04dd2f 131
2422c46b
C
132 expect(res.body.total).to.equal(2)
133 expect(res.body.data).to.be.an('array')
134 expect(res.body.data).to.have.lengthOf(1)
135 expect(res.body.data[0].displayName).to.equal('video channel updated')
136 expect(res.body.data[0].description).to.equal('video channel description updated')
137 expect(res.body.data[0].support).to.equal('video channel support text updated')
138 }
5f04dd2f
C
139 })
140
2422c46b
C
141 it('Should get video channel', async function () {
142 const res = await getVideoChannel(servers[0].url, videoChannelId)
5f04dd2f
C
143
144 const videoChannel = res.body
7bc29171 145 expect(videoChannel.displayName).to.equal('video channel updated')
5f04dd2f 146 expect(videoChannel.description).to.equal('video channel description updated')
2422c46b 147 expect(videoChannel.support).to.equal('video channel support text updated')
5f04dd2f
C
148 })
149
2422c46b
C
150 it('Should delete video channel', async function () {
151 await deleteVideoChannel(servers[0].url, servers[0].accessToken, videoChannelId)
5f04dd2f
C
152 })
153
2422c46b
C
154 it('Should have video channel deleted', async function () {
155 const res = await getVideoChannelsList(servers[0].url, 0, 10)
5f04dd2f
C
156
157 expect(res.body.total).to.equal(1)
158 expect(res.body.data).to.be.an('array')
159 expect(res.body.data).to.have.lengthOf(1)
7bc29171 160 expect(res.body.data[0].displayName).to.equal('Default root channel')
5f04dd2f
C
161 })
162
163 after(async function () {
2422c46b 164 killallServers(servers)
5f04dd2f
C
165
166 // Keep the logs if the test failed
167 if (this['ok']) {
168 await flushTests()
169 }
170 })
171})