aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/tests/api/videos/video-change-ownership.ts185
-rw-r--r--shared/extra-utils/server/servers.ts4
-rw-r--r--shared/extra-utils/videos/change-ownership-command.ts69
-rw-r--r--shared/extra-utils/videos/index.ts2
-rw-r--r--shared/extra-utils/videos/video-change-ownership.ts72
5 files changed, 173 insertions, 159 deletions
diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts
index 3c33cf015..1b81fe047 100644
--- a/server/tests/api/videos/video-change-ownership.ts
+++ b/server/tests/api/videos/video-change-ownership.ts
@@ -4,8 +4,7 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6import { 6import {
7 acceptChangeOwnership, 7 ChangeOwnershipCommand,
8 changeVideoOwnership,
9 cleanupTests, 8 cleanupTests,
10 createUser, 9 createUser,
11 doubleFollow, 10 doubleFollow,
@@ -13,9 +12,7 @@ import {
13 flushAndRunServer, 12 flushAndRunServer,
14 getMyUserInformation, 13 getMyUserInformation,
15 getVideo, 14 getVideo,
16 getVideoChangeOwnershipList,
17 getVideosList, 15 getVideosList,
18 refuseChangeOwnership,
19 ServerInfo, 16 ServerInfo,
20 setAccessTokensToServers, 17 setAccessTokensToServers,
21 setDefaultVideoChannel, 18 setDefaultVideoChannel,
@@ -39,16 +36,18 @@ describe('Test video change ownership - nominal', function () {
39 password: 'My other password' 36 password: 'My other password'
40 } 37 }
41 38
42 let firstUserAccessToken = '' 39 let firstUserToken = ''
43 let firstUserChannelId: number 40 let firstUserChannelId: number
44 41
45 let secondUserAccessToken = '' 42 let secondUserToken = ''
46 let secondUserChannelId: number 43 let secondUserChannelId: number
47 44
48 let lastRequestChangeOwnershipId = '' 45 let lastRequestId: number
49 46
50 let liveId: number 47 let liveId: number
51 48
49 let command: ChangeOwnershipCommand
50
52 before(async function () { 51 before(async function () {
53 this.timeout(50000) 52 this.timeout(50000)
54 53
@@ -83,17 +82,17 @@ describe('Test video change ownership - nominal', function () {
83 videoQuota: videoQuota 82 videoQuota: videoQuota
84 }) 83 })
85 84
86 firstUserAccessToken = await userLogin(servers[0], firstUser) 85 firstUserToken = await userLogin(servers[0], firstUser)
87 secondUserAccessToken = await userLogin(servers[0], secondUser) 86 secondUserToken = await userLogin(servers[0], secondUser)
88 87
89 { 88 {
90 const res = await getMyUserInformation(servers[0].url, firstUserAccessToken) 89 const res = await getMyUserInformation(servers[0].url, firstUserToken)
91 const firstUserInformation: User = res.body 90 const firstUserInformation: User = res.body
92 firstUserChannelId = firstUserInformation.videoChannels[0].id 91 firstUserChannelId = firstUserInformation.videoChannels[0].id
93 } 92 }
94 93
95 { 94 {
96 const res = await getMyUserInformation(servers[0].url, secondUserAccessToken) 95 const res = await getMyUserInformation(servers[0].url, secondUserToken)
97 const secondUserInformation: User = res.body 96 const secondUserInformation: User = res.body
98 secondUserChannelId = secondUserInformation.videoChannels[0].id 97 secondUserChannelId = secondUserInformation.videoChannels[0].id
99 } 98 }
@@ -103,7 +102,7 @@ describe('Test video change ownership - nominal', function () {
103 name: 'my super name', 102 name: 'my super name',
104 description: 'my super description' 103 description: 'my super description'
105 } 104 }
106 const res = await uploadVideo(servers[0].url, firstUserAccessToken, videoAttributes) 105 const res = await uploadVideo(servers[0].url, firstUserToken, videoAttributes)
107 106
108 const resVideo = await getVideo(servers[0].url, res.body.video.id) 107 const resVideo = await getVideo(servers[0].url, res.body.video.id)
109 servers[0].video = resVideo.body 108 servers[0].video = resVideo.body
@@ -111,116 +110,129 @@ describe('Test video change ownership - nominal', function () {
111 110
112 { 111 {
113 const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } 112 const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC }
114 const video = await servers[0].liveCommand.create({ token: firstUserAccessToken, fields: attributes }) 113 const video = await servers[0].liveCommand.create({ token: firstUserToken, fields: attributes })
115 114
116 liveId = video.id 115 liveId = video.id
117 } 116 }
118 117
118 command = servers[0].changeOwnershipCommand
119
119 await doubleFollow(servers[0], servers[1]) 120 await doubleFollow(servers[0], servers[1])
120 }) 121 })
121 122
122 it('Should not have video change ownership', async function () { 123 it('Should not have video change ownership', async function () {
123 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) 124 {
125 const body = await command.list({ token: firstUserToken })
124 126
125 expect(resFirstUser.body.total).to.equal(0) 127 expect(body.total).to.equal(0)
126 expect(resFirstUser.body.data).to.be.an('array') 128 expect(body.data).to.be.an('array')
127 expect(resFirstUser.body.data.length).to.equal(0) 129 expect(body.data.length).to.equal(0)
130 }
128 131
129 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 132 {
133 const body = await command.list({ token: secondUserToken })
130 134
131 expect(resSecondUser.body.total).to.equal(0) 135 expect(body.total).to.equal(0)
132 expect(resSecondUser.body.data).to.be.an('array') 136 expect(body.data).to.be.an('array')
133 expect(resSecondUser.body.data.length).to.equal(0) 137 expect(body.data.length).to.equal(0)
138 }
134 }) 139 })
135 140
136 it('Should send a request to change ownership of a video', async function () { 141 it('Should send a request to change ownership of a video', async function () {
137 this.timeout(15000) 142 this.timeout(15000)
138 143
139 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) 144 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
140 }) 145 })
141 146
142 it('Should only return a request to change ownership for the second user', async function () { 147 it('Should only return a request to change ownership for the second user', async function () {
143 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) 148 {
149 const body = await command.list({ token: firstUserToken })
144 150
145 expect(resFirstUser.body.total).to.equal(0) 151 expect(body.total).to.equal(0)
146 expect(resFirstUser.body.data).to.be.an('array') 152 expect(body.data).to.be.an('array')
147 expect(resFirstUser.body.data.length).to.equal(0) 153 expect(body.data.length).to.equal(0)
154 }
148 155
149 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 156 {
157 const body = await command.list({ token: secondUserToken })
150 158
151 expect(resSecondUser.body.total).to.equal(1) 159 expect(body.total).to.equal(1)
152 expect(resSecondUser.body.data).to.be.an('array') 160 expect(body.data).to.be.an('array')
153 expect(resSecondUser.body.data.length).to.equal(1) 161 expect(body.data.length).to.equal(1)
154 162
155 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id 163 lastRequestId = body.data[0].id
164 }
156 }) 165 })
157 166
158 it('Should accept the same change ownership request without crashing', async function () { 167 it('Should accept the same change ownership request without crashing', async function () {
159 this.timeout(10000) 168 this.timeout(10000)
160 169
161 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) 170 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
162 }) 171 })
163 172
164 it('Should not create multiple change ownership requests while one is waiting', async function () { 173 it('Should not create multiple change ownership requests while one is waiting', async function () {
165 this.timeout(10000) 174 this.timeout(10000)
166 175
167 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 176 const body = await command.list({ token: secondUserToken })
168 177
169 expect(resSecondUser.body.total).to.equal(1) 178 expect(body.total).to.equal(1)
170 expect(resSecondUser.body.data).to.be.an('array') 179 expect(body.data).to.be.an('array')
171 expect(resSecondUser.body.data.length).to.equal(1) 180 expect(body.data.length).to.equal(1)
172 }) 181 })
173 182
174 it('Should not be possible to refuse the change of ownership from first user', async function () { 183 it('Should not be possible to refuse the change of ownership from first user', async function () {
175 this.timeout(10000) 184 this.timeout(10000)
176 185
177 await refuseChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, HttpStatusCode.FORBIDDEN_403) 186 await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
178 }) 187 })
179 188
180 it('Should be possible to refuse the change of ownership from second user', async function () { 189 it('Should be possible to refuse the change of ownership from second user', async function () {
181 this.timeout(10000) 190 this.timeout(10000)
182 191
183 await refuseChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId) 192 await command.refuse({ token: secondUserToken, ownershipId: lastRequestId })
184 }) 193 })
185 194
186 it('Should send a new request to change ownership of a video', async function () { 195 it('Should send a new request to change ownership of a video', async function () {
187 this.timeout(15000) 196 this.timeout(15000)
188 197
189 await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) 198 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
190 }) 199 })
191 200
192 it('Should return two requests to change ownership for the second user', async function () { 201 it('Should return two requests to change ownership for the second user', async function () {
193 const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) 202 {
203 const body = await command.list({ token: firstUserToken })
194 204
195 expect(resFirstUser.body.total).to.equal(0) 205 expect(body.total).to.equal(0)
196 expect(resFirstUser.body.data).to.be.an('array') 206 expect(body.data).to.be.an('array')
197 expect(resFirstUser.body.data.length).to.equal(0) 207 expect(body.data.length).to.equal(0)
208 }
198 209
199 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 210 {
211 const body = await command.list({ token: secondUserToken })
200 212
201 expect(resSecondUser.body.total).to.equal(2) 213 expect(body.total).to.equal(2)
202 expect(resSecondUser.body.data).to.be.an('array') 214 expect(body.data).to.be.an('array')
203 expect(resSecondUser.body.data.length).to.equal(2) 215 expect(body.data.length).to.equal(2)
204 216
205 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id 217 lastRequestId = body.data[0].id
218 }
206 }) 219 })
207 220
208 it('Should not be possible to accept the change of ownership from first user', async function () { 221 it('Should not be possible to accept the change of ownership from first user', async function () {
209 this.timeout(10000) 222 this.timeout(10000)
210 223
211 await acceptChangeOwnership( 224 await command.accept({
212 servers[0].url, 225 token: firstUserToken,
213 firstUserAccessToken, 226 ownershipId: lastRequestId,
214 lastRequestChangeOwnershipId, 227 channelId: secondUserChannelId,
215 secondUserChannelId, 228 expectedStatus: HttpStatusCode.FORBIDDEN_403
216 HttpStatusCode.FORBIDDEN_403 229 })
217 )
218 }) 230 })
219 231
220 it('Should be possible to accept the change of ownership from second user', async function () { 232 it('Should be possible to accept the change of ownership from second user', async function () {
221 this.timeout(10000) 233 this.timeout(10000)
222 234
223 await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, secondUserChannelId) 235 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
224 236
225 await waitJobs(servers) 237 await waitJobs(servers)
226 }) 238 })
@@ -240,20 +252,20 @@ describe('Test video change ownership - nominal', function () {
240 it('Should send a request to change ownership of a live', async function () { 252 it('Should send a request to change ownership of a live', async function () {
241 this.timeout(15000) 253 this.timeout(15000)
242 254
243 await changeVideoOwnership(servers[0].url, firstUserAccessToken, liveId, secondUser.username) 255 await command.create({ token: firstUserToken, videoId: liveId, username: secondUser.username })
244 256
245 const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) 257 const body = await command.list({ token: secondUserToken })
246 258
247 expect(resSecondUser.body.total).to.equal(3) 259 expect(body.total).to.equal(3)
248 expect(resSecondUser.body.data.length).to.equal(3) 260 expect(body.data.length).to.equal(3)
249 261
250 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id 262 lastRequestId = body.data[0].id
251 }) 263 })
252 264
253 it('Should accept a live ownership change', async function () { 265 it('Should accept a live ownership change', async function () {
254 this.timeout(20000) 266 this.timeout(20000)
255 267
256 await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, secondUserChannelId) 268 await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId })
257 269
258 await waitJobs(servers) 270 await waitJobs(servers)
259 271
@@ -283,9 +295,9 @@ describe('Test video change ownership - quota too small', function () {
283 username: 'second', 295 username: 'second',
284 password: 'My other password' 296 password: 'My other password'
285 } 297 }
286 let firstUserAccessToken = '' 298 let firstUserToken = ''
287 let secondUserAccessToken = '' 299 let secondUserToken = ''
288 let lastRequestChangeOwnershipId = '' 300 let lastRequestId: number
289 301
290 before(async function () { 302 before(async function () {
291 this.timeout(50000) 303 this.timeout(50000)
@@ -311,15 +323,15 @@ describe('Test video change ownership - quota too small', function () {
311 videoQuota: limitedVideoQuota 323 videoQuota: limitedVideoQuota
312 }) 324 })
313 325
314 firstUserAccessToken = await userLogin(server, firstUser) 326 firstUserToken = await userLogin(server, firstUser)
315 secondUserAccessToken = await userLogin(server, secondUser) 327 secondUserToken = await userLogin(server, secondUser)
316 328
317 // Upload some videos on the server 329 // Upload some videos on the server
318 const video1Attributes = { 330 const video1Attributes = {
319 name: 'my super name', 331 name: 'my super name',
320 description: 'my super description' 332 description: 'my super description'
321 } 333 }
322 await uploadVideo(server.url, firstUserAccessToken, video1Attributes) 334 await uploadVideo(server.url, firstUserToken, video1Attributes)
323 335
324 await waitJobs(server) 336 await waitJobs(server)
325 337
@@ -334,39 +346,42 @@ describe('Test video change ownership - quota too small', function () {
334 it('Should send a request to change ownership of a video', async function () { 346 it('Should send a request to change ownership of a video', async function () {
335 this.timeout(15000) 347 this.timeout(15000)
336 348
337 await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username) 349 await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser.username })
338 }) 350 })
339 351
340 it('Should only return a request to change ownership for the second user', async function () { 352 it('Should only return a request to change ownership for the second user', async function () {
341 const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken) 353 {
354 const body = await server.changeOwnershipCommand.list({ token: firstUserToken })
342 355
343 expect(resFirstUser.body.total).to.equal(0) 356 expect(body.total).to.equal(0)
344 expect(resFirstUser.body.data).to.be.an('array') 357 expect(body.data).to.be.an('array')
345 expect(resFirstUser.body.data.length).to.equal(0) 358 expect(body.data.length).to.equal(0)
359 }
346 360
347 const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken) 361 {
362 const body = await server.changeOwnershipCommand.list({ token: secondUserToken })
348 363
349 expect(resSecondUser.body.total).to.equal(1) 364 expect(body.total).to.equal(1)
350 expect(resSecondUser.body.data).to.be.an('array') 365 expect(body.data).to.be.an('array')
351 expect(resSecondUser.body.data.length).to.equal(1) 366 expect(body.data.length).to.equal(1)
352 367
353 lastRequestChangeOwnershipId = resSecondUser.body.data[0].id 368 lastRequestId = body.data[0].id
369 }
354 }) 370 })
355 371
356 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { 372 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
357 this.timeout(10000) 373 this.timeout(10000)
358 374
359 const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken) 375 const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserToken)
360 const secondUserInformation: User = secondUserInformationResponse.body 376 const secondUserInformation: User = secondUserInformationResponse.body
361 const channelId = secondUserInformation.videoChannels[0].id 377 const channelId = secondUserInformation.videoChannels[0].id
362 378
363 await acceptChangeOwnership( 379 await server.changeOwnershipCommand.accept({
364 server.url, 380 token: secondUserToken,
365 secondUserAccessToken, 381 ownershipId: lastRequestId,
366 lastRequestChangeOwnershipId,
367 channelId, 382 channelId,
368 HttpStatusCode.PAYLOAD_TOO_LARGE_413 383 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
369 ) 384 })
370 }) 385 })
371 386
372 after(async function () { 387 after(async function () {
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index 170360341..33f558414 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -18,7 +18,7 @@ import { makeGetRequest } from '../requests/requests'
18import { SearchCommand } from '../search' 18import { SearchCommand } from '../search'
19import { SocketIOCommand } from '../socket' 19import { SocketIOCommand } from '../socket'
20import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' 20import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users'
21import { LiveCommand, ServicesCommand, BlacklistCommand, CaptionsCommand } from '../videos' 21import { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, LiveCommand, ServicesCommand } from '../videos'
22import { ConfigCommand } from './config-command' 22import { ConfigCommand } from './config-command'
23import { ContactFormCommand } from './contact-form-command' 23import { ContactFormCommand } from './contact-form-command'
24import { DebugCommand } from './debug-command' 24import { DebugCommand } from './debug-command'
@@ -104,6 +104,7 @@ interface ServerInfo {
104 servicesCommand?: ServicesCommand 104 servicesCommand?: ServicesCommand
105 blacklistCommand?: BlacklistCommand 105 blacklistCommand?: BlacklistCommand
106 captionsCommand?: CaptionsCommand 106 captionsCommand?: CaptionsCommand
107 changeOwnershipCommand?: ChangeOwnershipCommand
107} 108}
108 109
109function parallelTests () { 110function parallelTests () {
@@ -333,6 +334,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
333 server.servicesCommand = new ServicesCommand(server) 334 server.servicesCommand = new ServicesCommand(server)
334 server.blacklistCommand = new BlacklistCommand(server) 335 server.blacklistCommand = new BlacklistCommand(server)
335 server.captionsCommand = new CaptionsCommand(server) 336 server.captionsCommand = new CaptionsCommand(server)
337 server.changeOwnershipCommand = new ChangeOwnershipCommand(server)
336 338
337 res(server) 339 res(server)
338 }) 340 })
diff --git a/shared/extra-utils/videos/change-ownership-command.ts b/shared/extra-utils/videos/change-ownership-command.ts
new file mode 100644
index 000000000..03f77a95f
--- /dev/null
+++ b/shared/extra-utils/videos/change-ownership-command.ts
@@ -0,0 +1,69 @@
1
2import { ResultList, VideoChangeOwnership } from '@shared/models'
3import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
4import { AbstractCommand, OverrideCommandOptions } from '../shared'
5
6export class ChangeOwnershipCommand extends AbstractCommand {
7
8 create (options: OverrideCommandOptions & {
9 videoId: number | string
10 username: string
11 }) {
12 const { videoId, username } = options
13 const path = '/api/v1/videos/' + videoId + '/give-ownership'
14
15 return this.postBodyRequest({
16 ...options,
17
18 path,
19 fields: { username },
20 implicitToken: true,
21 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
22 })
23 }
24
25 list (options: OverrideCommandOptions = {}) {
26 const path = '/api/v1/videos/ownership'
27
28 return this.getRequestBody<ResultList<VideoChangeOwnership>>({
29 ...options,
30
31 path,
32 query: { sort: '-createdAt' },
33 implicitToken: true,
34 defaultExpectedStatus: HttpStatusCode.OK_200
35 })
36 }
37
38 accept (options: OverrideCommandOptions & {
39 ownershipId: number
40 channelId: number
41 }) {
42 const { ownershipId, channelId } = options
43 const path = '/api/v1/videos/ownership/' + ownershipId + '/accept'
44
45 return this.postBodyRequest({
46 ...options,
47
48 path,
49 fields: { channelId },
50 implicitToken: true,
51 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
52 })
53 }
54
55 refuse (options: OverrideCommandOptions & {
56 ownershipId: number
57 }) {
58 const { ownershipId } = options
59 const path = '/api/v1/videos/ownership/' + ownershipId + '/refuse'
60
61 return this.postBodyRequest({
62 ...options,
63
64 path,
65 implicitToken: true,
66 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
67 })
68 }
69}
diff --git a/shared/extra-utils/videos/index.ts b/shared/extra-utils/videos/index.ts
index 03b4756d5..815c7f944 100644
--- a/shared/extra-utils/videos/index.ts
+++ b/shared/extra-utils/videos/index.ts
@@ -1,10 +1,10 @@
1export * from './blacklist-command' 1export * from './blacklist-command'
2export * from './captions' 2export * from './captions'
3export * from './captions-command' 3export * from './captions-command'
4export * from './change-ownership-command'
4export * from './live-command' 5export * from './live-command'
5export * from './live' 6export * from './live'
6export * from './services-command' 7export * from './services-command'
7export * from './video-change-ownership'
8export * from './video-channels' 8export * from './video-channels'
9export * from './video-comments' 9export * from './video-comments'
10export * from './video-history' 10export * from './video-history'
diff --git a/shared/extra-utils/videos/video-change-ownership.ts b/shared/extra-utils/videos/video-change-ownership.ts
deleted file mode 100644
index ef82a7636..000000000
--- a/shared/extra-utils/videos/video-change-ownership.ts
+++ /dev/null
@@ -1,72 +0,0 @@
1import * as request from 'supertest'
2import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
3
4function changeVideoOwnership (
5 url: string,
6 token: string,
7 videoId: number | string,
8 username,
9 expectedStatus = HttpStatusCode.NO_CONTENT_204
10) {
11 const path = '/api/v1/videos/' + videoId + '/give-ownership'
12
13 return request(url)
14 .post(path)
15 .set('Accept', 'application/json')
16 .set('Authorization', 'Bearer ' + token)
17 .send({ username })
18 .expect(expectedStatus)
19}
20
21function getVideoChangeOwnershipList (url: string, token: string) {
22 const path = '/api/v1/videos/ownership'
23
24 return request(url)
25 .get(path)
26 .query({ sort: '-createdAt' })
27 .set('Accept', 'application/json')
28 .set('Authorization', 'Bearer ' + token)
29 .expect(HttpStatusCode.OK_200)
30 .expect('Content-Type', /json/)
31}
32
33function acceptChangeOwnership (
34 url: string,
35 token: string,
36 ownershipId: string,
37 channelId: number,
38 expectedStatus = HttpStatusCode.NO_CONTENT_204
39) {
40 const path = '/api/v1/videos/ownership/' + ownershipId + '/accept'
41
42 return request(url)
43 .post(path)
44 .set('Accept', 'application/json')
45 .set('Authorization', 'Bearer ' + token)
46 .send({ channelId })
47 .expect(expectedStatus)
48}
49
50function refuseChangeOwnership (
51 url: string,
52 token: string,
53 ownershipId: string,
54 expectedStatus = HttpStatusCode.NO_CONTENT_204
55) {
56 const path = '/api/v1/videos/ownership/' + ownershipId + '/refuse'
57
58 return request(url)
59 .post(path)
60 .set('Accept', 'application/json')
61 .set('Authorization', 'Bearer ' + token)
62 .expect(expectedStatus)
63}
64
65// ---------------------------------------------------------------------------
66
67export {
68 changeVideoOwnership,
69 getVideoChangeOwnershipList,
70 acceptChangeOwnership,
71 refuseChangeOwnership
72}