]>
Commit | Line | Data |
---|---|---|
74d63469 GR |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { | |
6 | acceptChangeOwnership, | |
7 | changeVideoOwnership, | |
5cf84858 | 8 | createUser, doubleFollow, flushAndRunMultipleServers, |
74d63469 GR |
9 | flushTests, |
10 | getMyUserInformation, | |
11 | getVideoChangeOwnershipList, | |
12 | getVideosList, | |
13 | killallServers, | |
14 | refuseChangeOwnership, | |
15 | runServer, | |
16 | ServerInfo, | |
17 | setAccessTokensToServers, | |
18 | uploadVideo, | |
5cf84858 C |
19 | userLogin, |
20 | getVideo | |
74d63469 GR |
21 | } from '../../utils' |
22 | import { waitJobs } from '../../utils/server/jobs' | |
23 | import { User } from '../../../../shared/models/users' | |
5cf84858 | 24 | import { VideoDetails } from '../../../../shared/models/videos' |
74d63469 GR |
25 | |
26 | const expect = chai.expect | |
27 | ||
28 | describe('Test video change ownership - nominal', function () { | |
5cf84858 | 29 | let servers: ServerInfo[] = [] |
74d63469 GR |
30 | const firstUser = { |
31 | username: 'first', | |
32 | password: 'My great password' | |
33 | } | |
34 | const secondUser = { | |
35 | username: 'second', | |
36 | password: 'My other password' | |
37 | } | |
38 | let firstUserAccessToken = '' | |
39 | let secondUserAccessToken = '' | |
40 | let lastRequestChangeOwnershipId = undefined | |
41 | ||
42 | before(async function () { | |
43 | this.timeout(50000) | |
44 | ||
5cf84858 C |
45 | servers = await flushAndRunMultipleServers(2) |
46 | await setAccessTokensToServers(servers) | |
74d63469 GR |
47 | |
48 | const videoQuota = 42000000 | |
5cf84858 C |
49 | await createUser(servers[0].url, servers[0].accessToken, firstUser.username, firstUser.password, videoQuota) |
50 | await createUser(servers[0].url, servers[0].accessToken, secondUser.username, secondUser.password, videoQuota) | |
74d63469 | 51 | |
5cf84858 C |
52 | firstUserAccessToken = await userLogin(servers[0], firstUser) |
53 | secondUserAccessToken = await userLogin(servers[0], secondUser) | |
74d63469 | 54 | |
5cf84858 | 55 | const videoAttributes = { |
74d63469 GR |
56 | name: 'my super name', |
57 | description: 'my super description' | |
58 | } | |
5cf84858 | 59 | await uploadVideo(servers[0].url, firstUserAccessToken, videoAttributes) |
74d63469 | 60 | |
5cf84858 | 61 | await waitJobs(servers) |
74d63469 | 62 | |
5cf84858 | 63 | const res = await getVideosList(servers[0].url) |
74d63469 GR |
64 | const videos = res.body.data |
65 | ||
66 | expect(videos.length).to.equal(1) | |
67 | ||
5cf84858 C |
68 | const video = videos.find(video => video.name === 'my super name') |
69 | expect(video.channel.name).to.equal('first_channel') | |
70 | servers[0].video = video | |
71 | ||
72 | await doubleFollow(servers[0], servers[1]) | |
74d63469 GR |
73 | }) |
74 | ||
75 | it('Should not have video change ownership', async function () { | |
5cf84858 | 76 | const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) |
74d63469 GR |
77 | |
78 | expect(resFirstUser.body.total).to.equal(0) | |
79 | expect(resFirstUser.body.data).to.be.an('array') | |
80 | expect(resFirstUser.body.data.length).to.equal(0) | |
81 | ||
5cf84858 | 82 | const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) |
74d63469 GR |
83 | |
84 | expect(resSecondUser.body.total).to.equal(0) | |
85 | expect(resSecondUser.body.data).to.be.an('array') | |
86 | expect(resSecondUser.body.data.length).to.equal(0) | |
87 | }) | |
88 | ||
89 | it('Should send a request to change ownership of a video', async function () { | |
90 | this.timeout(15000) | |
91 | ||
5cf84858 | 92 | await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) |
74d63469 GR |
93 | }) |
94 | ||
95 | it('Should only return a request to change ownership for the second user', async function () { | |
5cf84858 | 96 | const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) |
74d63469 GR |
97 | |
98 | expect(resFirstUser.body.total).to.equal(0) | |
99 | expect(resFirstUser.body.data).to.be.an('array') | |
100 | expect(resFirstUser.body.data.length).to.equal(0) | |
101 | ||
5cf84858 | 102 | const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) |
74d63469 GR |
103 | |
104 | expect(resSecondUser.body.total).to.equal(1) | |
105 | expect(resSecondUser.body.data).to.be.an('array') | |
106 | expect(resSecondUser.body.data.length).to.equal(1) | |
107 | ||
108 | lastRequestChangeOwnershipId = resSecondUser.body.data[0].id | |
109 | }) | |
110 | ||
111 | it('Should accept the same change ownership request without crashing', async function () { | |
112 | this.timeout(10000) | |
113 | ||
5cf84858 | 114 | await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) |
74d63469 GR |
115 | }) |
116 | ||
117 | it('Should not create multiple change ownership requests while one is waiting', async function () { | |
118 | this.timeout(10000) | |
119 | ||
5cf84858 | 120 | const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) |
74d63469 GR |
121 | |
122 | expect(resSecondUser.body.total).to.equal(1) | |
123 | expect(resSecondUser.body.data).to.be.an('array') | |
124 | expect(resSecondUser.body.data.length).to.equal(1) | |
125 | }) | |
126 | ||
127 | it('Should not be possible to refuse the change of ownership from first user', async function () { | |
128 | this.timeout(10000) | |
129 | ||
5cf84858 | 130 | await refuseChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, 403) |
74d63469 GR |
131 | }) |
132 | ||
133 | it('Should be possible to refuse the change of ownership from second user', async function () { | |
134 | this.timeout(10000) | |
135 | ||
5cf84858 | 136 | await refuseChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId) |
74d63469 GR |
137 | }) |
138 | ||
139 | it('Should send a new request to change ownership of a video', async function () { | |
140 | this.timeout(15000) | |
141 | ||
5cf84858 | 142 | await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) |
74d63469 GR |
143 | }) |
144 | ||
145 | it('Should return two requests to change ownership for the second user', async function () { | |
5cf84858 | 146 | const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) |
74d63469 GR |
147 | |
148 | expect(resFirstUser.body.total).to.equal(0) | |
149 | expect(resFirstUser.body.data).to.be.an('array') | |
150 | expect(resFirstUser.body.data.length).to.equal(0) | |
151 | ||
5cf84858 | 152 | const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) |
74d63469 GR |
153 | |
154 | expect(resSecondUser.body.total).to.equal(2) | |
155 | expect(resSecondUser.body.data).to.be.an('array') | |
156 | expect(resSecondUser.body.data.length).to.equal(2) | |
157 | ||
158 | lastRequestChangeOwnershipId = resSecondUser.body.data[0].id | |
159 | }) | |
160 | ||
161 | it('Should not be possible to accept the change of ownership from first user', async function () { | |
162 | this.timeout(10000) | |
163 | ||
5cf84858 | 164 | const secondUserInformationResponse = await getMyUserInformation(servers[0].url, secondUserAccessToken) |
74d63469 GR |
165 | const secondUserInformation: User = secondUserInformationResponse.body |
166 | const channelId = secondUserInformation.videoChannels[0].id | |
5cf84858 | 167 | await acceptChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, channelId, 403) |
74d63469 GR |
168 | }) |
169 | ||
170 | it('Should be possible to accept the change of ownership from second user', async function () { | |
171 | this.timeout(10000) | |
172 | ||
5cf84858 | 173 | const secondUserInformationResponse = await getMyUserInformation(servers[0].url, secondUserAccessToken) |
74d63469 GR |
174 | const secondUserInformation: User = secondUserInformationResponse.body |
175 | const channelId = secondUserInformation.videoChannels[0].id | |
5cf84858 C |
176 | await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, channelId) |
177 | ||
178 | await waitJobs(servers) | |
179 | }) | |
180 | ||
181 | it('Should have video channel updated', async function () { | |
182 | for (const server of servers) { | |
183 | const res = await getVideo(server.url, servers[0].video.uuid) | |
184 | ||
185 | const video: VideoDetails = res.body | |
186 | ||
187 | expect(video.name).to.equal('my super name') | |
188 | expect(video.channel.displayName).to.equal('Main second channel') | |
189 | expect(video.channel.name).to.equal('second_channel') | |
190 | } | |
74d63469 GR |
191 | }) |
192 | ||
193 | after(async function () { | |
5cf84858 | 194 | killallServers(servers) |
74d63469 GR |
195 | }) |
196 | }) | |
197 | ||
198 | describe('Test video change ownership - quota too small', function () { | |
199 | let server: ServerInfo = undefined | |
200 | const firstUser = { | |
201 | username: 'first', | |
202 | password: 'My great password' | |
203 | } | |
204 | const secondUser = { | |
205 | username: 'second', | |
206 | password: 'My other password' | |
207 | } | |
208 | let firstUserAccessToken = '' | |
209 | let secondUserAccessToken = '' | |
210 | let lastRequestChangeOwnershipId = undefined | |
211 | ||
212 | before(async function () { | |
213 | this.timeout(50000) | |
214 | ||
215 | // Run one server | |
216 | await flushTests() | |
217 | server = await runServer(1) | |
218 | await setAccessTokensToServers([server]) | |
219 | ||
220 | const videoQuota = 42000000 | |
221 | const limitedVideoQuota = 10 | |
222 | await createUser(server.url, server.accessToken, firstUser.username, firstUser.password, videoQuota) | |
223 | await createUser(server.url, server.accessToken, secondUser.username, secondUser.password, limitedVideoQuota) | |
224 | ||
225 | firstUserAccessToken = await userLogin(server, firstUser) | |
226 | secondUserAccessToken = await userLogin(server, secondUser) | |
227 | ||
228 | // Upload some videos on the server | |
229 | const video1Attributes = { | |
230 | name: 'my super name', | |
231 | description: 'my super description' | |
232 | } | |
233 | await uploadVideo(server.url, firstUserAccessToken, video1Attributes) | |
234 | ||
235 | await waitJobs(server) | |
236 | ||
237 | const res = await getVideosList(server.url) | |
238 | const videos = res.body.data | |
239 | ||
240 | expect(videos.length).to.equal(1) | |
241 | ||
242 | server.video = videos.find(video => video.name === 'my super name') | |
243 | }) | |
244 | ||
245 | it('Should send a request to change ownership of a video', async function () { | |
246 | this.timeout(15000) | |
247 | ||
248 | await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username) | |
249 | }) | |
250 | ||
251 | it('Should only return a request to change ownership for the second user', async function () { | |
252 | const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken) | |
253 | ||
254 | expect(resFirstUser.body.total).to.equal(0) | |
255 | expect(resFirstUser.body.data).to.be.an('array') | |
256 | expect(resFirstUser.body.data.length).to.equal(0) | |
257 | ||
258 | const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken) | |
259 | ||
260 | expect(resSecondUser.body.total).to.equal(1) | |
261 | expect(resSecondUser.body.data).to.be.an('array') | |
262 | expect(resSecondUser.body.data.length).to.equal(1) | |
263 | ||
264 | lastRequestChangeOwnershipId = resSecondUser.body.data[0].id | |
265 | }) | |
266 | ||
267 | it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { | |
268 | this.timeout(10000) | |
269 | ||
270 | const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken) | |
271 | const secondUserInformation: User = secondUserInformationResponse.body | |
272 | const channelId = secondUserInformation.videoChannels[0].id | |
273 | await acceptChangeOwnership(server.url, secondUserAccessToken, lastRequestChangeOwnershipId, channelId, 403) | |
274 | }) | |
275 | ||
276 | after(async function () { | |
277 | killallServers([server]) | |
278 | }) | |
279 | }) |