]>
Commit | Line | Data |
---|---|---|
5f04dd2f C |
1 | import * as request from 'supertest' |
2 | ||
3 | type VideoChannelAttributes = { | |
4 | name?: string | |
5 | description?: string | |
2422c46b | 6 | support?: string |
5f04dd2f C |
7 | } |
8 | ||
9 | function getVideoChannelsList (url: string, start: number, count: number, sort?: string) { | |
10 | const path = '/api/v1/videos/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 | ||
11ba2ab3 | 24 | function getAccountVideoChannelsList (url: string, accountId: number | string, specialStatus = 200) { |
975e6e0e | 25 | const path = '/api/v1/videos/accounts/' + accountId + '/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 | ||
2422c46b | 34 | function addVideoChannel (url: string, token: string, videoChannelAttributesArg: VideoChannelAttributes, expectedStatus = 200) { |
5f04dd2f C |
35 | const path = '/api/v1/videos/channels' |
36 | ||
37 | // Default attributes | |
38 | let attributes = { | |
39 | name: 'my super video channel', | |
2422c46b C |
40 | description: 'my super channel description', |
41 | support: 'my super channel support' | |
5f04dd2f C |
42 | } |
43 | attributes = Object.assign(attributes, videoChannelAttributesArg) | |
44 | ||
45 | return request(url) | |
46 | .post(path) | |
47 | .send(attributes) | |
48 | .set('Accept', 'application/json') | |
49 | .set('Authorization', 'Bearer ' + token) | |
50 | .expect(expectedStatus) | |
51 | } | |
52 | ||
53 | function updateVideoChannel (url: string, token: string, channelId: number, attributes: VideoChannelAttributes, expectedStatus = 204) { | |
54 | const body = {} | |
55 | const path = '/api/v1/videos/channels/' + channelId | |
56 | ||
57 | if (attributes.name) body['name'] = attributes.name | |
58 | if (attributes.description) body['description'] = attributes.description | |
2422c46b | 59 | if (attributes.support) body['support'] = attributes.support |
5f04dd2f C |
60 | |
61 | return request(url) | |
62 | .put(path) | |
63 | .send(body) | |
64 | .set('Accept', 'application/json') | |
65 | .set('Authorization', 'Bearer ' + token) | |
66 | .expect(expectedStatus) | |
67 | } | |
68 | ||
69 | function deleteVideoChannel (url: string, token: string, channelId: number, expectedStatus = 204) { | |
70 | const path = '/api/v1/videos/channels/' | |
71 | ||
72 | return request(url) | |
73 | .delete(path + channelId) | |
74 | .set('Accept', 'application/json') | |
75 | .set('Authorization', 'Bearer ' + token) | |
76 | .expect(expectedStatus) | |
77 | } | |
78 | ||
79 | function getVideoChannel (url: string, channelId: number) { | |
80 | const path = '/api/v1/videos/channels/' + channelId | |
81 | ||
82 | return request(url) | |
83 | .get(path) | |
84 | .set('Accept', 'application/json') | |
85 | .expect(200) | |
86 | .expect('Content-Type', /json/) | |
87 | } | |
88 | ||
89 | // --------------------------------------------------------------------------- | |
90 | ||
91 | export { | |
92 | getVideoChannelsList, | |
975e6e0e | 93 | getAccountVideoChannelsList, |
5f04dd2f C |
94 | addVideoChannel, |
95 | updateVideoChannel, | |
96 | deleteVideoChannel, | |
97 | getVideoChannel | |
98 | } |