X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Futils%2Fvideos.ts;h=73a9f1a0abbc6024cecf2494d6cce3ab10eed1a2;hb=1b5b10d13152d704d2396a1e53d56aba1a8e7e03;hp=2a9a236ca50259f9b550ba4a21680cb04cb601e0;hpb=14d3270f363245d2c83fcc2ac109e39743b5627e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.ts index 2a9a236ca..73a9f1a0a 100644 --- a/server/tests/utils/videos.ts +++ b/server/tests/utils/videos.ts @@ -6,6 +6,8 @@ import * as parseTorrent from 'parse-torrent' import { makeGetRequest } from './requests' import { readFilePromise } from './miscs' import { ServerInfo } from './servers' +import { getMyUserInformation } from './users' +import { VideoPrivacy } from '../../../shared' type VideoAttributes = { name?: string @@ -15,6 +17,8 @@ type VideoAttributes = { nsfw?: boolean description?: string tags?: string[] + channelId?: number + privacy?: VideoPrivacy fixture?: string } @@ -36,27 +40,46 @@ function getVideoLanguages (url: string) { return makeGetRequest(url, path) } -function getAllVideosListBy (url: string) { - const path = '/api/v1/videos' +function getVideoPrivacies (url: string) { + const path = '/api/v1/videos/privacies' + + return makeGetRequest(url, path) +} + +function getVideo (url: string, id: number | string, expectedStatus = 200) { + const path = '/api/v1/videos/' + id return request(url) .get(path) - .query({ sort: 'createdAt' }) - .query({ start: 0 }) - .query({ count: 10000 }) .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) + .expect(expectedStatus) } -function getVideo (url: string, id: number | string) { +function viewVideo (url: string, id: number | string, expectedStatus = 204) { + const path = '/api/v1/videos/' + id + '/views' + + return request(url) + .post(path) + .set('Accept', 'application/json') + .expect(expectedStatus) +} + +function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = 200) { const path = '/api/v1/videos/' + id return request(url) - .get(path) - .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) + .get(path) + .set('Authorization', 'Bearer ' + token) + .set('Accept', 'application/json') + .expect(expectedStatus) +} + +function getVideoDescription (url: string, descriptionPath: string) { + return request(url) + .get(descriptionPath) + .set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) } function getVideosList (url: string) { @@ -70,6 +93,22 @@ function getVideosList (url: string) { .expect('Content-Type', /json/) } +function getMyVideos (url: string, accessToken: string, start: number, count: number, sort?: string) { + const path = '/api/v1/users/me/videos' + + const req = request(url) + .get(path) + .query({ start: start }) + .query({ count: count }) + + if (sort) req.query({ sort }) + + return req.set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + accessToken) + .expect(200) + .expect('Content-Type', /json/) +} + function getVideosListPagination (url: string, start: number, count: number, sort?: string) { const path = '/api/v1/videos' @@ -162,8 +201,14 @@ async function testVideoImage (url: string, imageName: string, imagePath: string } } -function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 204) { +async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 204) { const path = '/api/v1/videos/upload' + let defaultChannelId = '1' + + try { + const res = await getMyUserInformation(url, accessToken) + defaultChannelId = res.body.videoChannels[0].id + } catch (e) { /* empty */ } // Default attributes let attributes = { @@ -171,9 +216,11 @@ function uploadVideo (url: string, accessToken: string, videoAttributesArg: Vide category: 5, licence: 4, language: 3, + channelId: defaultChannelId, nsfw: true, description: 'my super description', tags: [ 'tag' ], + privacy: VideoPrivacy.PUBLIC, fixture: 'video_short.webm' } attributes = Object.assign(attributes, videoAttributesArg) @@ -187,6 +234,8 @@ function uploadVideo (url: string, accessToken: string, videoAttributesArg: Vide .field('licence', attributes.licence.toString()) .field('nsfw', JSON.stringify(attributes.nsfw)) .field('description', attributes.description) + .field('privacy', attributes.privacy.toString()) + .field('channelId', attributes.channelId) if (attributes.language !== undefined) { req.field('language', attributes.language.toString()) @@ -218,6 +267,7 @@ function updateVideo (url: string, accessToken: string, id: number, attributes: if (attributes.nsfw) body['nsfw'] = attributes.nsfw if (attributes.description) body['description'] = attributes.description if (attributes.tags) body['tags'] = attributes.tags + if (attributes.privacy) body['privacy'] = attributes.privacy return request(url) .put(path) @@ -253,11 +303,14 @@ function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: n // --------------------------------------------------------------------------- export { + getVideoDescription, getVideoCategories, getVideoLicences, + getVideoPrivacies, getVideoLanguages, - getAllVideosListBy, + getMyVideos, getVideo, + getVideoWithToken, getVideosList, getVideosListPagination, getVideosListSort, @@ -269,5 +322,6 @@ export { uploadVideo, updateVideo, rateVideo, + viewVideo, parseTorrentVideo }