aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/videos/video-channels.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils/videos/video-channels.ts')
-rw-r--r--server/tests/utils/videos/video-channels.ts95
1 files changed, 95 insertions, 0 deletions
diff --git a/server/tests/utils/videos/video-channels.ts b/server/tests/utils/videos/video-channels.ts
new file mode 100644
index 000000000..0fb80d331
--- /dev/null
+++ b/server/tests/utils/videos/video-channels.ts
@@ -0,0 +1,95 @@
1import * as request from 'supertest'
2
3type VideoChannelAttributes = {
4 name?: string
5 description?: string
6}
7
8function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {
9 const path = '/api/v1/videos/channels'
10
11 const req = request(url)
12 .get(path)
13 .query({ start: start })
14 .query({ count: count })
15
16 if (sort) req.query({ sort })
17
18 return req.set('Accept', 'application/json')
19 .expect(200)
20 .expect('Content-Type', /json/)
21}
22
23function getAccountVideoChannelsList (url: string, accountId: number | string) {
24 const path = '/api/v1/videos/accounts/' + accountId + '/channels'
25
26 return request(url)
27 .get(path)
28 .set('Accept', 'application/json')
29 .expect(200)
30 .expect('Content-Type', /json/)
31}
32
33function addVideoChannel (url: string, token: string, videoChannelAttributesArg: VideoChannelAttributes, expectedStatus = 204) {
34 const path = '/api/v1/videos/channels'
35
36 // Default attributes
37 let attributes = {
38 name: 'my super video channel',
39 description: 'my super channel description'
40 }
41 attributes = Object.assign(attributes, videoChannelAttributesArg)
42
43 return request(url)
44 .post(path)
45 .send(attributes)
46 .set('Accept', 'application/json')
47 .set('Authorization', 'Bearer ' + token)
48 .expect(expectedStatus)
49}
50
51function updateVideoChannel (url: string, token: string, channelId: number, attributes: VideoChannelAttributes, expectedStatus = 204) {
52 const body = {}
53 const path = '/api/v1/videos/channels/' + channelId
54
55 if (attributes.name) body['name'] = attributes.name
56 if (attributes.description) body['description'] = attributes.description
57
58 return request(url)
59 .put(path)
60 .send(body)
61 .set('Accept', 'application/json')
62 .set('Authorization', 'Bearer ' + token)
63 .expect(expectedStatus)
64}
65
66function deleteVideoChannel (url: string, token: string, channelId: number, expectedStatus = 204) {
67 const path = '/api/v1/videos/channels/'
68
69 return request(url)
70 .delete(path + channelId)
71 .set('Accept', 'application/json')
72 .set('Authorization', 'Bearer ' + token)
73 .expect(expectedStatus)
74}
75
76function getVideoChannel (url: string, channelId: number) {
77 const path = '/api/v1/videos/channels/' + channelId
78
79 return request(url)
80 .get(path)
81 .set('Accept', 'application/json')
82 .expect(200)
83 .expect('Content-Type', /json/)
84}
85
86// ---------------------------------------------------------------------------
87
88export {
89 getVideoChannelsList,
90 getAccountVideoChannelsList,
91 addVideoChannel,
92 updateVideoChannel,
93 deleteVideoChannel,
94 getVideoChannel
95}