From 08c1efbe32244c321de28b0f2a6aaa3f99f46b58 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 26 Apr 2018 16:11:38 +0200 Subject: Add video channel management --- server/controllers/api/video-channel.ts | 2 +- server/lib/user.ts | 4 ++-- server/lib/video-channel.ts | 2 +- server/middlewares/validators/video-channels.ts | 4 ++-- server/tests/api/check-params/video-channels.ts | 14 +++++++------- server/tests/api/videos/multiple-servers.ts | 2 +- server/tests/api/videos/video-channels.ts | 4 ++-- server/tests/utils/videos/video-channels.ts | 15 +++++---------- 8 files changed, 21 insertions(+), 26 deletions(-) (limited to 'server') diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index 6241aaa5c..263eb2a8a 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts @@ -138,7 +138,7 @@ async function updateVideoChannel (req: express.Request, res: express.Response) transaction: t } - if (videoChannelInfoToUpdate.name !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.name) + if (videoChannelInfoToUpdate.displayName !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.displayName) if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description) if (videoChannelInfoToUpdate.support !== undefined) videoChannelInstance.set('support', videoChannelInfoToUpdate.support) diff --git a/server/lib/user.ts b/server/lib/user.ts index d019c4e71..51050de9b 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts @@ -17,9 +17,9 @@ async function createUserAccountAndChannel (userToCreate: UserModel, validateUse const userCreated = await userToCreate.save(userOptions) const accountCreated = await createLocalAccountWithoutKeys(userToCreate.username, userToCreate.id, null, t) - const videoChannelName = `Default ${userCreated.username} channel` + const videoChannelDisplayName = `Default ${userCreated.username} channel` const videoChannelInfo = { - name: videoChannelName + displayName: videoChannelDisplayName } const videoChannel = await createVideoChannel(videoChannelInfo, accountCreated, t) diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.ts index 9f7ed9297..600316cda 100644 --- a/server/lib/video-channel.ts +++ b/server/lib/video-channel.ts @@ -14,7 +14,7 @@ async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account const actorInstanceCreated = await actorInstance.save({ transaction: t }) const videoChannelData = { - name: videoChannelInfo.name, + name: videoChannelInfo.displayName, description: videoChannelInfo.description, support: videoChannelInfo.support, accountId: account.id, diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index a70f196df..3af20a1b4 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts @@ -27,7 +27,7 @@ const listVideoAccountChannelsValidator = [ ] const videoChannelsAddValidator = [ - body('name').custom(isVideoChannelNameValid).withMessage('Should have a valid name'), + body('displayName').custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), @@ -42,7 +42,7 @@ const videoChannelsAddValidator = [ const videoChannelsUpdateValidator = [ param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), - body('name').optional().custom(isVideoChannelNameValid).withMessage('Should have a valid name'), + body('displayName').optional().custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 7cda879ed..40a8e97cc 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -25,7 +25,7 @@ import { User } from '../../../../shared/models/users' const expect = chai.expect -describe('Test videos API validator', function () { +describe('Test video channels API validator', function () { const videoChannelPath = '/api/v1/video-channels' let server: ServerInfo let accessTokenUser: string @@ -85,7 +85,7 @@ describe('Test videos API validator', function () { describe('When adding a video channel', function () { const baseCorrectParams = { - name: 'hello', + displayName: 'hello', description: 'super description', support: 'super support text' } @@ -105,13 +105,13 @@ describe('Test videos API validator', function () { await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) - it('Should fail without name', async function () { - const fields = omit(baseCorrectParams, 'name') + it('Should fail without a name', async function () { + const fields = omit(baseCorrectParams, 'displayName') await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) }) + const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) @@ -138,7 +138,7 @@ describe('Test videos API validator', function () { describe('When updating a video channel', function () { const baseCorrectParams = { - name: 'hello', + displayName: 'hello', description: 'super description' } let path: string @@ -168,7 +168,7 @@ describe('Test videos API validator', function () { }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) }) + const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index e462a2d47..94d627e26 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -59,7 +59,7 @@ describe('Test multiple servers', function () { { const videoChannel = { - name: 'my channel', + displayName: 'my channel', description: 'super channel' } await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, videoChannel) diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index d24b8ab0b..585b6a2b5 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -59,7 +59,7 @@ describe('Test video channels', function () { this.timeout(10000) const videoChannel = { - name: 'second video channel', + displayName: 'second video channel', description: 'super video channel description', support: 'super video channel support text' } @@ -125,7 +125,7 @@ describe('Test video channels', function () { this.timeout(5000) const videoChannelAttributes = { - name: 'video channel updated', + displayName: 'video channel updated', description: 'video channel description updated', support: 'video channel support text updated' } diff --git a/server/tests/utils/videos/video-channels.ts b/server/tests/utils/videos/video-channels.ts index 978e21b19..021c4c420 100644 --- a/server/tests/utils/videos/video-channels.ts +++ b/server/tests/utils/videos/video-channels.ts @@ -1,10 +1,5 @@ import * as request from 'supertest' - -type VideoChannelAttributes = { - name?: string - description?: string - support?: string -} +import { VideoChannelCreate, VideoChannelUpdate } from '../../../../shared/models/videos' function getVideoChannelsList (url: string, start: number, count: number, sort?: string) { const path = '/api/v1/video-channels' @@ -34,14 +29,14 @@ function getAccountVideoChannelsList (url: string, accountId: number | string, s function addVideoChannel ( url: string, token: string, - videoChannelAttributesArg: VideoChannelAttributes, + videoChannelAttributesArg: VideoChannelCreate, expectedStatus = 200 ) { const path = '/api/v1/video-channels/' // Default attributes let attributes = { - name: 'my super video channel', + displayName: 'my super video channel', description: 'my super channel description', support: 'my super channel support' } @@ -59,13 +54,13 @@ function updateVideoChannel ( url: string, token: string, channelId: number | string, - attributes: VideoChannelAttributes, + attributes: VideoChannelUpdate, expectedStatus = 204 ) { const body = {} const path = '/api/v1/video-channels/' + channelId - if (attributes.name) body['name'] = attributes.name + if (attributes.displayName) body['displayName'] = attributes.displayName if (attributes.description) body['description'] = attributes.description if (attributes.support) body['support'] = attributes.support -- cgit v1.2.3