]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/utils/videos/video-channels.ts
Add video channel account list
[github/Chocobozzz/PeerTube.git] / server / tests / utils / videos / video-channels.ts
CommitLineData
5f04dd2f
C
1import * as request from 'supertest'
2
3type VideoChannelAttributes = {
4 name?: string
5 description?: string
2422c46b 6 support?: string
5f04dd2f
C
7}
8
9function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {
48dce1c9 10 const path = '/api/v1/video-channels'
5f04dd2f
C
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
11ba2ab3 24function getAccountVideoChannelsList (url: string, accountId: number | string, specialStatus = 200) {
48dce1c9 25 const path = '/api/v1/accounts/' + accountId + '/video-channels'
5f04dd2f
C
26
27 return request(url)
28 .get(path)
29 .set('Accept', 'application/json')
11ba2ab3 30 .expect(specialStatus)
5f04dd2f
C
31 .expect('Content-Type', /json/)
32}
33
48dce1c9
C
34function addVideoChannel (
35 url: string,
36 token: string,
6b738c7a 37 accountId: number | string,
48dce1c9
C
38 videoChannelAttributesArg: VideoChannelAttributes,
39 expectedStatus = 200
40) {
41 const path = '/api/v1/accounts/' + accountId + '/video-channels/'
5f04dd2f
C
42
43 // Default attributes
44 let attributes = {
45 name: 'my super video channel',
2422c46b
C
46 description: 'my super channel description',
47 support: 'my super channel support'
5f04dd2f
C
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
48dce1c9
C
59function updateVideoChannel (
60 url: string,
61 token: string,
6b738c7a
C
62 accountId: number | string,
63 channelId: number | string,
48dce1c9
C
64 attributes: VideoChannelAttributes,
65 expectedStatus = 204
66) {
5f04dd2f 67 const body = {}
48dce1c9 68 const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId
5f04dd2f
C
69
70 if (attributes.name) body['name'] = attributes.name
71 if (attributes.description) body['description'] = attributes.description
2422c46b 72 if (attributes.support) body['support'] = attributes.support
5f04dd2f
C
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
6b738c7a 82function deleteVideoChannel (url: string, token: string, accountId: number | string, channelId: number | string, expectedStatus = 204) {
48dce1c9 83 const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId
5f04dd2f
C
84
85 return request(url)
48dce1c9 86 .delete(path)
5f04dd2f
C
87 .set('Accept', 'application/json')
88 .set('Authorization', 'Bearer ' + token)
89 .expect(expectedStatus)
90}
91
6b738c7a 92function getVideoChannel (url: string, accountId: number | string, channelId: number | string) {
48dce1c9 93 const path = '/api/v1/accounts/' + accountId + '/video-channels/' + channelId
5f04dd2f
C
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
104export {
105 getVideoChannelsList,
975e6e0e 106 getAccountVideoChannelsList,
5f04dd2f
C
107 addVideoChannel,
108 updateVideoChannel,
109 deleteVideoChannel,
110 getVideoChannel
111}