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