]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-channels.ts
Do not enable cors twice on /api in test mode
[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 4import 'mocha'
0f320037 5import { User, Video } from '../../../../shared/index'
3cd0734f 6import { doubleFollow, flushAndRunMultipleServers, getVideoChannelVideos, updateVideo, uploadVideo } 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'
3cd0734f 20import { waitJobs } from '../../utils/server/jobs'
5f04dd2f 21
2422c46b
C
22const expect = chai.expect
23
24describe('Test video channels', function () {
25 let servers: ServerInfo[]
5f04dd2f 26 let userInfo: User
6b738c7a 27 let accountUUID: string
0f320037
C
28 let firstVideoChannelId: number
29 let firstVideoChannelUUID: string
30 let secondVideoChannelId: number
31 let secondVideoChannelUUID: string
32 let videoUUID: string
5f04dd2f
C
33
34 before(async function () {
e212f887 35 this.timeout(30000)
5f04dd2f
C
36
37 await flushTests()
38
2422c46b
C
39 servers = await flushAndRunMultipleServers(2)
40
41 await setAccessTokensToServers(servers)
42 await doubleFollow(servers[0], servers[1])
5f04dd2f 43
48dce1c9 44 {
6b738c7a
C
45 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
46 const user: User = res.body
47 accountUUID = user.account.uuid
0f320037
C
48
49 firstVideoChannelId = user.videoChannels[0].id
50 firstVideoChannelUUID = user.videoChannels[0].uuid
48dce1c9
C
51 }
52
3cd0734f 53 await waitJobs(servers)
5f04dd2f
C
54 })
55
56 it('Should have one video channel (created with root)', async () => {
2422c46b 57 const res = await getVideoChannelsList(servers[0].url, 0, 2)
5f04dd2f
C
58
59 expect(res.body.total).to.equal(1)
60 expect(res.body.data).to.be.an('array')
61 expect(res.body.data).to.have.lengthOf(1)
62 })
63
2422c46b
C
64 it('Should create another video channel', async function () {
65 this.timeout(10000)
66
0f320037
C
67 {
68 const videoChannel = {
69 displayName: 'second video channel',
70 description: 'super video channel description',
71 support: 'super video channel support text'
72 }
73 const res = await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, videoChannel)
74 secondVideoChannelId = res.body.videoChannel.id
75 secondVideoChannelUUID = res.body.videoChannel.uuid
5f04dd2f 76 }
2422c46b
C
77
78 // The channel is 1 is propagated to servers 2
0f320037
C
79 {
80 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'my video name', channelId: secondVideoChannelId })
81 videoUUID = res.body.video.uuid
82 }
2422c46b 83
3cd0734f 84 await waitJobs(servers)
5f04dd2f
C
85 })
86
87 it('Should have two video channels when getting my information', async () => {
2422c46b 88 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
5f04dd2f
C
89 userInfo = res.body
90
91 expect(userInfo.videoChannels).to.be.an('array')
92 expect(userInfo.videoChannels).to.have.lengthOf(2)
93
94 const videoChannels = userInfo.videoChannels
7bc29171
C
95 expect(videoChannels[0].displayName).to.equal('Default root channel')
96 expect(videoChannels[1].displayName).to.equal('second video channel')
5f04dd2f 97 expect(videoChannels[1].description).to.equal('super video channel description')
2422c46b 98 expect(videoChannels[1].support).to.equal('super video channel support text')
5f04dd2f
C
99 })
100
2422c46b 101 it('Should have two video channels when getting account channels on server 1', async function () {
ad9e39fb 102 const res = await getAccountVideoChannelsList(servers[0].url, userInfo.account.name + '@' + userInfo.account.host)
5f04dd2f
C
103 expect(res.body.total).to.equal(2)
104 expect(res.body.data).to.be.an('array')
105 expect(res.body.data).to.have.lengthOf(2)
106
107 const videoChannels = res.body.data
7bc29171
C
108 expect(videoChannels[0].displayName).to.equal('Default root channel')
109 expect(videoChannels[1].displayName).to.equal('second video channel')
5f04dd2f 110 expect(videoChannels[1].description).to.equal('super video channel description')
2422c46b
C
111 expect(videoChannels[1].support).to.equal('super video channel support text')
112 })
113
114 it('Should have one video channel when getting account channels on server 2', async function () {
ad9e39fb 115 const res = await getAccountVideoChannelsList(servers[1].url, userInfo.account.name + '@' + userInfo.account.host)
2422c46b
C
116 expect(res.body.total).to.equal(1)
117 expect(res.body.data).to.be.an('array')
118 expect(res.body.data).to.have.lengthOf(1)
5f04dd2f 119
2422c46b
C
120 const videoChannels = res.body.data
121 expect(videoChannels[0].displayName).to.equal('second video channel')
122 expect(videoChannels[0].description).to.equal('super video channel description')
123 expect(videoChannels[0].support).to.equal('super video channel support text')
5f04dd2f
C
124 })
125
2422c46b
C
126 it('Should list video channels', async function () {
127 const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name')
5f04dd2f
C
128
129 expect(res.body.total).to.equal(2)
130 expect(res.body.data).to.be.an('array')
131 expect(res.body.data).to.have.lengthOf(1)
7bc29171 132 expect(res.body.data[0].displayName).to.equal('Default root channel')
5f04dd2f
C
133 })
134
2422c46b
C
135 it('Should update video channel', async function () {
136 this.timeout(5000)
137
5f04dd2f 138 const videoChannelAttributes = {
08c1efbe 139 displayName: 'video channel updated',
2422c46b
C
140 description: 'video channel description updated',
141 support: 'video channel support text updated'
5f04dd2f
C
142 }
143
0f320037 144 await updateVideoChannel(servers[0].url, servers[0].accessToken, secondVideoChannelId, videoChannelAttributes)
2422c46b 145
3cd0734f 146 await waitJobs(servers)
5f04dd2f
C
147 })
148
2422c46b
C
149 it('Should have video channel updated', async function () {
150 for (const server of servers) {
151 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
5f04dd2f 152
2422c46b
C
153 expect(res.body.total).to.equal(2)
154 expect(res.body.data).to.be.an('array')
155 expect(res.body.data).to.have.lengthOf(1)
156 expect(res.body.data[0].displayName).to.equal('video channel updated')
157 expect(res.body.data[0].description).to.equal('video channel description updated')
158 expect(res.body.data[0].support).to.equal('video channel support text updated')
159 }
5f04dd2f
C
160 })
161
2422c46b 162 it('Should get video channel', async function () {
0f320037 163 const res = await getVideoChannel(servers[0].url, secondVideoChannelId)
5f04dd2f
C
164
165 const videoChannel = res.body
7bc29171 166 expect(videoChannel.displayName).to.equal('video channel updated')
5f04dd2f 167 expect(videoChannel.description).to.equal('video channel description updated')
2422c46b 168 expect(videoChannel.support).to.equal('video channel support text updated')
5f04dd2f
C
169 })
170
0f320037 171 it('Should list the second video channel videos', async function () {
6b738c7a
C
172 this.timeout(10000)
173
174 for (const server of servers) {
0f320037
C
175 const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondVideoChannelUUID, 0, 5)
176 expect(res1.body.total).to.equal(1)
177 expect(res1.body.data).to.be.an('array')
178 expect(res1.body.data).to.have.lengthOf(1)
179 expect(res1.body.data[0].name).to.equal('my video name')
180 }
181 })
182
183 it('Should change the video channel of a video', async function () {
184 this.timeout(10000)
185
186 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId })
187
3cd0734f 188 await waitJobs(servers)
0f320037
C
189 })
190
191 it('Should list the first video channel videos', async function () {
192 this.timeout(10000)
193
194 for (const server of servers) {
195 const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondVideoChannelUUID, 0, 5)
196 expect(res1.body.total).to.equal(0)
197
198 const res2 = await getVideoChannelVideos(server.url, server.accessToken, firstVideoChannelUUID, 0, 5)
199 expect(res2.body.total).to.equal(1)
200
201 const videos: Video[] = res2.body.data
202 expect(videos).to.be.an('array')
203 expect(videos).to.have.lengthOf(1)
204 expect(videos[0].name).to.equal('my video name')
6b738c7a
C
205 }
206 })
207
2422c46b 208 it('Should delete video channel', async function () {
0f320037 209 await deleteVideoChannel(servers[0].url, servers[0].accessToken, secondVideoChannelId)
5f04dd2f
C
210 })
211
2422c46b
C
212 it('Should have video channel deleted', async function () {
213 const res = await getVideoChannelsList(servers[0].url, 0, 10)
5f04dd2f
C
214
215 expect(res.body.total).to.equal(1)
216 expect(res.body.data).to.be.an('array')
217 expect(res.body.data).to.have.lengthOf(1)
7bc29171 218 expect(res.body.data[0].displayName).to.equal('Default root channel')
5f04dd2f
C
219 })
220
221 after(async function () {
2422c46b 222 killallServers(servers)
5f04dd2f
C
223 })
224})