]>
Commit | Line | Data |
---|---|---|
5f04dd2f | 1 | import * as request from 'supertest' |
08c1efbe | 2 | import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared/models/videos' |
4bbfc6c6 | 3 | import { updateAvatarRequest } from '../index' |
5f04dd2f C |
4 | |
5 | function getVideoChannelsList (url: string, start: number, count: number, sort?: string) { | |
48dce1c9 | 6 | const path = '/api/v1/video-channels' |
5f04dd2f C |
7 | |
8 | const req = request(url) | |
9 | .get(path) | |
10 | .query({ start: start }) | |
11 | .query({ count: count }) | |
12 | ||
13 | if (sort) req.query({ sort }) | |
14 | ||
15 | return req.set('Accept', 'application/json') | |
16 | .expect(200) | |
17 | .expect('Content-Type', /json/) | |
18 | } | |
19 | ||
ad9e39fb C |
20 | function getAccountVideoChannelsList (url: string, accountName: string, specialStatus = 200) { |
21 | const path = '/api/v1/accounts/' + accountName + '/video-channels' | |
5f04dd2f C |
22 | |
23 | return request(url) | |
24 | .get(path) | |
25 | .set('Accept', 'application/json') | |
11ba2ab3 | 26 | .expect(specialStatus) |
5f04dd2f C |
27 | .expect('Content-Type', /json/) |
28 | } | |
29 | ||
48dce1c9 C |
30 | function addVideoChannel ( |
31 | url: string, | |
32 | token: string, | |
08c1efbe | 33 | videoChannelAttributesArg: VideoChannelCreate, |
48dce1c9 C |
34 | expectedStatus = 200 |
35 | ) { | |
cc918ac3 | 36 | const path = '/api/v1/video-channels/' |
5f04dd2f C |
37 | |
38 | // Default attributes | |
39 | let attributes = { | |
08c1efbe | 40 | displayName: 'my super video channel', |
2422c46b C |
41 | description: 'my super channel description', |
42 | support: 'my super channel support' | |
5f04dd2f C |
43 | } |
44 | attributes = Object.assign(attributes, videoChannelAttributesArg) | |
45 | ||
46 | return request(url) | |
47 | .post(path) | |
48 | .send(attributes) | |
49 | .set('Accept', 'application/json') | |
50 | .set('Authorization', 'Bearer ' + token) | |
51 | .expect(expectedStatus) | |
52 | } | |
53 | ||
48dce1c9 C |
54 | function updateVideoChannel ( |
55 | url: string, | |
56 | token: string, | |
f5b0af50 | 57 | channelName: string, |
08c1efbe | 58 | attributes: VideoChannelUpdate, |
48dce1c9 C |
59 | expectedStatus = 204 |
60 | ) { | |
5f04dd2f | 61 | const body = {} |
f5b0af50 | 62 | const path = '/api/v1/video-channels/' + channelName |
5f04dd2f | 63 | |
08c1efbe | 64 | if (attributes.displayName) body['displayName'] = attributes.displayName |
5f04dd2f | 65 | if (attributes.description) body['description'] = attributes.description |
2422c46b | 66 | if (attributes.support) body['support'] = attributes.support |
5f04dd2f C |
67 | |
68 | return request(url) | |
69 | .put(path) | |
70 | .send(body) | |
71 | .set('Accept', 'application/json') | |
72 | .set('Authorization', 'Bearer ' + token) | |
73 | .expect(expectedStatus) | |
74 | } | |
75 | ||
f5b0af50 C |
76 | function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) { |
77 | const path = '/api/v1/video-channels/' + channelName | |
5f04dd2f C |
78 | |
79 | return request(url) | |
48dce1c9 | 80 | .delete(path) |
5f04dd2f C |
81 | .set('Accept', 'application/json') |
82 | .set('Authorization', 'Bearer ' + token) | |
83 | .expect(expectedStatus) | |
84 | } | |
85 | ||
f5b0af50 C |
86 | function getVideoChannel (url: string, channelName: string) { |
87 | const path = '/api/v1/video-channels/' + channelName | |
5f04dd2f C |
88 | |
89 | return request(url) | |
90 | .get(path) | |
91 | .set('Accept', 'application/json') | |
92 | .expect(200) | |
93 | .expect('Content-Type', /json/) | |
94 | } | |
95 | ||
4bbfc6c6 C |
96 | function updateVideoChannelAvatar (options: { |
97 | url: string, | |
98 | accessToken: string, | |
99 | fixture: string, | |
8a19bee1 | 100 | videoChannelName: string | number |
4bbfc6c6 C |
101 | }) { |
102 | ||
8a19bee1 | 103 | const path = '/api/v1/video-channels/' + options.videoChannelName + '/avatar/pick' |
4bbfc6c6 C |
104 | |
105 | return updateAvatarRequest(Object.assign(options, { path })) | |
106 | } | |
107 | ||
5f04dd2f C |
108 | // --------------------------------------------------------------------------- |
109 | ||
110 | export { | |
4bbfc6c6 | 111 | updateVideoChannelAvatar, |
5f04dd2f | 112 | getVideoChannelsList, |
975e6e0e | 113 | getAccountVideoChannelsList, |
5f04dd2f C |
114 | addVideoChannel, |
115 | updateVideoChannel, | |
116 | deleteVideoChannel, | |
117 | getVideoChannel | |
118 | } |