1 /* eslint-disable @typescript-eslint/no-floating-promises */
3 import * as request from 'supertest'
4 import { VideoChannelUpdate } from '../../models/videos/channel/video-channel-update.model'
5 import { VideoChannelCreate } from '../../models/videos/channel/video-channel-create.model'
6 import { makeGetRequest, updateAvatarRequest } from '../requests/requests'
7 import { ServerInfo } from '../server/servers'
8 import { User } from '../../models/users/user.model'
9 import { getMyUserInformation } from '../users/users'
11 function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {
12 const path = '/api/v1/video-channels'
14 const req = request(url)
16 .query({ start: start })
17 .query({ count: count })
19 if (sort) req.query({ sort })
21 return req.set('Accept', 'application/json')
23 .expect('Content-Type', /json/)
26 function getAccountVideoChannelsList (parameters: {
32 specialStatus?: number
34 const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200 } = parameters
36 const path = '/api/v1/accounts/' + accountName + '/video-channels'
38 return makeGetRequest({
46 statusCodeExpected: specialStatus
50 function addVideoChannel (
53 videoChannelAttributesArg: VideoChannelCreate,
56 const path = '/api/v1/video-channels/'
60 displayName: 'my super video channel',
61 description: 'my super channel description',
62 support: 'my super channel support'
64 attributes = Object.assign(attributes, videoChannelAttributesArg)
69 .set('Accept', 'application/json')
70 .set('Authorization', 'Bearer ' + token)
71 .expect(expectedStatus)
74 function updateVideoChannel (
78 attributes: VideoChannelUpdate,
82 const path = '/api/v1/video-channels/' + channelName
84 if (attributes.displayName) body.displayName = attributes.displayName
85 if (attributes.description) body.description = attributes.description
86 if (attributes.support) body.support = attributes.support
87 if (attributes.bulkVideosSupportUpdate) body.bulkVideosSupportUpdate = attributes.bulkVideosSupportUpdate
92 .set('Accept', 'application/json')
93 .set('Authorization', 'Bearer ' + token)
94 .expect(expectedStatus)
97 function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) {
98 const path = '/api/v1/video-channels/' + channelName
102 .set('Accept', 'application/json')
103 .set('Authorization', 'Bearer ' + token)
104 .expect(expectedStatus)
107 function getVideoChannel (url: string, channelName: string) {
108 const path = '/api/v1/video-channels/' + channelName
112 .set('Accept', 'application/json')
114 .expect('Content-Type', /json/)
117 function updateVideoChannelAvatar (options: {
121 videoChannelName: string | number
124 const path = '/api/v1/video-channels/' + options.videoChannelName + '/avatar/pick'
126 return updateAvatarRequest(Object.assign(options, { path }))
129 function setDefaultVideoChannel (servers: ServerInfo[]) {
130 const tasks: Promise<any>[] = []
132 for (const server of servers) {
133 const p = getMyUserInformation(server.url, server.accessToken)
134 .then(res => { server.videoChannel = (res.body as User).videoChannels[0] })
139 return Promise.all(tasks)
142 // ---------------------------------------------------------------------------
145 updateVideoChannelAvatar,
146 getVideoChannelsList,
147 getAccountVideoChannelsList,
152 setDefaultVideoChannel