1 import * as request from 'supertest'
2 import { VideoChannelCreate, VideoChannelUpdate } from '../../models/videos'
3 import { makeGetRequest, updateAvatarRequest } from '../requests/requests'
4 import { getMyUserInformation, ServerInfo } from '..'
5 import { User } from '../..'
7 function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {
8 const path = '/api/v1/video-channels'
10 const req = request(url)
12 .query({ start: start })
13 .query({ count: count })
15 if (sort) req.query({ sort })
17 return req.set('Accept', 'application/json')
19 .expect('Content-Type', /json/)
22 function getAccountVideoChannelsList (parameters: {
28 specialStatus?: number
30 const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200 } = parameters
32 const path = '/api/v1/accounts/' + accountName + '/video-channels'
34 return makeGetRequest({
42 statusCodeExpected: specialStatus
46 function addVideoChannel (
49 videoChannelAttributesArg: VideoChannelCreate,
52 const path = '/api/v1/video-channels/'
56 displayName: 'my super video channel',
57 description: 'my super channel description',
58 support: 'my super channel support'
60 attributes = Object.assign(attributes, videoChannelAttributesArg)
65 .set('Accept', 'application/json')
66 .set('Authorization', 'Bearer ' + token)
67 .expect(expectedStatus)
70 function updateVideoChannel (
74 attributes: VideoChannelUpdate,
78 const path = '/api/v1/video-channels/' + channelName
80 if (attributes.displayName) body['displayName'] = attributes.displayName
81 if (attributes.description) body['description'] = attributes.description
82 if (attributes.support) body['support'] = attributes.support
87 .set('Accept', 'application/json')
88 .set('Authorization', 'Bearer ' + token)
89 .expect(expectedStatus)
92 function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) {
93 const path = '/api/v1/video-channels/' + channelName
97 .set('Accept', 'application/json')
98 .set('Authorization', 'Bearer ' + token)
99 .expect(expectedStatus)
102 function getVideoChannel (url: string, channelName: string) {
103 const path = '/api/v1/video-channels/' + channelName
107 .set('Accept', 'application/json')
109 .expect('Content-Type', /json/)
112 function updateVideoChannelAvatar (options: {
116 videoChannelName: string | number
119 const path = '/api/v1/video-channels/' + options.videoChannelName + '/avatar/pick'
121 return updateAvatarRequest(Object.assign(options, { path }))
124 function setDefaultVideoChannel (servers: ServerInfo[]) {
125 const tasks: Promise<any>[] = []
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])
134 return Promise.all(tasks)
137 // ---------------------------------------------------------------------------
140 updateVideoChannelAvatar,
141 getVideoChannelsList,
142 getAccountVideoChannelsList,
147 setDefaultVideoChannel