aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/videos.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-31 15:20:35 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-10-31 15:32:10 +0100
commit11474c3cd904fa0fc07fc0a3a9a35496da17f300 (patch)
tree945bb2cdc11548c80706dbf7f0db4fa0edabbee0 /server/tests/utils/videos.ts
parentfd45e8f43c2638478599ca75632518054461da85 (diff)
downloadPeerTube-11474c3cd904fa0fc07fc0a3a9a35496da17f300.tar.gz
PeerTube-11474c3cd904fa0fc07fc0a3a9a35496da17f300.tar.zst
PeerTube-11474c3cd904fa0fc07fc0a3a9a35496da17f300.zip
Add tests and fix bugs for video privacy
Diffstat (limited to 'server/tests/utils/videos.ts')
-rw-r--r--server/tests/utils/videos.ts45
1 files changed, 42 insertions, 3 deletions
diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.ts
index 2a5d00255..d4d5faf0a 100644
--- a/server/tests/utils/videos.ts
+++ b/server/tests/utils/videos.ts
@@ -7,6 +7,7 @@ import { makeGetRequest } from './requests'
7import { readFilePromise } from './miscs' 7import { readFilePromise } from './miscs'
8import { ServerInfo } from './servers' 8import { ServerInfo } from './servers'
9import { getMyUserInformation } from './users' 9import { getMyUserInformation } from './users'
10import { VideoPrivacy } from '../../../shared'
10 11
11type VideoAttributes = { 12type VideoAttributes = {
12 name?: string 13 name?: string
@@ -17,6 +18,7 @@ type VideoAttributes = {
17 description?: string 18 description?: string
18 tags?: string[] 19 tags?: string[]
19 channelId?: number 20 channelId?: number
21 privacy?: VideoPrivacy
20 fixture?: string 22 fixture?: string
21} 23}
22 24
@@ -38,6 +40,12 @@ function getVideoLanguages (url: string) {
38 return makeGetRequest(url, path) 40 return makeGetRequest(url, path)
39} 41}
40 42
43function getVideoPrivacies (url: string) {
44 const path = '/api/v1/videos/privacies'
45
46 return makeGetRequest(url, path)
47}
48
41function getAllVideosListBy (url: string) { 49function getAllVideosListBy (url: string) {
42 const path = '/api/v1/videos' 50 const path = '/api/v1/videos'
43 51
@@ -51,14 +59,23 @@ function getAllVideosListBy (url: string) {
51 .expect('Content-Type', /json/) 59 .expect('Content-Type', /json/)
52} 60}
53 61
54function getVideo (url: string, id: number | string) { 62function getVideo (url: string, id: number | string, expectedStatus = 200) {
55 const path = '/api/v1/videos/' + id 63 const path = '/api/v1/videos/' + id
56 64
57 return request(url) 65 return request(url)
58 .get(path) 66 .get(path)
59 .set('Accept', 'application/json') 67 .set('Accept', 'application/json')
60 .expect(200) 68 .expect(expectedStatus)
61 .expect('Content-Type', /json/) 69}
70
71function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = 200) {
72 const path = '/api/v1/videos/' + id
73
74 return request(url)
75 .get(path)
76 .set('Authorization', 'Bearer ' + token)
77 .set('Accept', 'application/json')
78 .expect(expectedStatus)
62} 79}
63 80
64function getVideoDescription (url: string, descriptionPath: string) { 81function getVideoDescription (url: string, descriptionPath: string) {
@@ -80,6 +97,22 @@ function getVideosList (url: string) {
80 .expect('Content-Type', /json/) 97 .expect('Content-Type', /json/)
81} 98}
82 99
100function getMyVideos (url: string, accessToken: string, start: number, count: number, sort?: string) {
101 const path = '/api/v1/users/me/videos'
102
103 const req = request(url)
104 .get(path)
105 .query({ start: start })
106 .query({ count: count })
107
108 if (sort) req.query({ sort })
109
110 return req.set('Accept', 'application/json')
111 .set('Authorization', 'Bearer ' + accessToken)
112 .expect(200)
113 .expect('Content-Type', /json/)
114}
115
83function getVideosListPagination (url: string, start: number, count: number, sort?: string) { 116function getVideosListPagination (url: string, start: number, count: number, sort?: string) {
84 const path = '/api/v1/videos' 117 const path = '/api/v1/videos'
85 118
@@ -191,6 +224,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
191 nsfw: true, 224 nsfw: true,
192 description: 'my super description', 225 description: 'my super description',
193 tags: [ 'tag' ], 226 tags: [ 'tag' ],
227 privacy: VideoPrivacy.PUBLIC,
194 fixture: 'video_short.webm' 228 fixture: 'video_short.webm'
195 } 229 }
196 attributes = Object.assign(attributes, videoAttributesArg) 230 attributes = Object.assign(attributes, videoAttributesArg)
@@ -204,6 +238,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
204 .field('licence', attributes.licence.toString()) 238 .field('licence', attributes.licence.toString())
205 .field('nsfw', JSON.stringify(attributes.nsfw)) 239 .field('nsfw', JSON.stringify(attributes.nsfw))
206 .field('description', attributes.description) 240 .field('description', attributes.description)
241 .field('privacy', attributes.privacy.toString())
207 .field('channelId', attributes.channelId) 242 .field('channelId', attributes.channelId)
208 243
209 if (attributes.language !== undefined) { 244 if (attributes.language !== undefined) {
@@ -236,6 +271,7 @@ function updateVideo (url: string, accessToken: string, id: number, attributes:
236 if (attributes.nsfw) body['nsfw'] = attributes.nsfw 271 if (attributes.nsfw) body['nsfw'] = attributes.nsfw
237 if (attributes.description) body['description'] = attributes.description 272 if (attributes.description) body['description'] = attributes.description
238 if (attributes.tags) body['tags'] = attributes.tags 273 if (attributes.tags) body['tags'] = attributes.tags
274 if (attributes.privacy) body['privacy'] = attributes.privacy
239 275
240 return request(url) 276 return request(url)
241 .put(path) 277 .put(path)
@@ -274,9 +310,12 @@ export {
274 getVideoDescription, 310 getVideoDescription,
275 getVideoCategories, 311 getVideoCategories,
276 getVideoLicences, 312 getVideoLicences,
313 getVideoPrivacies,
277 getVideoLanguages, 314 getVideoLanguages,
278 getAllVideosListBy, 315 getAllVideosListBy,
316 getMyVideos,
279 getVideo, 317 getVideo,
318 getVideoWithToken,
280 getVideosList, 319 getVideosList,
281 getVideosListPagination, 320 getVideosListPagination,
282 getVideosListSort, 321 getVideosListSort,