]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/utils/videos/video-channels.ts
Video channel API routes refractor
[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 accountId: number | string,
38 videoChannelAttributesArg: VideoChannelAttributes,
39 expectedStatus = 200
40 ) {
41 const path = '/api/v1/accounts/' + accountId + '/video-channels/'
42
43 // Default attributes
44 let attributes = {
45 name: 'my super video channel',
46 description: 'my super channel description',
47 support: 'my super channel support'
48 }
49 attributes = Object.assign(attributes, videoChannelAttributesArg)
50
51 return request(url)
52 .post(path)
53 .send(attributes)
54 .set('Accept', 'application/json')
55 .set('Authorization', 'Bearer ' + token)
56 .expect(expectedStatus)
57 }
58
59 function updateVideoChannel (
60 url: string,
61 token: string,
62 accountId: number | string,
63 channelId: number | string,
64 attributes: VideoChannelAttributes,
65 expectedStatus = 204
66 ) {
67 const body = {}
68 const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId
69
70 if (attributes.name) body['name'] = attributes.name
71 if (attributes.description) body['description'] = attributes.description
72 if (attributes.support) body['support'] = attributes.support
73
74 return request(url)
75 .put(path)
76 .send(body)
77 .set('Accept', 'application/json')
78 .set('Authorization', 'Bearer ' + token)
79 .expect(expectedStatus)
80 }
81
82 function deleteVideoChannel (url: string, token: string, accountId: number | string, channelId: number | string, expectedStatus = 204) {
83 const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId
84
85 return request(url)
86 .delete(path)
87 .set('Accept', 'application/json')
88 .set('Authorization', 'Bearer ' + token)
89 .expect(expectedStatus)
90 }
91
92 function getVideoChannel (url: string, accountId: number | string, channelId: number | string) {
93 const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId
94
95 return request(url)
96 .get(path)
97 .set('Accept', 'application/json')
98 .expect(200)
99 .expect('Content-Type', /json/)
100 }
101
102 // ---------------------------------------------------------------------------
103
104 export {
105 getVideoChannelsList,
106 getAccountVideoChannelsList,
107 addVideoChannel,
108 updateVideoChannel,
109 deleteVideoChannel,
110 getVideoChannel
111 }