1 import * as request from 'supertest'
2 import { VideoChannelCreate, VideoChannelUpdate } from '../../models/videos'
3 import { updateAvatarRequest } from '../requests/requests'
5 function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {
6 const path = '/api/v1/video-channels'
8 const req = request(url)
10 .query({ start: start })
11 .query({ count: count })
13 if (sort) req.query({ sort })
15 return req.set('Accept', 'application/json')
17 .expect('Content-Type', /json/)
20 function getAccountVideoChannelsList (url: string, accountName: string, specialStatus = 200) {
21 const path = '/api/v1/accounts/' + accountName + '/video-channels'
25 .set('Accept', 'application/json')
26 .expect(specialStatus)
27 .expect('Content-Type', /json/)
30 function addVideoChannel (
33 videoChannelAttributesArg: VideoChannelCreate,
36 const path = '/api/v1/video-channels/'
40 displayName: 'my super video channel',
41 description: 'my super channel description',
42 support: 'my super channel support'
44 attributes = Object.assign(attributes, videoChannelAttributesArg)
49 .set('Accept', 'application/json')
50 .set('Authorization', 'Bearer ' + token)
51 .expect(expectedStatus)
54 function updateVideoChannel (
58 attributes: VideoChannelUpdate,
62 const path = '/api/v1/video-channels/' + channelName
64 if (attributes.displayName) body['displayName'] = attributes.displayName
65 if (attributes.description) body['description'] = attributes.description
66 if (attributes.support) body['support'] = attributes.support
71 .set('Accept', 'application/json')
72 .set('Authorization', 'Bearer ' + token)
73 .expect(expectedStatus)
76 function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) {
77 const path = '/api/v1/video-channels/' + channelName
81 .set('Accept', 'application/json')
82 .set('Authorization', 'Bearer ' + token)
83 .expect(expectedStatus)
86 function getVideoChannel (url: string, channelName: string) {
87 const path = '/api/v1/video-channels/' + channelName
91 .set('Accept', 'application/json')
93 .expect('Content-Type', /json/)
96 function updateVideoChannelAvatar (options: {
100 videoChannelName: string | number
103 const path = '/api/v1/video-channels/' + options.videoChannelName + '/avatar/pick'
105 return updateAvatarRequest(Object.assign(options, { path }))
108 // ---------------------------------------------------------------------------
111 updateVideoChannelAvatar,
112 getVideoChannelsList,
113 getAccountVideoChannelsList,