1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
7 ChangeOwnershipCommand,
10 flushAndRunMultipleServers,
13 setAccessTokensToServers,
14 setDefaultVideoChannel,
16 } from '@shared/extra-utils'
17 import { VideoPrivacy } from '@shared/models'
19 const expect = chai.expect
21 describe('Test video change ownership - nominal', function () {
22 let servers: ServerInfo[] = []
24 const firstUser = 'first'
25 const secondUser = 'second'
27 let firstUserToken = ''
28 let firstUserChannelId: number
30 let secondUserToken = ''
31 let secondUserChannelId: number
33 let lastRequestId: number
37 let command: ChangeOwnershipCommand
39 before(async function () {
42 servers = await flushAndRunMultipleServers(2)
43 await setAccessTokensToServers(servers)
44 await setDefaultVideoChannel(servers)
46 await servers[0].configCommand.updateCustomSubConfig({
57 firstUserToken = await servers[0].usersCommand.generateUserAndToken(firstUser)
58 secondUserToken = await servers[0].usersCommand.generateUserAndToken(secondUser)
61 const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: firstUserToken })
62 firstUserChannelId = videoChannels[0].id
66 const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: secondUserToken })
67 secondUserChannelId = videoChannels[0].id
72 name: 'my super name',
73 description: 'my super description'
75 const { id } = await servers[0].videosCommand.upload({ token: firstUserToken, attributes })
77 servers[0].video = await servers[0].videosCommand.get({ id })
81 const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC }
82 const video = await servers[0].liveCommand.create({ token: firstUserToken, fields: attributes })
87 command = servers[0].changeOwnershipCommand
89 await doubleFollow(servers[0], servers[1])
92 it('Should not have video change ownership', async function () {
94 const body = await command.list({ token: firstUserToken })
96 expect(body.total).to.equal(0)
97 expect(body.data).to.be.an('array')
98 expect(body.data.length).to.equal(0)
102 const body = await command.list({ token: secondUserToken })
104 expect(body.total).to.equal(0)
105 expect(body.data).to.be.an('array')
106 expect(body.data.length).to.equal(0)
110 it('Should send a request to change ownership of a video', async function () {
113 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
116 it('Should only return a request to change ownership for the second user', async function () {
118 const body = await command.list({ token: firstUserToken })
120 expect(body.total).to.equal(0)
121 expect(body.data).to.be.an('array')
122 expect(body.data.length).to.equal(0)
126 const body = await command.list({ token: secondUserToken })
128 expect(body.total).to.equal(1)
129 expect(body.data).to.be.an('array')
130 expect(body.data.length).to.equal(1)
132 lastRequestId = body.data[0].id
136 it('Should accept the same change ownership request without crashing', async function () {
139 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
142 it('Should not create multiple change ownership requests while one is waiting', async function () {
145 const body = await command.list({ token: secondUserToken })
147 expect(body.total).to.equal(1)
148 expect(body.data).to.be.an('array')
149 expect(body.data.length).to.equal(1)
152 it('Should not be possible to refuse the change of ownership from first user', async function () {
155 await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
158 it('Should be possible to refuse the change of ownership from second user', async function () {
161 await command.refuse({ token: secondUserToken, ownershipId: lastRequestId })
164 it('Should send a new request to change ownership of a video', async function () {
167 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
170 it('Should return two requests to change ownership for the second user', async function () {
172 const body = await command.list({ token: firstUserToken })
174 expect(body.total).to.equal(0)
175 expect(body.data).to.be.an('array')
176 expect(body.data.length).to.equal(0)
180 const body = await command.list({ token: secondUserToken })
182 expect(body.total).to.equal(2)
183 expect(body.data).to.be.an('array')
184 expect(body.data.length).to.equal(2)
186 lastRequestId = body.data[0].id
190 it('Should not be possible to accept the change of ownership from first user', async function () {
193 await command.accept({
194 token: firstUserToken,
195 ownershipId: lastRequestId,
196 channelId: secondUserChannelId,
197 expectedStatus: HttpStatusCode.FORBIDDEN_403
201 it('Should be possible to accept the change of ownership from second user', async function () {
204 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
206 await waitJobs(servers)
209 it('Should have the channel of the video updated', async function () {
210 for (const server of servers) {
211 const video = await server.videosCommand.get({ id: servers[0].video.uuid })
213 expect(video.name).to.equal('my super name')
214 expect(video.channel.displayName).to.equal('Main second channel')
215 expect(video.channel.name).to.equal('second_channel')
219 it('Should send a request to change ownership of a live', async function () {
222 await command.create({ token: firstUserToken, videoId: liveId, username: secondUser })
224 const body = await command.list({ token: secondUserToken })
226 expect(body.total).to.equal(3)
227 expect(body.data.length).to.equal(3)
229 lastRequestId = body.data[0].id
232 it('Should accept a live ownership change', async function () {
235 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
237 await waitJobs(servers)
239 for (const server of servers) {
240 const video = await server.videosCommand.get({ id: servers[0].video.uuid })
242 expect(video.name).to.equal('my super name')
243 expect(video.channel.displayName).to.equal('Main second channel')
244 expect(video.channel.name).to.equal('second_channel')
248 after(async function () {
249 await cleanupTests(servers)
253 describe('Test video change ownership - quota too small', function () {
254 let server: ServerInfo
255 const firstUser = 'first'
256 const secondUser = 'second'
258 let firstUserToken = ''
259 let secondUserToken = ''
260 let lastRequestId: number
262 before(async function () {
266 server = await flushAndRunServer(1)
267 await setAccessTokensToServers([ server ])
269 await server.usersCommand.create({ username: secondUser, videoQuota: 10 })
271 firstUserToken = await server.usersCommand.generateUserAndToken(firstUser)
272 secondUserToken = await server.loginCommand.getAccessToken(secondUser)
274 // Upload some videos on the server
276 name: 'my super name',
277 description: 'my super description'
279 await server.videosCommand.upload({ token: firstUserToken, attributes })
281 await waitJobs(server)
283 const { data } = await server.videosCommand.list()
284 expect(data.length).to.equal(1)
286 server.video = data.find(video => video.name === 'my super name')
289 it('Should send a request to change ownership of a video', async function () {
292 await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser })
295 it('Should only return a request to change ownership for the second user', async function () {
297 const body = await server.changeOwnershipCommand.list({ token: firstUserToken })
299 expect(body.total).to.equal(0)
300 expect(body.data).to.be.an('array')
301 expect(body.data.length).to.equal(0)
305 const body = await server.changeOwnershipCommand.list({ token: secondUserToken })
307 expect(body.total).to.equal(1)
308 expect(body.data).to.be.an('array')
309 expect(body.data.length).to.equal(1)
311 lastRequestId = body.data[0].id
315 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
318 const { videoChannels } = await server.usersCommand.getMyInfo({ token: secondUserToken })
319 const channelId = videoChannels[0].id
321 await server.changeOwnershipCommand.accept({
322 token: secondUserToken,
323 ownershipId: lastRequestId,
325 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
329 after(async function () {
330 await cleanupTests([ server ])