]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/utils/videos/video-channels.ts
Add video channel management
[github/Chocobozzz/PeerTube.git] / server / tests / utils / videos / video-channels.ts
1 import * as request from 'supertest'
2 import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared/models/videos'
3
4 function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {
5 const path = '/api/v1/video-channels'
6
7 const req = request(url)
8 .get(path)
9 .query({ start: start })
10 .query({ count: count })
11
12 if (sort) req.query({ sort })
13
14 return req.set('Accept', 'application/json')
15 .expect(200)
16 .expect('Content-Type', /json/)
17 }
18
19 function getAccountVideoChannelsList (url: string, accountId: number | string, specialStatus = 200) {
20 const path = '/api/v1/accounts/' + accountId + '/video-channels'
21
22 return request(url)
23 .get(path)
24 .set('Accept', 'application/json')
25 .expect(specialStatus)
26 .expect('Content-Type', /json/)
27 }
28
29 function addVideoChannel (
30 url: string,
31 token: string,
32 videoChannelAttributesArg: VideoChannelCreate,
33 expectedStatus = 200
34 ) {
35 const path = '/api/v1/video-channels/'
36
37 // Default attributes
38 let attributes = {
39 displayName: 'my super video channel',
40 description: 'my super channel description',
41 support: 'my super channel support'
42 }
43 attributes = Object.assign(attributes, videoChannelAttributesArg)
44
45 return request(url)
46 .post(path)
47 .send(attributes)
48 .set('Accept', 'application/json')
49 .set('Authorization', 'Bearer ' + token)
50 .expect(expectedStatus)
51 }
52
53 function updateVideoChannel (
54 url: string,
55 token: string,
56 channelId: number | string,
57 attributes: VideoChannelUpdate,
58 expectedStatus = 204
59 ) {
60 const body = {}
61 const path = '/api/v1/video-channels/' + channelId
62
63 if (attributes.displayName) body['displayName'] = attributes.displayName
64 if (attributes.description) body['description'] = attributes.description
65 if (attributes.support) body['support'] = attributes.support
66
67 return request(url)
68 .put(path)
69 .send(body)
70 .set('Accept', 'application/json')
71 .set('Authorization', 'Bearer ' + token)
72 .expect(expectedStatus)
73 }
74
75 function deleteVideoChannel (url: string, token: string, channelId: number | string, expectedStatus = 204) {
76 const path = '/api/v1/video-channels/' + channelId
77
78 return request(url)
79 .delete(path)
80 .set('Accept', 'application/json')
81 .set('Authorization', 'Bearer ' + token)
82 .expect(expectedStatus)
83 }
84
85 function getVideoChannel (url: string, channelId: number | string) {
86 const path = '/api/v1/video-channels/' + channelId
87
88 return request(url)
89 .get(path)
90 .set('Accept', 'application/json')
91 .expect(200)
92 .expect('Content-Type', /json/)
93 }
94
95 // ---------------------------------------------------------------------------
96
97 export {
98 getVideoChannelsList,
99 getAccountVideoChannelsList,
100 addVideoChannel,
101 updateVideoChannel,
102 deleteVideoChannel,
103 getVideoChannel
104 }