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