1 import * as request from 'supertest'
2 import { VideoChannelCreate, VideoChannelUpdate } from '../../models/videos'
3 import { 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 (url: string, accountName: string, specialStatus = 200) {
23 const path = '/api/v1/accounts/' + accountName + '/video-channels'
27 .set('Accept', 'application/json')
28 .expect(specialStatus)
29 .expect('Content-Type', /json/)
32 function addVideoChannel (
35 videoChannelAttributesArg: VideoChannelCreate,
38 const path = '/api/v1/video-channels/'
42 displayName: 'my super video channel',
43 description: 'my super channel description',
44 support: 'my super channel support'
46 attributes = Object.assign(attributes, videoChannelAttributesArg)
51 .set('Accept', 'application/json')
52 .set('Authorization', 'Bearer ' + token)
53 .expect(expectedStatus)
56 function updateVideoChannel (
60 attributes: VideoChannelUpdate,
64 const path = '/api/v1/video-channels/' + channelName
66 if (attributes.displayName) body['displayName'] = attributes.displayName
67 if (attributes.description) body['description'] = attributes.description
68 if (attributes.support) body['support'] = attributes.support
73 .set('Accept', 'application/json')
74 .set('Authorization', 'Bearer ' + token)
75 .expect(expectedStatus)
78 function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) {
79 const path = '/api/v1/video-channels/' + channelName
83 .set('Accept', 'application/json')
84 .set('Authorization', 'Bearer ' + token)
85 .expect(expectedStatus)
88 function getVideoChannel (url: string, channelName: string) {
89 const path = '/api/v1/video-channels/' + channelName
93 .set('Accept', 'application/json')
95 .expect('Content-Type', /json/)
98 function updateVideoChannelAvatar (options: {
102 videoChannelName: string | number
105 const path = '/api/v1/video-channels/' + options.videoChannelName + '/avatar/pick'
107 return updateAvatarRequest(Object.assign(options, { path }))
110 function setDefaultVideoChannel (servers: ServerInfo[]) {
111 const tasks: Promise<any>[] = []
113 for (const server of servers) {
114 const p = getMyUserInformation(server.url, server.accessToken)
115 .then(res => server.videoChannel = (res.body as User).videoChannels[0])
120 return Promise.all(tasks)
123 // ---------------------------------------------------------------------------
126 updateVideoChannelAvatar,
127 getVideoChannelsList,
128 getAccountVideoChannelsList,
133 setDefaultVideoChannel