Verified Commit a5461888 authored by Chocobozzz's avatar Chocobozzz
Browse files

Introduce channels command

parent 57f879a5
...@@ -5,7 +5,6 @@ import { omit } from 'lodash' ...@@ -5,7 +5,6 @@ import { omit } from 'lodash'
import { User, UserRole, VideoCreateResult } from '../../../../shared' import { User, UserRole, VideoCreateResult } from '../../../../shared'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
addVideoChannel,
blockUser, blockUser,
buildAbsoluteFixturePath, buildAbsoluteFixturePath,
cleanupTests, cleanupTests,
...@@ -1041,8 +1040,8 @@ describe('Test users API validators', function () { ...@@ -1041,8 +1040,8 @@ describe('Test users API validators', function () {
}) })
it('Should fail with an existing channel', async function () { it('Should fail with an existing channel', async function () {
const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' } const attributes = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg) await server.channelsCommand.create({ attributes })
const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } }) const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } })
......
...@@ -6,11 +6,10 @@ import { omit } from 'lodash' ...@@ -6,11 +6,10 @@ import { omit } from 'lodash'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
buildAbsoluteFixturePath, buildAbsoluteFixturePath,
ChannelsCommand,
cleanupTests, cleanupTests,
createUser, createUser,
deleteVideoChannel,
flushAndRunServer, flushAndRunServer,
getAccountVideoChannelsList,
immutableAssign, immutableAssign,
makeGetRequest, makeGetRequest,
makePostBodyRequest, makePostBodyRequest,
...@@ -33,6 +32,7 @@ describe('Test video channels API validator', function () { ...@@ -33,6 +32,7 @@ describe('Test video channels API validator', function () {
const videoChannelPath = '/api/v1/video-channels' const videoChannelPath = '/api/v1/video-channels'
let server: ServerInfo let server: ServerInfo
let accessTokenUser: string let accessTokenUser: string
let command: ChannelsCommand
// --------------------------------------------------------------- // ---------------------------------------------------------------
...@@ -52,6 +52,8 @@ describe('Test video channels API validator', function () { ...@@ -52,6 +52,8 @@ describe('Test video channels API validator', function () {
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
accessTokenUser = await userLogin(server, user) accessTokenUser = await userLogin(server, user)
} }
command = server.channelsCommand
}) })
describe('When listing a video channels', function () { describe('When listing a video channels', function () {
...@@ -84,7 +86,7 @@ describe('Test video channels API validator', function () { ...@@ -84,7 +86,7 @@ describe('Test video channels API validator', function () {
}) })
it('Should fail with a unknown account', async function () { it('Should fail with a unknown account', async function () {
await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: HttpStatusCode.NOT_FOUND_404 }) await server.channelsCommand.listByAccount({ accountName: 'unknown', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
}) })
it('Should succeed with the correct parameters', async function () { it('Should succeed with the correct parameters', async function () {
...@@ -327,23 +329,23 @@ describe('Test video channels API validator', function () { ...@@ -327,23 +329,23 @@ describe('Test video channels API validator', function () {
describe('When deleting a video channel', function () { describe('When deleting a video channel', function () {
it('Should fail with a non authenticated user', async function () { it('Should fail with a non authenticated user', async function () {
await deleteVideoChannel(server.url, 'coucou', 'super_channel', HttpStatusCode.UNAUTHORIZED_401) await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should fail with another authenticated user', async function () { it('Should fail with another authenticated user', async function () {
await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', HttpStatusCode.FORBIDDEN_403) await command.delete({ token: accessTokenUser, channelName: 'super_channel', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
}) })
it('Should fail with an unknown video channel id', async function () { it('Should fail with an unknown video channel id', async function () {
await deleteVideoChannel(server.url, server.accessToken, 'super_channel2', HttpStatusCode.NOT_FOUND_404) await command.delete({ channelName: 'super_channel2', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
}) })
it('Should succeed with the correct parameters', async function () { it('Should succeed with the correct parameters', async function () {
await deleteVideoChannel(server.url, server.accessToken, 'super_channel') await command.delete({ channelName: 'super_channel' })
}) })
it('Should fail to delete the last user video channel', async function () { it('Should fail to delete the last user video channel', async function () {
await deleteVideoChannel(server.url, server.accessToken, 'root_channel', HttpStatusCode.CONFLICT_409) await command.delete({ channelName: 'root_channel', expectedStatus: HttpStatusCode.CONFLICT_409 })
}) })
}) })
......
...@@ -17,7 +17,6 @@ import { ...@@ -17,7 +17,6 @@ import {
ServerInfo, ServerInfo,
updateMyUser, updateMyUser,
updateVideo, updateVideo,
updateVideoChannel,
uploadRandomVideoOnServers, uploadRandomVideoOnServers,
wait, wait,
waitJobs waitJobs
...@@ -404,7 +403,11 @@ describe('Test user notifications', function () { ...@@ -404,7 +403,11 @@ describe('Test user notifications', function () {
displayName: 'super root 2 name' displayName: 'super root 2 name'
}) })
await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName }) await servers[0].channelsCommand.update({
token: userAccessToken,
channelName: 'user_1_channel',
attributes: { displayName: myChannelName }
})
}) })
it('Should notify when a local channel is following one of our channel', async function () { it('Should notify when a local channel is following one of our channel', async function () {
......
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha' import 'mocha'
import { expect } from 'chai'
import { import {
cleanupTests, cleanupTests,
flushAndRunServer, flushAndRunServer,
...@@ -15,8 +16,6 @@ import { ...@@ -15,8 +16,6 @@ import {
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { VideoPrivacy } from '@shared/models' import { VideoPrivacy } from '@shared/models'
const expect = chai.expect
describe('Test redundancy constraints', function () { describe('Test redundancy constraints', function () {
let remoteServer: ServerInfo let remoteServer: ServerInfo
let localServer: ServerInfo let localServer: ServerInfo
......
...@@ -3,19 +3,15 @@ ...@@ -3,19 +3,15 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import {
addVideoChannel,
cleanupTests, cleanupTests,
createUser, createUser,
deleteVideoChannel,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideoChannelsList,
getVideoChannelVideos, getVideoChannelVideos,
SearchCommand, SearchCommand,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
updateMyUser, updateMyUser,
updateVideo, updateVideo,
updateVideoChannel,
uploadVideo, uploadVideo,
userLogin, userLogin,
wait, wait,
...@@ -45,7 +41,7 @@ describe('Test ActivityPub video channels search', function () { ...@@ -45,7 +41,7 @@ describe('Test ActivityPub video channels search', function () {
name: 'channel1_server1', name: 'channel1_server1',
displayName: 'Channel 1 server 1' displayName: 'Channel 1 server 1'
} }
await addVideoChannel(servers[0].url, servers[0].accessToken, channel) await servers[0].channelsCommand.create({ attributes: channel })
} }
{ {
...@@ -57,8 +53,8 @@ describe('Test ActivityPub video channels search', function () { ...@@ -57,8 +53,8 @@ describe('Test ActivityPub video channels search', function () {
name: 'channel1_server2', name: 'channel1_server2',
displayName: 'Channel 1 server 2' displayName: 'Channel 1 server 2'
} }
const resChannel = await addVideoChannel(servers[1].url, userServer2Token, channel) const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel })
channelIdServer2 = resChannel.body.videoChannel.id channelIdServer2 = created.id
const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 }) const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 })
videoServer2UUID = res.body.video.uuid videoServer2UUID = res.body.video.uuid
...@@ -143,12 +139,12 @@ describe('Test ActivityPub video channels search', function () { ...@@ -143,12 +139,12 @@ describe('Test ActivityPub video channels search', function () {
}) })
it('Should not list this remote video channel', async function () { it('Should not list this remote video channel', async function () {
const res = await getVideoChannelsList(servers[0].url, 0, 5) const body = await servers[0].channelsCommand.list()
expect(res.body.total).to.equal(3) expect(body.total).to.equal(3)
expect(res.body.data).to.have.lengthOf(3) expect(body.data).to.have.lengthOf(3)
expect(res.body.data[0].name).to.equal('channel1_server1') expect(body.data[0].name).to.equal('channel1_server1')
expect(res.body.data[1].name).to.equal('user1_server1_channel') expect(body.data[1].name).to.equal('user1_server1_channel')
expect(res.body.data[2].name).to.equal('root_channel') expect(body.data[2].name).to.equal('root_channel')
}) })
it('Should list video channel videos of server 2 without token', async function () { it('Should list video channel videos of server 2 without token', async function () {
...@@ -171,7 +167,11 @@ describe('Test ActivityPub video channels search', function () { ...@@ -171,7 +167,11 @@ describe('Test ActivityPub video channels search', function () {
it('Should update video channel of server 2, and refresh it on server 1', async function () { it('Should update video channel of server 2, and refresh it on server 1', async function () {
this.timeout(60000) this.timeout(60000)
await updateVideoChannel(servers[1].url, userServer2Token, 'channel1_server2', { displayName: 'channel updated' }) await servers[1].channelsCommand.update({
token: userServer2Token,
channelName: 'channel1_server2',
attributes: { displayName: 'channel updated' }
})
await updateMyUser({ url: servers[1].url, accessToken: userServer2Token, displayName: 'user updated' }) await updateMyUser({ url: servers[1].url, accessToken: userServer2Token, displayName: 'user updated' })
await waitJobs(servers) await waitJobs(servers)
...@@ -217,7 +217,7 @@ describe('Test ActivityPub video channels search', function () { ...@@ -217,7 +217,7 @@ describe('Test ActivityPub video channels search', function () {
it('Should delete video channel of server 2, and delete it on server 1', async function () { it('Should delete video channel of server 2, and delete it on server 1', async function () {
this.timeout(60000) this.timeout(60000)
await deleteVideoChannel(servers[1].url, userServer2Token, 'channel1_server2') await servers[1].channelsCommand.delete({ token: userServer2Token, channelName: 'channel1_server2' })
await waitJobs(servers) await waitJobs(servers)
// Expire video // Expire video
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import {
addVideoChannel,
cleanupTests, cleanupTests,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getVideosList, getVideosList,
...@@ -123,8 +122,8 @@ describe('Test ActivityPub videos search', function () { ...@@ -123,8 +122,8 @@ describe('Test ActivityPub videos search', function () {
name: 'super_channel', name: 'super_channel',
displayName: 'super channel' displayName: 'super channel'
} }
const resChannel = await addVideoChannel(servers[1].url, servers[1].accessToken, channelAttributes) const created = await servers[1].channelsCommand.create({ attributes: channelAttributes })
const videoChannelId = resChannel.body.videoChannel.id const videoChannelId = created.id
const attributes = { const attributes = {
name: 'updated', name: 'updated',
......
...@@ -2,15 +2,7 @@ ...@@ -2,15 +2,7 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import { cleanupTests, createUser, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
addVideoChannel,
cleanupTests,
createUser,
flushAndRunServer,
SearchCommand,
ServerInfo,
setAccessTokensToServers
} from '@shared/extra-utils'
import { VideoChannel } from '@shared/models' import { VideoChannel } from '@shared/models'
const expect = chai.expect const expect = chai.expect
...@@ -32,7 +24,7 @@ describe('Test channels search', function () { ...@@ -32,7 +24,7 @@ describe('Test channels search', function () {
name: 'squall_channel', name: 'squall_channel',
displayName: 'Squall channel' displayName: 'Squall channel'
} }
await addVideoChannel(server.url, server.accessToken, channel) await server.channelsCommand.create({ attributes: channel })
} }
command = server.searchCommand command = server.searchCommand
......
...@@ -37,6 +37,8 @@ describe('Test plugins', function () { ...@@ -37,6 +37,8 @@ describe('Test plugins', function () {
} }
server = await flushAndRunServer(1, configOverride) server = await flushAndRunServer(1, configOverride)
await setAccessTokensToServers([ server ]) await setAccessTokensToServers([ server ])
command = server.pluginsCommand
}) })
it('Should list and search available plugins and themes', async function () { it('Should list and search available plugins and themes', async function () {
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
import 'mocha' import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { import {
addVideoChannel,
addVideoCommentThread, addVideoCommentThread,
cleanupTests, cleanupTests,
createUser, createUser,
...@@ -143,12 +142,12 @@ describe('Test stats (excluding redundancy)', function () { ...@@ -143,12 +142,12 @@ describe('Test stats (excluding redundancy)', function () {
} }
{ {
const channelAttributes = { const attributes = {
name: 'stats_channel', name: 'stats_channel',
displayName: 'My stats channel' displayName: 'My stats channel'
} }
const resChannel = await addVideoChannel(server.url, server.accessToken, channelAttributes) const created = await server.channelsCommand.create({ attributes })
channelId = resChannel.body.videoChannel.id channelId = created.id
const data = await server.statsCommand.get() const data = await server.statsCommand.get()
......
...@@ -12,7 +12,6 @@ import { ...@@ -12,7 +12,6 @@ import {
flushAndRunMultipleServers, flushAndRunMultipleServers,
getAccountVideos, getAccountVideos,
getMyUserInformation, getMyUserInformation,
getVideoChannelsList,
removeUser, removeUser,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
...@@ -23,7 +22,7 @@ import { ...@@ -23,7 +22,7 @@ import {
userLogin, userLogin,
waitJobs waitJobs
} from '@shared/extra-utils' } from '@shared/extra-utils'
import { User, VideoChannel } from '@shared/models' import { User } from '@shared/models'
const expect = chai.expect const expect = chai.expect
...@@ -199,10 +198,8 @@ describe('Test users with multiple servers', function () { ...@@ -199,10 +198,8 @@ describe('Test users with multiple servers', function () {
const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
expect(accountDeleted).not.to.be.undefined expect(accountDeleted).not.to.be.undefined
const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) const { data } = await server.channelsCommand.list()
const videoChannelDeleted = resVideoChannels.body.data.find(a => { const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
return a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port
}) as VideoChannel
expect(videoChannelDeleted).not.to.be.undefined expect(videoChannelDeleted).not.to.be.undefined
} }
...@@ -216,10 +213,8 @@ describe('Test users with multiple servers', function () { ...@@ -216,10 +213,8 @@ describe('Test users with multiple servers', function () {
const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
expect(accountDeleted).to.be.undefined expect(accountDeleted).to.be.undefined
const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) const { data } = await server.channelsCommand.list()
const videoChannelDeleted = resVideoChannels.body.data.find(a => { const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
return a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port
}) as VideoChannel
expect(videoChannelDeleted).to.be.undefined expect(videoChannelDeleted).to.be.undefined
} }
}) })
......
...@@ -18,7 +18,6 @@ import { ...@@ -18,7 +18,6 @@ import {
getUserInformation, getUserInformation,
getUsersList, getUsersList,
getUsersListPaginationAndSort, getUsersListPaginationAndSort,
getVideoChannel,
getVideosList, getVideosList,
killallServers, killallServers,
login, login,
...@@ -864,9 +863,9 @@ describe('Test users', function () { ...@@ -864,9 +863,9 @@ describe('Test users', function () {
}) })
it('Should have created the channel', async function () { it('Should have created the channel', async function () {
const res = await getVideoChannel(server.url, 'my_user_15_channel') const { displayName } = await server.channelsCommand.get({ channelName: 'my_user_15_channel' })
expect(res.body.displayName).to.equal('my channel rocks') expect(displayName).to.equal('my channel rocks')
}) })
it('Should remove me', async function () { it('Should remove me', async function () {
......
...@@ -5,7 +5,6 @@ import * as chai from 'chai' ...@@ -5,7 +5,6 @@ import * as chai from 'chai'
import * as request from 'supertest' import * as request from 'supertest'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
addVideoChannel,
buildAbsoluteFixturePath, buildAbsoluteFixturePath,
checkTmpIsEmpty, checkTmpIsEmpty,
checkVideoFilesWereRemoved, checkVideoFilesWereRemoved,
...@@ -17,7 +16,6 @@ import { ...@@ -17,7 +16,6 @@ import {
flushAndRunMultipleServers, flushAndRunMultipleServers,
getLocalVideos, getLocalVideos,
getVideo, getVideo,
getVideoChannelsList,
getVideosList, getVideosList,
rateVideo, rateVideo,
removeVideo, removeVideo,
...@@ -64,9 +62,9 @@ describe('Test multiple servers', function () { ...@@ -64,9 +62,9 @@ describe('Test multiple servers', function () {
displayName: 'my channel', displayName: 'my channel',
description: 'super channel' description: 'super channel'
} }
await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) await servers[0].channelsCommand.create({ attributes: videoChannel })
const channelRes = await getVideoChannelsList(servers[0].url, 0, 1) const { data } = await servers[0].channelsCommand.list({ start: 0, count: 1 })
videoChannelId = channelRes.body.data[0].id videoChannelId = data[0].id
} }
// Server 1 and server 2 follow each other // Server 1 and server 2 follow each other
......
...@@ -7,43 +7,29 @@ import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' ...@@ -7,43 +7,29 @@ import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
import { import {
cleanupTests, cleanupTests,
createUser, createUser,
deleteVideoChannelImage,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getActorImage, getActorImage,
getVideo, getVideo,
getVideoChannel,
getVideoChannelVideos, getVideoChannelVideos,
setDefaultVideoChannel, setDefaultVideoChannel,