From 4bbfc6c606c8d3794bae25c64c516120af41f4eb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 29 Jun 2018 11:29:23 +0200 Subject: API: Add ability to update video channel avatar --- server/tests/api/check-params/users.ts | 14 +++++++ server/tests/api/check-params/video-channels.ts | 56 ++++++++++++++++++++++++- server/tests/api/videos/video-channels.ts | 34 ++++++++++++++- server/tests/utils/requests/requests.ts | 29 ++++++++++++- server/tests/utils/users/users.ts | 18 +------- server/tests/utils/videos/video-channels.ts | 14 +++++++ 6 files changed, 145 insertions(+), 20 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 28537315e..e1954c64f 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -304,6 +304,20 @@ describe('Test users API validators', function () { await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) }) + it('Should fail with an unauthenticated user', async function () { + const fields = {} + const attaches = { + 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') + } + await makeUploadRequest({ + url: server.url, + path: path + '/me/avatar/pick', + fields, + attaches, + statusCodeExpected: 401 + }) + }) + it('Should succeed with the correct params', async function () { const fields = {} const attaches = { diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 5080af2c9..7b05e5882 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -14,7 +14,7 @@ import { killallServers, makeGetRequest, makePostBodyRequest, - makePutBodyRequest, + makePutBodyRequest, makeUploadRequest, runServer, ServerInfo, setAccessTokensToServers, @@ -22,6 +22,7 @@ import { } from '../../utils' import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' import { User } from '../../../../shared/models/users' +import { join } from "path" const expect = chai.expect @@ -189,6 +190,59 @@ describe('Test video channels API validator', function () { }) }) + describe('When updating video channel avatar', function () { + let path: string + + before(async function () { + path = videoChannelPath + '/' + videoChannelUUID + }) + + it('Should fail with an incorrect input file', async function () { + const fields = {} + const attaches = { + 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') + } + await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches }) + }) + + it('Should fail with a big file', async function () { + const fields = {} + const attaches = { + 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') + } + await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches }) + }) + + it('Should fail with an unauthenticated user', async function () { + const fields = {} + const attaches = { + 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') + } + await makeUploadRequest({ + url: server.url, + path: path + '/avatar/pick', + fields, + attaches, + statusCodeExpected: 401 + }) + }) + + it('Should succeed with the correct params', async function () { + const fields = {} + const attaches = { + 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') + } + await makeUploadRequest({ + url: server.url, + path: path + '/avatar/pick', + token: server.accessToken, + fields, + attaches, + statusCodeExpected: 200 + }) + }) + }) + describe('When getting a video channel', function () { it('Should return the list of the video channels with nothing', async function () { const res = await makeGetRequest({ diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index ad543e2d6..e4e3ce9d9 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -3,7 +3,14 @@ import * as chai from 'chai' import 'mocha' import { User, Video } from '../../../../shared/index' -import { doubleFollow, flushAndRunMultipleServers, getVideoChannelVideos, updateVideo, uploadVideo } from '../../utils' +import { + doubleFollow, + flushAndRunMultipleServers, + getVideoChannelVideos, testImage, + updateVideo, + updateVideoChannelAvatar, + uploadVideo, wait +} from '../../utils' import { addVideoChannel, deleteVideoChannel, @@ -159,6 +166,31 @@ describe('Test video channels', function () { } }) + it('Should update video channel avatar', async function () { + this.timeout(5000) + + const fixture = 'avatar.png' + + await updateVideoChannelAvatar({ + url: servers[0].url, + accessToken: servers[0].accessToken, + videoChannelId: secondVideoChannelId, + fixture + }) + + await waitJobs(servers) + }) + + it('Should have video channel avatar updated', async function () { + for (const server of servers) { + const res = await getVideoChannelsList(server.url, 0, 1, '-name') + + const videoChannel = res.body.data.find(c => c.id === secondVideoChannelId) + + await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png') + } + }) + it('Should get video channel', async function () { const res = await getVideoChannel(servers[0].url, secondVideoChannelId) diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts index b6195089d..ebde692cd 100644 --- a/server/tests/utils/requests/requests.ts +++ b/server/tests/utils/requests/requests.ts @@ -1,5 +1,6 @@ import * as request from 'supertest' import { buildAbsoluteFixturePath } from '../miscs/miscs' +import { isAbsolute, join } from 'path' function makeGetRequest (options: { url: string, @@ -45,7 +46,7 @@ function makeUploadRequest (options: { url: string, method?: 'POST' | 'PUT', path: string, - token: string, + token?: string, fields: { [ fieldName: string ]: any }, attaches: { [ attachName: string ]: any }, statusCodeExpected?: number @@ -122,6 +123,29 @@ function makePutBodyRequest (options: { .expect(options.statusCodeExpected) } +function updateAvatarRequest (options: { + url: string, + path: string, + accessToken: string, + fixture: string +}) { + let filePath = '' + if (isAbsolute(options.fixture)) { + filePath = options.fixture + } else { + filePath = join(__dirname, '..', '..', 'fixtures', options.fixture) + } + + return makeUploadRequest({ + url: options.url, + path: options.path, + token: options.accessToken, + fields: {}, + attaches: { avatarfile: filePath }, + statusCodeExpected: 200 + }) +} + // --------------------------------------------------------------------------- export { @@ -129,5 +153,6 @@ export { makeUploadRequest, makePostBodyRequest, makePutBodyRequest, - makeDeleteRequest + makeDeleteRequest, + updateAvatarRequest } diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index 34d50f7ad..37b15f64a 100644 --- a/server/tests/utils/users/users.ts +++ b/server/tests/utils/users/users.ts @@ -1,6 +1,5 @@ -import { isAbsolute, join } from 'path' import * as request from 'supertest' -import { makePostBodyRequest, makeUploadRequest, makePutBodyRequest } from '../' +import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../' import { UserRole } from '../../../../shared/index' import { NSFWPolicyType } from '../../../../shared/models/videos/nsfw-policy.type' @@ -160,21 +159,8 @@ function updateMyAvatar (options: { fixture: string }) { const path = '/api/v1/users/me/avatar/pick' - let filePath = '' - if (isAbsolute(options.fixture)) { - filePath = options.fixture - } else { - filePath = join(__dirname, '..', '..', 'fixtures', options.fixture) - } - return makeUploadRequest({ - url: options.url, - path, - token: options.accessToken, - fields: {}, - attaches: { avatarfile: filePath }, - statusCodeExpected: 200 - }) + return updateAvatarRequest(Object.assign(options, { path })) } function updateUser (options: { diff --git a/server/tests/utils/videos/video-channels.ts b/server/tests/utils/videos/video-channels.ts index a064598f4..3ca39469c 100644 --- a/server/tests/utils/videos/video-channels.ts +++ b/server/tests/utils/videos/video-channels.ts @@ -1,5 +1,6 @@ import * as request from 'supertest' import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared/models/videos' +import { updateAvatarRequest } from '../index' function getVideoChannelsList (url: string, start: number, count: number, sort?: string) { const path = '/api/v1/video-channels' @@ -92,9 +93,22 @@ function getVideoChannel (url: string, channelId: number | string) { .expect('Content-Type', /json/) } +function updateVideoChannelAvatar (options: { + url: string, + accessToken: string, + fixture: string, + videoChannelId: string | number +}) { + + const path = '/api/v1/video-channels/' + options.videoChannelId + '/avatar/pick' + + return updateAvatarRequest(Object.assign(options, { path })) +} + // --------------------------------------------------------------------------- export { + updateVideoChannelAvatar, getVideoChannelsList, getAccountVideoChannelsList, addVideoChannel, -- cgit v1.2.3