]>
Commit | Line | Data |
---|---|---|
5f04dd2f C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
5f04dd2f | 3 | import * as chai from 'chai' |
2422c46b | 4 | import 'mocha' |
0f320037 | 5 | import { User, Video } from '../../../../shared/index' |
4bbfc6c6 | 6 | import { |
7c3b7976 | 7 | cleanupTests, |
8a19bee1 | 8 | createUser, |
4bbfc6c6 C |
9 | doubleFollow, |
10 | flushAndRunMultipleServers, | |
d175a6f7 C |
11 | getVideoChannelVideos, |
12 | testImage, | |
4bbfc6c6 C |
13 | updateVideo, |
14 | updateVideoChannelAvatar, | |
d175a6f7 C |
15 | uploadVideo, |
16 | userLogin | |
94565d52 | 17 | } from '../../../../shared/extra-utils' |
5f04dd2f | 18 | import { |
2422c46b C |
19 | addVideoChannel, |
20 | deleteVideoChannel, | |
5f04dd2f | 21 | flushTests, |
2422c46b | 22 | getAccountVideoChannelsList, |
5f04dd2f | 23 | getMyUserInformation, |
2422c46b | 24 | getVideoChannel, |
5f04dd2f | 25 | getVideoChannelsList, |
2422c46b C |
26 | killallServers, |
27 | ServerInfo, | |
28 | setAccessTokensToServers, | |
29 | updateVideoChannel | |
94565d52 C |
30 | } from '../../../../shared/extra-utils/index' |
31 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
5f04dd2f | 32 | |
2422c46b C |
33 | const expect = chai.expect |
34 | ||
35 | describe('Test video channels', function () { | |
36 | let servers: ServerInfo[] | |
5f04dd2f | 37 | let userInfo: User |
6b738c7a | 38 | let accountUUID: string |
0f320037 | 39 | let firstVideoChannelId: number |
0f320037 | 40 | let secondVideoChannelId: number |
0f320037 | 41 | let videoUUID: string |
5f04dd2f C |
42 | |
43 | before(async function () { | |
e212f887 | 44 | this.timeout(30000) |
5f04dd2f | 45 | |
2422c46b C |
46 | servers = await flushAndRunMultipleServers(2) |
47 | ||
48 | await setAccessTokensToServers(servers) | |
49 | await doubleFollow(servers[0], servers[1]) | |
5f04dd2f | 50 | |
48dce1c9 | 51 | { |
6b738c7a C |
52 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) |
53 | const user: User = res.body | |
54 | accountUUID = user.account.uuid | |
0f320037 C |
55 | |
56 | firstVideoChannelId = user.videoChannels[0].id | |
48dce1c9 C |
57 | } |
58 | ||
3cd0734f | 59 | await waitJobs(servers) |
5f04dd2f C |
60 | }) |
61 | ||
62 | it('Should have one video channel (created with root)', async () => { | |
2422c46b | 63 | const res = await getVideoChannelsList(servers[0].url, 0, 2) |
5f04dd2f C |
64 | |
65 | expect(res.body.total).to.equal(1) | |
66 | expect(res.body.data).to.be.an('array') | |
67 | expect(res.body.data).to.have.lengthOf(1) | |
68 | }) | |
69 | ||
2422c46b C |
70 | it('Should create another video channel', async function () { |
71 | this.timeout(10000) | |
72 | ||
0f320037 C |
73 | { |
74 | const videoChannel = { | |
8a19bee1 | 75 | name: 'second_video_channel', |
0f320037 C |
76 | displayName: 'second video channel', |
77 | description: 'super video channel description', | |
78 | support: 'super video channel support text' | |
79 | } | |
80 | const res = await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, videoChannel) | |
81 | secondVideoChannelId = res.body.videoChannel.id | |
5f04dd2f | 82 | } |
2422c46b C |
83 | |
84 | // The channel is 1 is propagated to servers 2 | |
0f320037 C |
85 | { |
86 | const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'my video name', channelId: secondVideoChannelId }) | |
87 | videoUUID = res.body.video.uuid | |
88 | } | |
2422c46b | 89 | |
3cd0734f | 90 | await waitJobs(servers) |
5f04dd2f C |
91 | }) |
92 | ||
93 | it('Should have two video channels when getting my information', async () => { | |
2422c46b | 94 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) |
5f04dd2f C |
95 | userInfo = res.body |
96 | ||
97 | expect(userInfo.videoChannels).to.be.an('array') | |
98 | expect(userInfo.videoChannels).to.have.lengthOf(2) | |
99 | ||
100 | const videoChannels = userInfo.videoChannels | |
8a19bee1 C |
101 | expect(videoChannels[0].name).to.equal('root_channel') |
102 | expect(videoChannels[0].displayName).to.equal('Main root channel') | |
103 | ||
104 | expect(videoChannels[1].name).to.equal('second_video_channel') | |
7bc29171 | 105 | expect(videoChannels[1].displayName).to.equal('second video channel') |
5f04dd2f | 106 | expect(videoChannels[1].description).to.equal('super video channel description') |
2422c46b | 107 | expect(videoChannels[1].support).to.equal('super video channel support text') |
5f04dd2f C |
108 | }) |
109 | ||
2422c46b | 110 | it('Should have two video channels when getting account channels on server 1', async function () { |
ad9e39fb | 111 | const res = await getAccountVideoChannelsList(servers[0].url, userInfo.account.name + '@' + userInfo.account.host) |
5f04dd2f C |
112 | expect(res.body.total).to.equal(2) |
113 | expect(res.body.data).to.be.an('array') | |
114 | expect(res.body.data).to.have.lengthOf(2) | |
115 | ||
116 | const videoChannels = res.body.data | |
8a19bee1 C |
117 | expect(videoChannels[0].name).to.equal('root_channel') |
118 | expect(videoChannels[0].displayName).to.equal('Main root channel') | |
119 | ||
120 | expect(videoChannels[1].name).to.equal('second_video_channel') | |
7bc29171 | 121 | expect(videoChannels[1].displayName).to.equal('second video channel') |
5f04dd2f | 122 | expect(videoChannels[1].description).to.equal('super video channel description') |
2422c46b C |
123 | expect(videoChannels[1].support).to.equal('super video channel support text') |
124 | }) | |
125 | ||
126 | it('Should have one video channel when getting account channels on server 2', async function () { | |
ad9e39fb | 127 | const res = await getAccountVideoChannelsList(servers[1].url, userInfo.account.name + '@' + userInfo.account.host) |
2422c46b C |
128 | expect(res.body.total).to.equal(1) |
129 | expect(res.body.data).to.be.an('array') | |
130 | expect(res.body.data).to.have.lengthOf(1) | |
5f04dd2f | 131 | |
2422c46b | 132 | const videoChannels = res.body.data |
8a19bee1 | 133 | expect(videoChannels[0].name).to.equal('second_video_channel') |
2422c46b C |
134 | expect(videoChannels[0].displayName).to.equal('second video channel') |
135 | expect(videoChannels[0].description).to.equal('super video channel description') | |
136 | expect(videoChannels[0].support).to.equal('super video channel support text') | |
5f04dd2f C |
137 | }) |
138 | ||
2422c46b C |
139 | it('Should list video channels', async function () { |
140 | const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name') | |
5f04dd2f C |
141 | |
142 | expect(res.body.total).to.equal(2) | |
143 | expect(res.body.data).to.be.an('array') | |
144 | expect(res.body.data).to.have.lengthOf(1) | |
8a19bee1 C |
145 | expect(res.body.data[0].name).to.equal('root_channel') |
146 | expect(res.body.data[0].displayName).to.equal('Main root channel') | |
5f04dd2f C |
147 | }) |
148 | ||
2422c46b C |
149 | it('Should update video channel', async function () { |
150 | this.timeout(5000) | |
151 | ||
5f04dd2f | 152 | const videoChannelAttributes = { |
08c1efbe | 153 | displayName: 'video channel updated', |
2422c46b C |
154 | description: 'video channel description updated', |
155 | support: 'video channel support text updated' | |
5f04dd2f C |
156 | } |
157 | ||
8a19bee1 | 158 | await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes) |
2422c46b | 159 | |
3cd0734f | 160 | await waitJobs(servers) |
5f04dd2f C |
161 | }) |
162 | ||
2422c46b C |
163 | it('Should have video channel updated', async function () { |
164 | for (const server of servers) { | |
165 | const res = await getVideoChannelsList(server.url, 0, 1, '-name') | |
5f04dd2f | 166 | |
2422c46b C |
167 | expect(res.body.total).to.equal(2) |
168 | expect(res.body.data).to.be.an('array') | |
169 | expect(res.body.data).to.have.lengthOf(1) | |
8a19bee1 | 170 | expect(res.body.data[0].name).to.equal('second_video_channel') |
2422c46b C |
171 | expect(res.body.data[0].displayName).to.equal('video channel updated') |
172 | expect(res.body.data[0].description).to.equal('video channel description updated') | |
173 | expect(res.body.data[0].support).to.equal('video channel support text updated') | |
174 | } | |
5f04dd2f C |
175 | }) |
176 | ||
4bbfc6c6 C |
177 | it('Should update video channel avatar', async function () { |
178 | this.timeout(5000) | |
179 | ||
180 | const fixture = 'avatar.png' | |
181 | ||
182 | await updateVideoChannelAvatar({ | |
183 | url: servers[0].url, | |
184 | accessToken: servers[0].accessToken, | |
8a19bee1 | 185 | videoChannelName: 'second_video_channel', |
4bbfc6c6 C |
186 | fixture |
187 | }) | |
188 | ||
189 | await waitJobs(servers) | |
190 | }) | |
191 | ||
192 | it('Should have video channel avatar updated', async function () { | |
193 | for (const server of servers) { | |
194 | const res = await getVideoChannelsList(server.url, 0, 1, '-name') | |
195 | ||
196 | const videoChannel = res.body.data.find(c => c.id === secondVideoChannelId) | |
197 | ||
198 | await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png') | |
199 | } | |
200 | }) | |
201 | ||
2422c46b | 202 | it('Should get video channel', async function () { |
8a19bee1 | 203 | const res = await getVideoChannel(servers[0].url, 'second_video_channel') |
5f04dd2f C |
204 | |
205 | const videoChannel = res.body | |
8a19bee1 | 206 | expect(videoChannel.name).to.equal('second_video_channel') |
7bc29171 | 207 | expect(videoChannel.displayName).to.equal('video channel updated') |
5f04dd2f | 208 | expect(videoChannel.description).to.equal('video channel description updated') |
2422c46b | 209 | expect(videoChannel.support).to.equal('video channel support text updated') |
5f04dd2f C |
210 | }) |
211 | ||
0f320037 | 212 | it('Should list the second video channel videos', async function () { |
6b738c7a C |
213 | this.timeout(10000) |
214 | ||
215 | for (const server of servers) { | |
8a19bee1 C |
216 | const channelURI = 'second_video_channel@localhost:9001' |
217 | const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) | |
0f320037 C |
218 | expect(res1.body.total).to.equal(1) |
219 | expect(res1.body.data).to.be.an('array') | |
220 | expect(res1.body.data).to.have.lengthOf(1) | |
221 | expect(res1.body.data[0].name).to.equal('my video name') | |
222 | } | |
223 | }) | |
224 | ||
225 | it('Should change the video channel of a video', async function () { | |
226 | this.timeout(10000) | |
227 | ||
228 | await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId }) | |
229 | ||
3cd0734f | 230 | await waitJobs(servers) |
0f320037 C |
231 | }) |
232 | ||
233 | it('Should list the first video channel videos', async function () { | |
234 | this.timeout(10000) | |
235 | ||
236 | for (const server of servers) { | |
8a19bee1 C |
237 | const secondChannelURI = 'second_video_channel@localhost:9001' |
238 | const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5) | |
0f320037 C |
239 | expect(res1.body.total).to.equal(0) |
240 | ||
8a19bee1 C |
241 | const channelURI = 'root_channel@localhost:9001' |
242 | const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) | |
0f320037 C |
243 | expect(res2.body.total).to.equal(1) |
244 | ||
245 | const videos: Video[] = res2.body.data | |
246 | expect(videos).to.be.an('array') | |
247 | expect(videos).to.have.lengthOf(1) | |
248 | expect(videos[0].name).to.equal('my video name') | |
6b738c7a C |
249 | } |
250 | }) | |
251 | ||
2422c46b | 252 | it('Should delete video channel', async function () { |
8a19bee1 | 253 | await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel') |
5f04dd2f C |
254 | }) |
255 | ||
2422c46b C |
256 | it('Should have video channel deleted', async function () { |
257 | const res = await getVideoChannelsList(servers[0].url, 0, 10) | |
5f04dd2f C |
258 | |
259 | expect(res.body.total).to.equal(1) | |
260 | expect(res.body.data).to.be.an('array') | |
261 | expect(res.body.data).to.have.lengthOf(1) | |
8a19bee1 C |
262 | expect(res.body.data[0].displayName).to.equal('Main root channel') |
263 | }) | |
264 | ||
265 | it('Should create the main channel with an uuid if there is a conflict', async function () { | |
266 | { | |
267 | const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' } | |
268 | await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, videoChannel) | |
269 | } | |
270 | ||
271 | { | |
1eddc9a7 | 272 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'toto', password: 'password' }) |
8a19bee1 C |
273 | const accessToken = await userLogin(servers[ 0 ], { username: 'toto', password: 'password' }) |
274 | ||
275 | const res = await getMyUserInformation(servers[ 0 ].url, accessToken) | |
276 | const videoChannel = res.body.videoChannels[ 0 ] | |
277 | expect(videoChannel.name).to.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/) | |
278 | } | |
5f04dd2f C |
279 | }) |
280 | ||
7c3b7976 C |
281 | after(async function () { |
282 | await cleanupTests(servers) | |
5f04dd2f C |
283 | }) |
284 | }) |