1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
5 ChangeOwnershipCommand,
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
14 } from '@shared/server-commands'
15 import { HttpStatusCode, VideoPrivacy } from '@shared/models'
17 describe('Test video change ownership - nominal', function () {
18 let servers: PeerTubeServer[] = []
20 const firstUser = 'first'
21 const secondUser = 'second'
23 let firstUserToken = ''
24 let firstUserChannelId: number
26 let secondUserToken = ''
27 let secondUserChannelId: number
29 let lastRequestId: number
33 let command: ChangeOwnershipCommand
35 before(async function () {
38 servers = await createMultipleServers(2)
39 await setAccessTokensToServers(servers)
40 await setDefaultVideoChannel(servers)
42 await servers[0].config.updateCustomSubConfig({
53 firstUserToken = await servers[0].users.generateUserAndToken(firstUser)
54 secondUserToken = await servers[0].users.generateUserAndToken(secondUser)
57 const { videoChannels } = await servers[0].users.getMyInfo({ token: firstUserToken })
58 firstUserChannelId = videoChannels[0].id
62 const { videoChannels } = await servers[0].users.getMyInfo({ token: secondUserToken })
63 secondUserChannelId = videoChannels[0].id
68 name: 'my super name',
69 description: 'my super description'
71 const { id } = await servers[0].videos.upload({ token: firstUserToken, attributes })
73 servers[0].store.videoCreated = await servers[0].videos.get({ id })
77 const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC }
78 const video = await servers[0].live.create({ token: firstUserToken, fields: attributes })
83 command = servers[0].changeOwnership
85 await doubleFollow(servers[0], servers[1])
88 it('Should not have video change ownership', async function () {
90 const body = await command.list({ token: firstUserToken })
92 expect(body.total).to.equal(0)
93 expect(body.data).to.be.an('array')
94 expect(body.data.length).to.equal(0)
98 const body = await command.list({ token: secondUserToken })
100 expect(body.total).to.equal(0)
101 expect(body.data).to.be.an('array')
102 expect(body.data.length).to.equal(0)
106 it('Should send a request to change ownership of a video', async function () {
109 await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser })
112 it('Should only return a request to change ownership for the second user', async function () {
114 const body = await command.list({ token: firstUserToken })
116 expect(body.total).to.equal(0)
117 expect(body.data).to.be.an('array')
118 expect(body.data.length).to.equal(0)
122 const body = await command.list({ token: secondUserToken })
124 expect(body.total).to.equal(1)
125 expect(body.data).to.be.an('array')
126 expect(body.data.length).to.equal(1)
128 lastRequestId = body.data[0].id
132 it('Should accept the same change ownership request without crashing', async function () {
133 await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser })
136 it('Should not create multiple change ownership requests while one is waiting', async function () {
137 const body = await command.list({ token: secondUserToken })
139 expect(body.total).to.equal(1)
140 expect(body.data).to.be.an('array')
141 expect(body.data.length).to.equal(1)
144 it('Should not be possible to refuse the change of ownership from first user', async function () {
145 await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
148 it('Should be possible to refuse the change of ownership from second user', async function () {
149 await command.refuse({ token: secondUserToken, ownershipId: lastRequestId })
152 it('Should send a new request to change ownership of a video', async function () {
155 await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser })
158 it('Should return two requests to change ownership for the second user', async function () {
160 const body = await command.list({ token: firstUserToken })
162 expect(body.total).to.equal(0)
163 expect(body.data).to.be.an('array')
164 expect(body.data.length).to.equal(0)
168 const body = await command.list({ token: secondUserToken })
170 expect(body.total).to.equal(2)
171 expect(body.data).to.be.an('array')
172 expect(body.data.length).to.equal(2)
174 lastRequestId = body.data[0].id
178 it('Should not be possible to accept the change of ownership from first user', async function () {
179 await command.accept({
180 token: firstUserToken,
181 ownershipId: lastRequestId,
182 channelId: secondUserChannelId,
183 expectedStatus: HttpStatusCode.FORBIDDEN_403
187 it('Should be possible to accept the change of ownership from second user', async function () {
188 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
190 await waitJobs(servers)
193 it('Should have the channel of the video updated', async function () {
194 for (const server of servers) {
195 const video = await server.videos.get({ id: servers[0].store.videoCreated.uuid })
197 expect(video.name).to.equal('my super name')
198 expect(video.channel.displayName).to.equal('Main second channel')
199 expect(video.channel.name).to.equal('second_channel')
203 it('Should send a request to change ownership of a live', async function () {
206 await command.create({ token: firstUserToken, videoId: liveId, username: secondUser })
208 const body = await command.list({ token: secondUserToken })
210 expect(body.total).to.equal(3)
211 expect(body.data.length).to.equal(3)
213 lastRequestId = body.data[0].id
216 it('Should accept a live ownership change', async function () {
219 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
221 await waitJobs(servers)
223 for (const server of servers) {
224 const video = await server.videos.get({ id: servers[0].store.videoCreated.uuid })
226 expect(video.name).to.equal('my super name')
227 expect(video.channel.displayName).to.equal('Main second channel')
228 expect(video.channel.name).to.equal('second_channel')
232 after(async function () {
233 await cleanupTests(servers)
237 describe('Test video change ownership - quota too small', function () {
238 let server: PeerTubeServer
239 const firstUser = 'first'
240 const secondUser = 'second'
242 let firstUserToken = ''
243 let secondUserToken = ''
244 let lastRequestId: number
246 before(async function () {
250 server = await createSingleServer(1)
251 await setAccessTokensToServers([ server ])
253 await server.users.create({ username: secondUser, videoQuota: 10 })
255 firstUserToken = await server.users.generateUserAndToken(firstUser)
256 secondUserToken = await server.login.getAccessToken(secondUser)
258 // Upload some videos on the server
260 name: 'my super name',
261 description: 'my super description'
263 await server.videos.upload({ token: firstUserToken, attributes })
265 await waitJobs(server)
267 const { data } = await server.videos.list()
268 expect(data.length).to.equal(1)
270 server.store.videoCreated = data.find(video => video.name === 'my super name')
273 it('Should send a request to change ownership of a video', async function () {
276 await server.changeOwnership.create({ token: firstUserToken, videoId: server.store.videoCreated.id, username: secondUser })
279 it('Should only return a request to change ownership for the second user', async function () {
281 const body = await server.changeOwnership.list({ token: firstUserToken })
283 expect(body.total).to.equal(0)
284 expect(body.data).to.be.an('array')
285 expect(body.data.length).to.equal(0)
289 const body = await server.changeOwnership.list({ token: secondUserToken })
291 expect(body.total).to.equal(1)
292 expect(body.data).to.be.an('array')
293 expect(body.data.length).to.equal(1)
295 lastRequestId = body.data[0].id
299 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
300 const { videoChannels } = await server.users.getMyInfo({ token: secondUserToken })
301 const channelId = videoChannels[0].id
303 await server.changeOwnership.accept({
304 token: secondUserToken,
305 ownershipId: lastRequestId,
307 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
311 after(async function () {
312 await cleanupTests([ server ])