]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { User, Video } from '../../../../shared/index' | |
6 | import { | |
7 | cleanupTests, | |
8 | createUser, | |
9 | doubleFollow, | |
10 | flushAndRunMultipleServers, | |
11 | getVideoChannelVideos, | |
12 | testImage, | |
13 | updateVideo, | |
14 | updateVideoChannelAvatar, | |
15 | uploadVideo, | |
16 | userLogin | |
17 | } from '../../../../shared/extra-utils' | |
18 | import { | |
19 | addVideoChannel, | |
20 | deleteVideoChannel, | |
21 | flushTests, | |
22 | getAccountVideoChannelsList, | |
23 | getMyUserInformation, | |
24 | getVideoChannel, | |
25 | getVideoChannelsList, | |
26 | killallServers, | |
27 | ServerInfo, | |
28 | setAccessTokensToServers, | |
29 | updateVideoChannel | |
30 | } from '../../../../shared/extra-utils/index' | |
31 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
32 | ||
33 | const expect = chai.expect | |
34 | ||
35 | describe('Test video channels', function () { | |
36 | let servers: ServerInfo[] | |
37 | let userInfo: User | |
38 | let accountUUID: string | |
39 | let firstVideoChannelId: number | |
40 | let secondVideoChannelId: number | |
41 | let videoUUID: string | |
42 | ||
43 | before(async function () { | |
44 | this.timeout(30000) | |
45 | ||
46 | servers = await flushAndRunMultipleServers(2) | |
47 | ||
48 | await setAccessTokensToServers(servers) | |
49 | await doubleFollow(servers[0], servers[1]) | |
50 | ||
51 | { | |
52 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | |
53 | const user: User = res.body | |
54 | accountUUID = user.account.uuid | |
55 | ||
56 | firstVideoChannelId = user.videoChannels[0].id | |
57 | } | |
58 | ||
59 | await waitJobs(servers) | |
60 | }) | |
61 | ||
62 | it('Should have one video channel (created with root)', async () => { | |
63 | const res = await getVideoChannelsList(servers[0].url, 0, 2) | |
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 | ||
70 | it('Should create another video channel', async function () { | |
71 | this.timeout(10000) | |
72 | ||
73 | { | |
74 | const videoChannel = { | |
75 | name: 'second_video_channel', | |
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 | |
82 | } | |
83 | ||
84 | // The channel is 1 is propagated to servers 2 | |
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 | } | |
89 | ||
90 | await waitJobs(servers) | |
91 | }) | |
92 | ||
93 | it('Should have two video channels when getting my information', async () => { | |
94 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | |
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 | |
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') | |
105 | expect(videoChannels[1].displayName).to.equal('second video channel') | |
106 | expect(videoChannels[1].description).to.equal('super video channel description') | |
107 | expect(videoChannels[1].support).to.equal('super video channel support text') | |
108 | }) | |
109 | ||
110 | it('Should have two video channels when getting account channels on server 1', async function () { | |
111 | const res = await getAccountVideoChannelsList(servers[0].url, userInfo.account.name + '@' + userInfo.account.host) | |
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 | |
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') | |
121 | expect(videoChannels[1].displayName).to.equal('second video channel') | |
122 | expect(videoChannels[1].description).to.equal('super video channel description') | |
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 () { | |
127 | const res = await getAccountVideoChannelsList(servers[1].url, userInfo.account.name + '@' + userInfo.account.host) | |
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) | |
131 | ||
132 | const videoChannels = res.body.data | |
133 | expect(videoChannels[0].name).to.equal('second_video_channel') | |
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') | |
137 | }) | |
138 | ||
139 | it('Should list video channels', async function () { | |
140 | const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name') | |
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) | |
145 | expect(res.body.data[0].name).to.equal('root_channel') | |
146 | expect(res.body.data[0].displayName).to.equal('Main root channel') | |
147 | }) | |
148 | ||
149 | it('Should update video channel', async function () { | |
150 | this.timeout(5000) | |
151 | ||
152 | const videoChannelAttributes = { | |
153 | displayName: 'video channel updated', | |
154 | description: 'video channel description updated', | |
155 | support: 'video channel support text updated' | |
156 | } | |
157 | ||
158 | await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes) | |
159 | ||
160 | await waitJobs(servers) | |
161 | }) | |
162 | ||
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') | |
166 | ||
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) | |
170 | expect(res.body.data[0].name).to.equal('second_video_channel') | |
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 | } | |
175 | }) | |
176 | ||
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, | |
185 | videoChannelName: 'second_video_channel', | |
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 | ||
202 | it('Should get video channel', async function () { | |
203 | const res = await getVideoChannel(servers[0].url, 'second_video_channel') | |
204 | ||
205 | const videoChannel = res.body | |
206 | expect(videoChannel.name).to.equal('second_video_channel') | |
207 | expect(videoChannel.displayName).to.equal('video channel updated') | |
208 | expect(videoChannel.description).to.equal('video channel description updated') | |
209 | expect(videoChannel.support).to.equal('video channel support text updated') | |
210 | }) | |
211 | ||
212 | it('Should list the second video channel videos', async function () { | |
213 | this.timeout(10000) | |
214 | ||
215 | for (const server of servers) { | |
216 | const channelURI = 'second_video_channel@localhost:' + server.port | |
217 | const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) | |
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 | ||
230 | await waitJobs(servers) | |
231 | }) | |
232 | ||
233 | it('Should list the first video channel videos', async function () { | |
234 | this.timeout(10000) | |
235 | ||
236 | for (const server of servers) { | |
237 | const secondChannelURI = 'second_video_channel@localhost:' + server.port | |
238 | const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5) | |
239 | expect(res1.body.total).to.equal(0) | |
240 | ||
241 | const channelURI = 'root_channel@localhost:' + server.port | |
242 | const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) | |
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') | |
249 | } | |
250 | }) | |
251 | ||
252 | it('Should delete video channel', async function () { | |
253 | await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel') | |
254 | }) | |
255 | ||
256 | it('Should have video channel deleted', async function () { | |
257 | const res = await getVideoChannelsList(servers[0].url, 0, 10) | |
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) | |
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 | { | |
272 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'toto', password: 'password' }) | |
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 | } | |
279 | }) | |
280 | ||
281 | after(async function () { | |
282 | await cleanupTests(servers) | |
283 | }) | |
284 | }) |