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