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/utils/requests/requests.ts | 29 +++++++++++++++++++++++++++-- server/tests/utils/users/users.ts | 18 ++---------------- server/tests/utils/videos/video-channels.ts | 14 ++++++++++++++ 3 files changed, 43 insertions(+), 18 deletions(-) (limited to 'server/tests/utils') 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