mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Add playlist rest tests
This commit is contained in:
@@ -13,6 +13,9 @@ export interface PlaylistObject {
|
||||
|
||||
icon: ActivityIconObject
|
||||
|
||||
published: string
|
||||
updated: string
|
||||
|
||||
orderedItems?: string[]
|
||||
|
||||
partOf?: string
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export enum VideoPlaylistType {
|
||||
REGULAR = 1,
|
||||
WATCH_LATER = 2
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { AccountSummary } from '../../actors/index'
|
||||
import { VideoChannelSummary, VideoConstant } from '..'
|
||||
import { VideoPlaylistPrivacy } from './video-playlist-privacy.model'
|
||||
import { VideoPlaylistType } from './video-playlist-type.model'
|
||||
|
||||
export interface VideoPlaylist {
|
||||
id: number
|
||||
@@ -15,6 +16,8 @@ export interface VideoPlaylist {
|
||||
|
||||
videosLength: number
|
||||
|
||||
type: VideoConstant<VideoPlaylistType>
|
||||
|
||||
createdAt: Date | string
|
||||
updatedAt: Date | string
|
||||
|
||||
|
||||
@@ -77,6 +77,8 @@ function makeUploadRequest (options: {
|
||||
Object.keys(options.fields).forEach(field => {
|
||||
const value = options.fields[field]
|
||||
|
||||
if (value === undefined) return
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
req.field(field + '[' + i + ']', value[i])
|
||||
|
||||
@@ -6,6 +6,7 @@ import { root, wait } from '../miscs/miscs'
|
||||
import { readdir, readFile } from 'fs-extra'
|
||||
import { existsSync } from 'fs'
|
||||
import { expect } from 'chai'
|
||||
import { VideoChannel } from '../../models/videos'
|
||||
|
||||
interface ServerInfo {
|
||||
app: ChildProcess,
|
||||
@@ -25,6 +26,7 @@ interface ServerInfo {
|
||||
}
|
||||
|
||||
accessToken?: string
|
||||
videoChannel?: VideoChannel
|
||||
|
||||
video?: {
|
||||
id: number
|
||||
@@ -39,6 +41,8 @@ interface ServerInfo {
|
||||
id: number
|
||||
uuid: string
|
||||
}
|
||||
|
||||
videos?: { id: number, uuid: string }[]
|
||||
}
|
||||
|
||||
function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) {
|
||||
|
||||
@@ -3,6 +3,7 @@ import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '..
|
||||
|
||||
import { UserRole } from '../../index'
|
||||
import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type'
|
||||
import { ServerInfo, userLogin } from '..'
|
||||
|
||||
function createUser (
|
||||
url: string,
|
||||
@@ -32,6 +33,13 @@ function createUser (
|
||||
.expect(specialStatus)
|
||||
}
|
||||
|
||||
async function generateUserAccessToken (server: ServerInfo, username: string) {
|
||||
const password = 'my super password'
|
||||
await createUser(server.url, server.accessToken, username, password)
|
||||
|
||||
return userLogin(server, { username, password })
|
||||
}
|
||||
|
||||
function registerUser (url: string, username: string, password: string, specialStatus = 204) {
|
||||
const path = '/api/v1/users/register'
|
||||
const body = {
|
||||
@@ -300,5 +308,6 @@ export {
|
||||
resetPassword,
|
||||
updateMyAvatar,
|
||||
askSendVerifyEmail,
|
||||
generateUserAccessToken,
|
||||
verifyEmail
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import * as request from 'supertest'
|
||||
import { VideoChannelCreate, VideoChannelUpdate } from '../../models/videos'
|
||||
import { updateAvatarRequest } from '../requests/requests'
|
||||
import { getMyUserInformation, ServerInfo } from '..'
|
||||
import { User } from '../..'
|
||||
|
||||
function getVideoChannelsList (url: string, start: number, count: number, sort?: string) {
|
||||
const path = '/api/v1/video-channels'
|
||||
@@ -105,6 +107,19 @@ function updateVideoChannelAvatar (options: {
|
||||
return updateAvatarRequest(Object.assign(options, { path }))
|
||||
}
|
||||
|
||||
function setDefaultVideoChannel (servers: ServerInfo[]) {
|
||||
const tasks: Promise<any>[] = []
|
||||
|
||||
for (const server of servers) {
|
||||
const p = getMyUserInformation(server.url, server.accessToken)
|
||||
.then(res => server.videoChannel = (res.body as User).videoChannels[0])
|
||||
|
||||
tasks.push(p)
|
||||
}
|
||||
|
||||
return Promise.all(tasks)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
@@ -114,5 +129,6 @@ export {
|
||||
addVideoChannel,
|
||||
updateVideoChannel,
|
||||
deleteVideoChannel,
|
||||
getVideoChannel
|
||||
getVideoChannel,
|
||||
setDefaultVideoChannel
|
||||
}
|
||||
|
||||
@@ -4,6 +4,12 @@ import { omit } from 'lodash'
|
||||
import { VideoPlaylistUpdate } from '../../models/videos/playlist/video-playlist-update.model'
|
||||
import { VideoPlaylistElementCreate } from '../../models/videos/playlist/video-playlist-element-create.model'
|
||||
import { VideoPlaylistElementUpdate } from '../../models/videos/playlist/video-playlist-element-update.model'
|
||||
import { videoUUIDToId } from './videos'
|
||||
import { join } from 'path'
|
||||
import { root } from '..'
|
||||
import { readdir } from 'fs-extra'
|
||||
import { expect } from 'chai'
|
||||
import { VideoPlaylistType } from '../../models/videos/playlist/video-playlist-type.model'
|
||||
|
||||
function getVideoPlaylistsList (url: string, start: number, count: number, sort?: string) {
|
||||
const path = '/api/v1/video-playlists'
|
||||
@@ -17,7 +23,67 @@ function getVideoPlaylistsList (url: string, start: number, count: number, sort?
|
||||
return makeGetRequest({
|
||||
url,
|
||||
path,
|
||||
query
|
||||
query,
|
||||
statusCodeExpected: 200
|
||||
})
|
||||
}
|
||||
|
||||
function getVideoChannelPlaylistsList (url: string, videoChannelName: string, start: number, count: number, sort?: string) {
|
||||
const path = '/api/v1/video-channels/' + videoChannelName + '/video-playlists'
|
||||
|
||||
const query = {
|
||||
start,
|
||||
count,
|
||||
sort
|
||||
}
|
||||
|
||||
return makeGetRequest({
|
||||
url,
|
||||
path,
|
||||
query,
|
||||
statusCodeExpected: 200
|
||||
})
|
||||
}
|
||||
|
||||
function getAccountPlaylistsList (url: string, accountName: string, start: number, count: number, sort?: string) {
|
||||
const path = '/api/v1/accounts/' + accountName + '/video-playlists'
|
||||
|
||||
const query = {
|
||||
start,
|
||||
count,
|
||||
sort
|
||||
}
|
||||
|
||||
return makeGetRequest({
|
||||
url,
|
||||
path,
|
||||
query,
|
||||
statusCodeExpected: 200
|
||||
})
|
||||
}
|
||||
|
||||
function getAccountPlaylistsListWithToken (
|
||||
url: string,
|
||||
token: string,
|
||||
accountName: string,
|
||||
start: number,
|
||||
count: number,
|
||||
playlistType?: VideoPlaylistType
|
||||
) {
|
||||
const path = '/api/v1/accounts/' + accountName + '/video-playlists'
|
||||
|
||||
const query = {
|
||||
start,
|
||||
count,
|
||||
playlistType
|
||||
}
|
||||
|
||||
return makeGetRequest({
|
||||
url,
|
||||
token,
|
||||
path,
|
||||
query,
|
||||
statusCodeExpected: 200
|
||||
})
|
||||
}
|
||||
|
||||
@@ -31,6 +97,17 @@ function getVideoPlaylist (url: string, playlistId: number | string, statusCodeE
|
||||
})
|
||||
}
|
||||
|
||||
function getVideoPlaylistWithToken (url: string, token: string, playlistId: number | string, statusCodeExpected = 200) {
|
||||
const path = '/api/v1/video-playlists/' + playlistId
|
||||
|
||||
return makeGetRequest({
|
||||
url,
|
||||
token,
|
||||
path,
|
||||
statusCodeExpected
|
||||
})
|
||||
}
|
||||
|
||||
function deleteVideoPlaylist (url: string, token: string, playlistId: number | string, statusCodeExpected = 204) {
|
||||
const path = '/api/v1/video-playlists/' + playlistId
|
||||
|
||||
@@ -93,13 +170,15 @@ function updateVideoPlaylist (options: {
|
||||
})
|
||||
}
|
||||
|
||||
function addVideoInPlaylist (options: {
|
||||
async function addVideoInPlaylist (options: {
|
||||
url: string,
|
||||
token: string,
|
||||
playlistId: number | string,
|
||||
elementAttrs: VideoPlaylistElementCreate
|
||||
elementAttrs: VideoPlaylistElementCreate | { videoId: string }
|
||||
expectedStatus?: number
|
||||
}) {
|
||||
options.elementAttrs.videoId = await videoUUIDToId(options.url, options.elementAttrs.videoId)
|
||||
|
||||
const path = '/api/v1/video-playlists/' + options.playlistId + '/videos'
|
||||
|
||||
return makePostBodyRequest({
|
||||
@@ -135,7 +214,7 @@ function removeVideoFromPlaylist (options: {
|
||||
token: string,
|
||||
playlistId: number | string,
|
||||
videoId: number | string,
|
||||
expectedStatus: number
|
||||
expectedStatus?: number
|
||||
}) {
|
||||
const path = '/api/v1/video-playlists/' + options.playlistId + '/videos/' + options.videoId
|
||||
|
||||
@@ -156,7 +235,7 @@ function reorderVideosPlaylist (options: {
|
||||
insertAfterPosition: number,
|
||||
reorderLength?: number
|
||||
},
|
||||
expectedStatus: number
|
||||
expectedStatus?: number
|
||||
}) {
|
||||
const path = '/api/v1/video-playlists/' + options.playlistId + '/videos/reorder'
|
||||
|
||||
@@ -165,15 +244,37 @@ function reorderVideosPlaylist (options: {
|
||||
path,
|
||||
token: options.token,
|
||||
fields: options.elementAttrs,
|
||||
statusCodeExpected: options.expectedStatus
|
||||
statusCodeExpected: options.expectedStatus || 204
|
||||
})
|
||||
}
|
||||
|
||||
async function checkPlaylistFilesWereRemoved (
|
||||
playlistUUID: string,
|
||||
serverNumber: number,
|
||||
directories = [ 'thumbnails' ]
|
||||
) {
|
||||
const testDirectory = 'test' + serverNumber
|
||||
|
||||
for (const directory of directories) {
|
||||
const directoryPath = join(root(), testDirectory, directory)
|
||||
|
||||
const files = await readdir(directoryPath)
|
||||
for (const file of files) {
|
||||
expect(file).to.not.contain(playlistUUID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
getVideoPlaylistsList,
|
||||
getVideoChannelPlaylistsList,
|
||||
getAccountPlaylistsList,
|
||||
getAccountPlaylistsListWithToken,
|
||||
|
||||
getVideoPlaylist,
|
||||
getVideoPlaylistWithToken,
|
||||
|
||||
createVideoPlaylist,
|
||||
updateVideoPlaylist,
|
||||
@@ -183,5 +284,7 @@ export {
|
||||
updateVideoPlaylistElement,
|
||||
removeVideoFromPlaylist,
|
||||
|
||||
reorderVideosPlaylist
|
||||
reorderVideosPlaylist,
|
||||
|
||||
checkPlaylistFilesWereRemoved
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* tslint:disable:no-unused-expression */
|
||||
|
||||
import { expect } from 'chai'
|
||||
import { existsSync, readdir, readFile } from 'fs-extra'
|
||||
import { pathExists, readdir, readFile } from 'fs-extra'
|
||||
import * as parseTorrent from 'parse-torrent'
|
||||
import { extname, join } from 'path'
|
||||
import * as request from 'supertest'
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
ServerInfo,
|
||||
testImage
|
||||
} from '../'
|
||||
|
||||
import * as validator from 'validator'
|
||||
import { VideoDetails, VideoPrivacy } from '../../models/videos'
|
||||
import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
|
||||
import { dateIsValid, webtorrentAdd } from '../miscs/miscs'
|
||||
@@ -311,8 +311,8 @@ async function checkVideoFilesWereRemoved (
|
||||
for (const directory of directories) {
|
||||
const directoryPath = join(root(), testDirectory, directory)
|
||||
|
||||
const directoryExists = existsSync(directoryPath)
|
||||
if (!directoryExists) continue
|
||||
const directoryExists = await pathExists(directoryPath)
|
||||
if (directoryExists === false) continue
|
||||
|
||||
const files = await readdir(directoryPath)
|
||||
for (const file of files) {
|
||||
@@ -597,12 +597,30 @@ async function completeVideoCheck (
|
||||
}
|
||||
}
|
||||
|
||||
async function videoUUIDToId (url: string, id: number | string) {
|
||||
if (validator.isUUID('' + id) === false) return id
|
||||
|
||||
const res = await getVideo(url, id)
|
||||
return res.body.id
|
||||
}
|
||||
|
||||
async function uploadVideoAndGetId (options: { server: ServerInfo, videoName: string, nsfw?: boolean, token?: string }) {
|
||||
const videoAttrs: any = { name: options.videoName }
|
||||
if (options.nsfw) videoAttrs.nsfw = options.nsfw
|
||||
|
||||
|
||||
const res = await uploadVideo(options.server.url, options.token || options.server.accessToken, videoAttrs)
|
||||
|
||||
return { id: res.body.video.id, uuid: res.body.video.uuid }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
getVideoDescription,
|
||||
getVideoCategories,
|
||||
getVideoLicences,
|
||||
videoUUIDToId,
|
||||
getVideoPrivacies,
|
||||
getVideoLanguages,
|
||||
getMyVideos,
|
||||
@@ -624,5 +642,6 @@ export {
|
||||
getLocalVideos,
|
||||
completeVideoCheck,
|
||||
checkVideoFilesWereRemoved,
|
||||
getPlaylistVideos
|
||||
getPlaylistVideos,
|
||||
uploadVideoAndGetId
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user