From ac81d1a06d57b9ae86663831e7f5edcef57b0fa4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Feb 2018 18:17:05 +0100 Subject: Add ability to set video thumbnail/preview --- server/tests/api/check-params/users.ts | 8 +- server/tests/api/check-params/videos.ts | 150 +++++++++++++++++++++++----- server/tests/api/fixtures/preview.jpg | Bin 0 -> 4215 bytes server/tests/api/fixtures/thumbnail.jpg | Bin 0 -> 1457 bytes server/tests/api/videos/multiple-servers.ts | 16 ++- server/tests/utils/miscs/miscs.ts | 15 ++- server/tests/utils/requests/requests.ts | 19 ++-- server/tests/utils/users/users.ts | 4 +- server/tests/utils/videos/videos.ts | 83 ++++++++++----- 9 files changed, 230 insertions(+), 65 deletions(-) create mode 100644 server/tests/api/fixtures/preview.jpg create mode 100644 server/tests/api/fixtures/thumbnail.jpg (limited to 'server/tests') diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 0fbc414c9..d9dea0713 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -7,7 +7,7 @@ import { UserRole } from '../../../../shared' import { createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest, - makePostBodyRequest, makePostUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers, + makePostBodyRequest, makeUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers, updateUser, uploadVideo, userLogin } from '../../utils' import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' @@ -273,7 +273,7 @@ describe('Test users API validators', function () { const attaches = { 'avatarfile': join(__dirname, '..', 'fixtures', 'video_short.mp4') } - await makePostUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) }) it('Should fail with a big file', async function () { @@ -281,7 +281,7 @@ describe('Test users API validators', function () { const attaches = { 'avatarfile': join(__dirname, '..', 'fixtures', 'avatar-big.png') } - await makePostUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) }) it('Should succeed with the correct params', async function () { @@ -289,7 +289,7 @@ describe('Test users API validators', function () { const attaches = { 'avatarfile': join(__dirname, '..', 'fixtures', 'avatar.png') } - await makePostUploadRequest({ + await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index f25e3f595..aa30b721b 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -7,7 +7,7 @@ import { join } from 'path' import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' import { createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest, - makeGetRequest, makePostUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin + makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin } from '../../utils' import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' @@ -111,91 +111,91 @@ describe('Test videos API validator', function () { it('Should fail with nothing', async function () { const fields = {} const attaches = {} - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail without name', async function () { const fields = omit(baseCorrectParams, 'name') const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a long name', async function () { const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a bad category', async function () { const fields = immutableAssign(baseCorrectParams, { category: 125 }) const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a bad licence', async function () { const fields = immutableAssign(baseCorrectParams, { licence: 125 }) const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a bad language', async function () { const fields = immutableAssign(baseCorrectParams, { language: 125 }) const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail without nsfw attribute', async function () { const fields = omit(baseCorrectParams, 'nsfw') const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a bad nsfw attribute', async function () { const fields = immutableAssign(baseCorrectParams, { nsfw: 2 }) const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail without commentsEnabled attribute', async function () { const fields = omit(baseCorrectParams, 'commentsEnabled') const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a bad commentsEnabled attribute', async function () { const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 }) const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a long description', async function () { const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) }) const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail without a channel', async function () { const fields = omit(baseCorrectParams, 'channelId') const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a bad channel', async function () { const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with another user channel', async function () { @@ -212,34 +212,34 @@ describe('Test videos API validator', function () { const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with too many tags', async function () { const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a tag length too low', async function () { const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail with a tag length too big', async function () { const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) const attaches = baseCorrectAttaches - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail without an input file', async function () { const fields = baseCorrectParams const attaches = {} - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should fail without an incorrect input file', async function () { @@ -247,7 +247,47 @@ describe('Test videos API validator', function () { const attaches = { 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') } - await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + }) + + it('Should fail with an incorrect thumbnail file', async function () { + const fields = baseCorrectParams + const attaches = { + 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar.png'), + 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') + } + + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + }) + + it('Should fail with a big thumbnail file', async function () { + const fields = baseCorrectParams + const attaches = { + 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar-big.png'), + 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') + } + + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + }) + + it('Should fail with an incorrect preview file', async function () { + const fields = baseCorrectParams + const attaches = { + 'previewfile': join(__dirname, '..', 'fixtures', 'avatar.png'), + 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') + } + + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) + }) + + it('Should fail with a big preview file', async function () { + const fields = baseCorrectParams + const attaches = { + 'previewfile': join(__dirname, '..', 'fixtures', 'avatar-big.png'), + 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') + } + + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) }) it('Should succeed with the correct parameters', async function () { @@ -257,7 +297,7 @@ describe('Test videos API validator', function () { { const attaches = baseCorrectAttaches - await makePostUploadRequest({ + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, @@ -272,7 +312,7 @@ describe('Test videos API validator', function () { videofile: join(__dirname, '..', 'fixtures', 'video_short.mp4') }) - await makePostUploadRequest({ + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, @@ -287,7 +327,7 @@ describe('Test videos API validator', function () { videofile: join(__dirname, '..', 'fixtures', 'video_short.ogv') }) - await makePostUploadRequest({ + await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, @@ -400,6 +440,70 @@ describe('Test videos API validator', function () { await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) }) + it('Should fail with an incorrect thumbnail file', async function () { + const fields = baseCorrectParams + const attaches = { + 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar.png') + } + + await makeUploadRequest({ + url: server.url, + method: 'PUT', + path: path + videoId, + token: server.accessToken, + fields, + attaches + }) + }) + + it('Should fail with a big thumbnail file', async function () { + const fields = baseCorrectParams + const attaches = { + 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar-big.png') + } + + await makeUploadRequest({ + url: server.url, + method: 'PUT', + path: path + videoId, + token: server.accessToken, + fields, + attaches + }) + }) + + it('Should fail with an incorrect preview file', async function () { + const fields = baseCorrectParams + const attaches = { + 'previewfile': join(__dirname, '..', 'fixtures', 'avatar.png') + } + + await makeUploadRequest({ + url: server.url, + method: 'PUT', + path: path + videoId, + token: server.accessToken, + fields, + attaches + }) + }) + + it('Should fail with a big preview file', async function () { + const fields = baseCorrectParams + const attaches = { + 'previewfile': join(__dirname, '..', 'fixtures', 'avatar-big.png') + } + + await makeUploadRequest({ + url: server.url, + method: 'PUT', + path: path + videoId, + token: server.accessToken, + fields, + attaches + }) + }) + it('Should fail with a video of another user') it('Should fail with a video of another server') diff --git a/server/tests/api/fixtures/preview.jpg b/server/tests/api/fixtures/preview.jpg new file mode 100644 index 000000000..c40ece838 Binary files /dev/null and b/server/tests/api/fixtures/preview.jpg differ diff --git a/server/tests/api/fixtures/thumbnail.jpg b/server/tests/api/fixtures/thumbnail.jpg new file mode 100644 index 000000000..cc3af8a4a Binary files /dev/null and b/server/tests/api/fixtures/thumbnail.jpg differ diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 0215b3011..3646fbb0f 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -137,7 +137,9 @@ describe('Test multiple servers', function () { nsfw: true, description: 'my super description for server 2', tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], - fixture: 'video_short2.webm' + fixture: 'video_short2.webm', + thumbnailfile: 'thumbnail.jpg', + previewfile: 'preview.jpg' } await uploadVideo(servers[1].url, userAccessToken, videoAttributes) @@ -184,7 +186,9 @@ describe('Test multiple servers', function () { resolution: 720, size: 710000 } - ] + ], + thumbnailfile: 'thumbnail', + previewfile: 'preview' } const res = await getVideosList(server.url) @@ -521,7 +525,9 @@ describe('Test multiple servers', function () { language: 13, nsfw: true, description: 'my super description updated', - tags: [ 'tag_up_1', 'tag_up_2' ] + tags: [ 'tag_up_1', 'tag_up_2' ], + thumbnailfile: 'thumbnail.jpg', + previewfile: 'preview.jpg' } await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) @@ -565,7 +571,9 @@ describe('Test multiple servers', function () { resolution: 720, size: 292677 } - ] + ], + thumbnailfile: 'thumbnail', + previewfile: 'preview' } await completeVideoCheck(server.url, videoUpdated, checkAttributes) } diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts index 99d109bfe..24cbf59ca 100644 --- a/server/tests/utils/miscs/miscs.ts +++ b/server/tests/utils/miscs/miscs.ts @@ -1,6 +1,6 @@ /* tslint:disable:no-unused-expression */ -import { join } from 'path' +import { isAbsolute, join } from 'path' import * as request from 'supertest' import * as WebTorrent from 'webtorrent' import { readFileBufferPromise } from '../../../helpers/core-utils' @@ -45,8 +45,8 @@ async function testImage (url: string, imageName: string, imagePath: string, ext const body = res.body const data = await readFileBufferPromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension)) - const minLength = body.length - ((50 * body.length) / 100) - const maxLength = body.length + ((50 * body.length) / 100) + const minLength = body.length - ((20 * body.length) / 100) + const maxLength = body.length + ((20 * body.length) / 100) return data.length > minLength && data.length < maxLength } else { @@ -55,6 +55,14 @@ async function testImage (url: string, imageName: string, imagePath: string, ext } } +function buildAbsoluteFixturePath (path: string) { + if (isAbsolute(path)) { + return path + } + + return join(__dirname, '..', '..', 'api', 'fixtures', path) +} + // --------------------------------------------------------------------------- export { @@ -63,5 +71,6 @@ export { webtorrentAdd, immutableAssign, testImage, + buildAbsoluteFixturePath, root } diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts index 840072430..a9b1dff9a 100644 --- a/server/tests/utils/requests/requests.ts +++ b/server/tests/utils/requests/requests.ts @@ -1,4 +1,5 @@ import * as request from 'supertest' +import { buildAbsoluteFixturePath } from '../' function makeGetRequest (options: { url: string, @@ -40,8 +41,9 @@ function makeDeleteRequest (options: { .expect(options.statusCodeExpected) } -function makePostUploadRequest (options: { +function makeUploadRequest (options: { url: string, + method?: 'POST' | 'PUT', path: string, token: string, fields: { [ fieldName: string ]: any }, @@ -50,9 +52,14 @@ function makePostUploadRequest (options: { }) { if (!options.statusCodeExpected) options.statusCodeExpected = 400 - const req = request(options.url) - .post(options.path) - .set('Accept', 'application/json') + let req: request.Test + if (options.method === 'PUT') { + req = request(options.url).put(options.path) + } else { + req = request(options.url).post(options.path) + } + + req.set('Accept', 'application/json') if (options.token) req.set('Authorization', 'Bearer ' + options.token) @@ -70,7 +77,7 @@ function makePostUploadRequest (options: { Object.keys(options.attaches).forEach(attach => { const value = options.attaches[attach] - req.attach(attach, value) + req.attach(attach, buildAbsoluteFixturePath(value)) }) return req.expect(options.statusCodeExpected) @@ -119,7 +126,7 @@ function makePutBodyRequest (options: { export { makeGetRequest, - makePostUploadRequest, + makeUploadRequest, makePostBodyRequest, makePutBodyRequest, makeDeleteRequest diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index 9e33e6796..3c9d46246 100644 --- a/server/tests/utils/users/users.ts +++ b/server/tests/utils/users/users.ts @@ -1,6 +1,6 @@ import { isAbsolute, join } from 'path' import * as request from 'supertest' -import { makePostBodyRequest, makePostUploadRequest, makePutBodyRequest } from '../' +import { makePostBodyRequest, makeUploadRequest, makePutBodyRequest } from '../' import { UserRole } from '../../../../shared/index' @@ -162,7 +162,7 @@ function updateMyAvatar (options: { filePath = join(__dirname, '..', '..', 'api', 'fixtures', options.fixture) } - return makePostUploadRequest({ + return makeUploadRequest({ url: options.url, path, token: options.accessToken, diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index 9105b5f13..9d4267db8 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts @@ -5,7 +5,16 @@ import { existsSync, readFile } from 'fs' import * as parseTorrent from 'parse-torrent' import { extname, isAbsolute, join } from 'path' import * as request from 'supertest' -import { getMyUserInformation, makeGetRequest, root, ServerInfo, testImage } from '../' +import { + buildAbsoluteFixturePath, + getMyUserInformation, + makeGetRequest, + makePutBodyRequest, + makeUploadRequest, + root, + ServerInfo, + testImage +} from '../' import { VideoPrivacy } from '../../../../shared/models/videos' import { readdirPromise } from '../../../helpers/core-utils' import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' @@ -23,6 +32,8 @@ type VideoAttributes = { channelId?: number privacy?: VideoPrivacy fixture?: string + thumbnailfile?: string + previewfile?: string } function getVideoCategories (url: string) { @@ -228,8 +239,8 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg defaultChannelId = res.body.videoChannels[0].id } catch (e) { /* empty */ } - // Default attributes - let attributes = { + // Override default attributes + const attributes = Object.assign({ name: 'my super video', category: 5, licence: 4, @@ -241,8 +252,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg privacy: VideoPrivacy.PUBLIC, commentsEnabled: true, fixture: 'video_short.webm' - } - attributes = Object.assign(attributes, videoAttributesArg) + }, videoAttributesArg) const req = request(url) .post(path) @@ -267,22 +277,22 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg req.field('licence', attributes.licence.toString()) } - for (let i = 0; i < attributes.tags.length; i++) { - req.field('tags[' + i + ']', attributes.tags[i]) + if (attributes.thumbnailfile !== undefined) { + req.attach('thumbnailfile', buildAbsoluteFixturePath(attributes.thumbnailfile)) + } + if (attributes.previewfile !== undefined) { + req.attach('previewfile', buildAbsoluteFixturePath(attributes.previewfile)) } - let filePath = '' - if (isAbsolute(attributes.fixture)) { - filePath = attributes.fixture - } else { - filePath = join(__dirname, '..', '..', 'api', 'fixtures', attributes.fixture) + for (let i = 0; i < attributes.tags.length; i++) { + req.field('tags[' + i + ']', attributes.tags[i]) } - return req.attach('videofile', filePath) + return req.attach('videofile', buildAbsoluteFixturePath(attributes.fixture)) .expect(specialStatus) } -function updateVideo (url: string, accessToken: string, id: number | string, attributes: VideoAttributes, specialStatus = 204) { +function updateVideo (url: string, accessToken: string, id: number | string, attributes: VideoAttributes, statusCodeExpected = 204) { const path = '/api/v1/videos/' + id const body = {} @@ -296,12 +306,30 @@ function updateVideo (url: string, accessToken: string, id: number | string, att if (attributes.tags) body['tags'] = attributes.tags if (attributes.privacy) body['privacy'] = attributes.privacy - return request(url) - .put(path) - .send(body) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + accessToken) - .expect(specialStatus) + // Upload request + if (attributes.thumbnailfile || attributes.previewfile) { + const attaches: any = {} + if (attributes.thumbnailfile) attaches.thumbnailfile = attributes.thumbnailfile + if (attributes.previewfile) attaches.previewfile = attributes.previewfile + + return makeUploadRequest({ + url, + method: 'PUT', + path, + token: accessToken, + fields: body, + attaches, + statusCodeExpected + }) + } + + return makePutBodyRequest({ + url, + path, + fields: body, + token: accessToken, + statusCodeExpected + }) } function rateVideo (url: string, accessToken: string, id: number, rating: string, specialStatus = 204) { @@ -355,7 +383,9 @@ async function completeVideoCheck ( files: { resolution: number size: number - }[] + }[], + thumbnailfile?: string + previewfile?: string } ) { if (!attributes.likes) attributes.likes = 0 @@ -414,8 +444,15 @@ async function completeVideoCheck ( const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100) expect(file.size).to.be.above(minSize).and.below(maxSize) - const test = await testImage(url, attributes.fixture, videoDetails.thumbnailPath) - expect(test).to.equal(true) + { + const test = await testImage(url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath) + expect(test).to.equal(true) + } + + if (attributes.previewfile) { + const test = await testImage(url, attributes.previewfile, videoDetails.previewPath) + expect(test).to.equal(true) + } const torrent = await webtorrentAdd(magnetUri, true) expect(torrent.files).to.be.an('array') -- cgit v1.2.3