]>
Commit | Line | Data |
---|---|---|
5f04dd2f | 1 | import * as request from 'supertest' |
08c1efbe | 2 | import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared/models/videos' |
5f04dd2f C |
3 | |
4 | function getVideoChannelsList (url: string, start: number, count: number, sort?: string) { | |
48dce1c9 | 5 | const path = '/api/v1/video-channels' |
5f04dd2f C |
6 | |
7 | const req = request(url) | |
8 | .get(path) | |
9 | .query({ start: start }) | |
10 | .query({ count: count }) | |
11 | ||
12 | if (sort) req.query({ sort }) | |
13 | ||
14 | return req.set('Accept', 'application/json') | |
15 | .expect(200) | |
16 | .expect('Content-Type', /json/) | |
17 | } | |
18 | ||
11ba2ab3 | 19 | function getAccountVideoChannelsList (url: string, accountId: number | string, specialStatus = 200) { |
48dce1c9 | 20 | const path = '/api/v1/accounts/' + accountId + '/video-channels' |
5f04dd2f C |
21 | |
22 | return request(url) | |
23 | .get(path) | |
24 | .set('Accept', 'application/json') | |
11ba2ab3 | 25 | .expect(specialStatus) |
5f04dd2f C |
26 | .expect('Content-Type', /json/) |
27 | } | |
28 | ||
48dce1c9 C |
29 | function addVideoChannel ( |
30 | url: string, | |
31 | token: string, | |
08c1efbe | 32 | videoChannelAttributesArg: VideoChannelCreate, |
48dce1c9 C |
33 | expectedStatus = 200 |
34 | ) { | |
cc918ac3 | 35 | const path = '/api/v1/video-channels/' |
5f04dd2f C |
36 | |
37 | // Default attributes | |
38 | let attributes = { | |
08c1efbe | 39 | displayName: '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 | ||
48dce1c9 C |
53 | function updateVideoChannel ( |
54 | url: string, | |
55 | token: string, | |
6b738c7a | 56 | channelId: number | string, |
08c1efbe | 57 | attributes: VideoChannelUpdate, |
48dce1c9 C |
58 | expectedStatus = 204 |
59 | ) { | |
5f04dd2f | 60 | const body = {} |
cc918ac3 | 61 | const path = '/api/v1/video-channels/' + channelId |
5f04dd2f | 62 | |
08c1efbe | 63 | if (attributes.displayName) body['displayName'] = attributes.displayName |
5f04dd2f | 64 | if (attributes.description) body['description'] = attributes.description |
2422c46b | 65 | if (attributes.support) body['support'] = attributes.support |
5f04dd2f C |
66 | |
67 | return request(url) | |
68 | .put(path) | |
69 | .send(body) | |
70 | .set('Accept', 'application/json') | |
71 | .set('Authorization', 'Bearer ' + token) | |
72 | .expect(expectedStatus) | |
73 | } | |
74 | ||
cc918ac3 C |
75 | function deleteVideoChannel (url: string, token: string, channelId: number | string, expectedStatus = 204) { |
76 | const path = '/api/v1/video-channels/' + channelId | |
5f04dd2f C |
77 | |
78 | return request(url) | |
48dce1c9 | 79 | .delete(path) |
5f04dd2f C |
80 | .set('Accept', 'application/json') |
81 | .set('Authorization', 'Bearer ' + token) | |
82 | .expect(expectedStatus) | |
83 | } | |
84 | ||
cc918ac3 C |
85 | function getVideoChannel (url: string, channelId: number | string) { |
86 | const path = '/api/v1/video-channels/' + channelId | |
5f04dd2f C |
87 | |
88 | return request(url) | |
89 | .get(path) | |
90 | .set('Accept', 'application/json') | |
91 | .expect(200) | |
92 | .expect('Content-Type', /json/) | |
93 | } | |
94 | ||
95 | // --------------------------------------------------------------------------- | |
96 | ||
97 | export { | |
98 | getVideoChannelsList, | |
975e6e0e | 99 | getAccountVideoChannelsList, |
5f04dd2f C |
100 | addVideoChannel, |
101 | updateVideoChannel, | |
102 | deleteVideoChannel, | |
103 | getVideoChannel | |
104 | } |