]>
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 | ) { | |
7d14d4d2 | 77 | const body: any = {} |
f5b0af50 | 78 | const path = '/api/v1/video-channels/' + channelName |
5f04dd2f | 79 | |
7d14d4d2 C |
80 | if (attributes.displayName) body.displayName = attributes.displayName |
81 | if (attributes.description) body.description = attributes.description | |
82 | if (attributes.support) body.support = attributes.support | |
83 | if (attributes.bulkVideosSupportUpdate) body.bulkVideosSupportUpdate = attributes.bulkVideosSupportUpdate | |
5f04dd2f C |
84 | |
85 | return request(url) | |
86 | .put(path) | |
87 | .send(body) | |
88 | .set('Accept', 'application/json') | |
89 | .set('Authorization', 'Bearer ' + token) | |
90 | .expect(expectedStatus) | |
91 | } | |
92 | ||
f5b0af50 C |
93 | function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) { |
94 | const path = '/api/v1/video-channels/' + channelName | |
5f04dd2f C |
95 | |
96 | return request(url) | |
48dce1c9 | 97 | .delete(path) |
5f04dd2f C |
98 | .set('Accept', 'application/json') |
99 | .set('Authorization', 'Bearer ' + token) | |
100 | .expect(expectedStatus) | |
101 | } | |
102 | ||
f5b0af50 C |
103 | function getVideoChannel (url: string, channelName: string) { |
104 | const path = '/api/v1/video-channels/' + channelName | |
5f04dd2f C |
105 | |
106 | return request(url) | |
107 | .get(path) | |
108 | .set('Accept', 'application/json') | |
109 | .expect(200) | |
110 | .expect('Content-Type', /json/) | |
111 | } | |
112 | ||
4bbfc6c6 C |
113 | function updateVideoChannelAvatar (options: { |
114 | url: string, | |
115 | accessToken: string, | |
116 | fixture: string, | |
8a19bee1 | 117 | videoChannelName: string | number |
4bbfc6c6 C |
118 | }) { |
119 | ||
8a19bee1 | 120 | const path = '/api/v1/video-channels/' + options.videoChannelName + '/avatar/pick' |
4bbfc6c6 C |
121 | |
122 | return updateAvatarRequest(Object.assign(options, { path })) | |
123 | } | |
124 | ||
df0b219d C |
125 | function setDefaultVideoChannel (servers: ServerInfo[]) { |
126 | const tasks: Promise<any>[] = [] | |
127 | ||
128 | for (const server of servers) { | |
129 | const p = getMyUserInformation(server.url, server.accessToken) | |
130 | .then(res => server.videoChannel = (res.body as User).videoChannels[0]) | |
131 | ||
132 | tasks.push(p) | |
133 | } | |
134 | ||
135 | return Promise.all(tasks) | |
136 | } | |
137 | ||
5f04dd2f C |
138 | // --------------------------------------------------------------------------- |
139 | ||
140 | export { | |
4bbfc6c6 | 141 | updateVideoChannelAvatar, |
5f04dd2f | 142 | getVideoChannelsList, |
975e6e0e | 143 | getAccountVideoChannelsList, |
5f04dd2f C |
144 | addVideoChannel, |
145 | updateVideoChannel, | |
146 | deleteVideoChannel, | |
df0b219d C |
147 | getVideoChannel, |
148 | setDefaultVideoChannel | |
5f04dd2f | 149 | } |