]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/utils/video-channels.ts
Speed up activity pub http requests
[github/Chocobozzz/PeerTube.git] / server / tests / utils / video-channels.ts
CommitLineData
5f04dd2f
C
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 getAuthorVideoChannelsList (url: string, authorId: number | string) {
24 const path = '/api/v1/videos/authors/' + authorId + '/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 getAuthorVideoChannelsList,
91 addVideoChannel,
92 updateVideoChannel,
93 deleteVideoChannel,
94 getVideoChannel
95}