]>
Commit | Line | Data |
---|---|---|
5f04dd2f | 1 | import * as request from 'supertest' |
d4681c00 | 2 | import { VideoChannelCreate, VideoChannelUpdate } from '../../models/videos' |
91b66319 | 3 | import { makeGetRequest, updateAvatarRequest } from '../requests/requests' |
df0b219d C |
4 | import { getMyUserInformation, ServerInfo } from '..' |
5 | import { User } from '../..' | |
5f04dd2f C |
6 | |
7 | function getVideoChannelsList (url: string, start: number, count: number, sort?: string) { | |
48dce1c9 | 8 | const path = '/api/v1/video-channels' |
5f04dd2f C |
9 | |
10 | const req = request(url) | |
11 | .get(path) | |
12 | .query({ start: start }) | |
13 | .query({ count: count }) | |
14 | ||
15 | if (sort) req.query({ sort }) | |
16 | ||
17 | return req.set('Accept', 'application/json') | |
18 | .expect(200) | |
19 | .expect('Content-Type', /json/) | |
20 | } | |
21 | ||
91b66319 C |
22 | function getAccountVideoChannelsList (parameters: { |
23 | url: string, | |
24 | accountName: string, | |
25 | start?: number, | |
26 | count?: number, | |
27 | sort?: string, | |
28 | specialStatus?: number | |
29 | }) { | |
30 | const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200 } = parameters | |
31 | ||
ad9e39fb | 32 | const path = '/api/v1/accounts/' + accountName + '/video-channels' |
5f04dd2f | 33 | |
91b66319 C |
34 | return makeGetRequest({ |
35 | url, | |
36 | path, | |
37 | query: { | |
38 | start, | |
39 | count, | |
40 | sort | |
41 | }, | |
42 | statusCodeExpected: specialStatus | |
43 | }) | |
5f04dd2f C |
44 | } |
45 | ||
48dce1c9 C |
46 | function addVideoChannel ( |
47 | url: string, | |
48 | token: string, | |
08c1efbe | 49 | videoChannelAttributesArg: VideoChannelCreate, |
48dce1c9 C |
50 | expectedStatus = 200 |
51 | ) { | |
cc918ac3 | 52 | const path = '/api/v1/video-channels/' |
5f04dd2f C |
53 | |
54 | // Default attributes | |
55 | let attributes = { | |
08c1efbe | 56 | displayName: 'my super video channel', |
2422c46b C |
57 | description: 'my super channel description', |
58 | support: 'my super channel support' | |
5f04dd2f C |
59 | } |
60 | attributes = Object.assign(attributes, videoChannelAttributesArg) | |
61 | ||
62 | return request(url) | |
63 | .post(path) | |
64 | .send(attributes) | |
65 | .set('Accept', 'application/json') | |
66 | .set('Authorization', 'Bearer ' + token) | |
67 | .expect(expectedStatus) | |
68 | } | |
69 | ||
48dce1c9 C |
70 | function updateVideoChannel ( |
71 | url: string, | |
72 | token: string, | |
f5b0af50 | 73 | channelName: string, |
08c1efbe | 74 | attributes: VideoChannelUpdate, |
48dce1c9 C |
75 | expectedStatus = 204 |
76 | ) { | |
5f04dd2f | 77 | const body = {} |
f5b0af50 | 78 | const path = '/api/v1/video-channels/' + channelName |
5f04dd2f | 79 | |
08c1efbe | 80 | if (attributes.displayName) body['displayName'] = attributes.displayName |
5f04dd2f | 81 | if (attributes.description) body['description'] = attributes.description |
2422c46b | 82 | if (attributes.support) body['support'] = attributes.support |
5f04dd2f C |
83 | |
84 | return request(url) | |
85 | .put(path) | |
86 | .send(body) | |
87 | .set('Accept', 'application/json') | |
88 | .set('Authorization', 'Bearer ' + token) | |
89 | .expect(expectedStatus) | |
90 | } | |
91 | ||
f5b0af50 C |
92 | function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) { |
93 | const path = '/api/v1/video-channels/' + channelName | |
5f04dd2f C |
94 | |
95 | return request(url) | |
48dce1c9 | 96 | .delete(path) |
5f04dd2f C |
97 | .set('Accept', 'application/json') |
98 | .set('Authorization', 'Bearer ' + token) | |
99 | .expect(expectedStatus) | |
100 | } | |
101 | ||
f5b0af50 C |
102 | function getVideoChannel (url: string, channelName: string) { |
103 | const path = '/api/v1/video-channels/' + channelName | |
5f04dd2f C |
104 | |
105 | return request(url) | |
106 | .get(path) | |
107 | .set('Accept', 'application/json') | |
108 | .expect(200) | |
109 | .expect('Content-Type', /json/) | |
110 | } | |
111 | ||
4bbfc6c6 C |
112 | function updateVideoChannelAvatar (options: { |
113 | url: string, | |
114 | accessToken: string, | |
115 | fixture: string, | |
8a19bee1 | 116 | videoChannelName: string | number |
4bbfc6c6 C |
117 | }) { |
118 | ||
8a19bee1 | 119 | const path = '/api/v1/video-channels/' + options.videoChannelName + '/avatar/pick' |
4bbfc6c6 C |
120 | |
121 | return updateAvatarRequest(Object.assign(options, { path })) | |
122 | } | |
123 | ||
df0b219d C |
124 | function setDefaultVideoChannel (servers: ServerInfo[]) { |
125 | const tasks: Promise<any>[] = [] | |
126 | ||
127 | for (const server of servers) { | |
128 | const p = getMyUserInformation(server.url, server.accessToken) | |
129 | .then(res => server.videoChannel = (res.body as User).videoChannels[0]) | |
130 | ||
131 | tasks.push(p) | |
132 | } | |
133 | ||
134 | return Promise.all(tasks) | |
135 | } | |
136 | ||
5f04dd2f C |
137 | // --------------------------------------------------------------------------- |
138 | ||
139 | export { | |
4bbfc6c6 | 140 | updateVideoChannelAvatar, |
5f04dd2f | 141 | getVideoChannelsList, |
975e6e0e | 142 | getAccountVideoChannelsList, |
5f04dd2f C |
143 | addVideoChannel, |
144 | updateVideoChannel, | |
145 | deleteVideoChannel, | |
df0b219d C |
146 | getVideoChannel, |
147 | setDefaultVideoChannel | |
5f04dd2f | 148 | } |