accountNameWithHostGetValidator,
accountsSortValidator,
ensureAuthUserOwnsAccountValidator,
- videosSortValidator
+ videosSortValidator,
+ videoChannelsSortValidator
} from '../../middlewares/validators'
import { AccountModel } from '../../models/account/account'
import { AccountVideoRateModel } from '../../models/account/account-video-rate'
accountsRouter.get('/:accountName/video-channels',
asyncMiddleware(accountNameWithHostGetValidator),
+ paginationValidator,
+ videoChannelsSortValidator,
+ setDefaultSort,
+ setDefaultPagination,
asyncMiddleware(listAccountChannels)
)
}
async function listAccountChannels (req: express.Request, res: express.Response) {
- const resultList = await VideoChannelModel.listByAccount(res.locals.account.id)
+ const options = {
+ accountId: res.locals.account.id,
+ start: req.query.start,
+ count: req.query.count,
+ sort: req.query.sort,
+ }
+
+ const resultList = await VideoChannelModel.listByAccount(options)
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
})
}
- static listByAccount (accountId: number) {
+ static listByAccount (options: {
+ accountId: number,
+ start: number,
+ count: number,
+ sort: string
+ }) {
const query = {
- order: getSort('createdAt'),
+ offset: options.start,
+ limit: options.count,
+ order: getSort(options.sort),
include: [
{
model: AccountModel,
where: {
- id: accountId
+ id: options.accountId
},
required: true
}
})
describe('When listing account video channels', function () {
+ const accountChannelPath = '/api/v1/accounts/fake/video-channels'
+
+ it('Should fail with a bad start pagination', async function () {
+ await checkBadStartPagination(server.url, accountChannelPath, server.accessToken)
+ })
+
+ it('Should fail with a bad count pagination', async function () {
+ await checkBadCountPagination(server.url, accountChannelPath, server.accessToken)
+ })
+
+ it('Should fail with an incorrect sort', async function () {
+ await checkBadSortPagination(server.url, accountChannelPath, server.accessToken)
+ })
+
it('Should fail with a unknown account', async function () {
- await getAccountVideoChannelsList(server.url, 'unknown', 404)
+ await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: 404 })
+ })
+
+ it('Should succeed with the correct parameters', async function () {
+ await makeGetRequest({
+ url: server.url,
+ path: accountChannelPath,
+ statusCodeExpected: 200
+ })
})
})
import * as chai from 'chai'
import 'mocha'
-import { User, Video } from '../../../../shared/index'
+import { User, Video, VideoChannel } from '../../../../shared/index'
import {
cleanupTests,
createUser,
})
it('Should have two video channels when getting account channels on server 1', async function () {
- const res = await getAccountVideoChannelsList(servers[0].url, userInfo.account.name + '@' + userInfo.account.host)
+ const res = await getAccountVideoChannelsList({
+ url: servers[ 0 ].url,
+ accountName: userInfo.account.name + '@' + userInfo.account.host
+ })
+
expect(res.body.total).to.equal(2)
expect(res.body.data).to.be.an('array')
expect(res.body.data).to.have.lengthOf(2)
expect(videoChannels[1].support).to.equal('super video channel support text')
})
+ it('Should paginate and sort account channels', async function () {
+ {
+ const res = await getAccountVideoChannelsList({
+ url: servers[ 0 ].url,
+ accountName: userInfo.account.name + '@' + userInfo.account.host,
+ start: 0,
+ count: 1,
+ sort: 'createdAt'
+ })
+
+ expect(res.body.total).to.equal(2)
+ expect(res.body.data).to.have.lengthOf(1)
+
+ const videoChannel: VideoChannel = res.body.data[ 0 ]
+ expect(videoChannel.name).to.equal('root_channel')
+ }
+
+ {
+ const res = await getAccountVideoChannelsList({
+ url: servers[ 0 ].url,
+ accountName: userInfo.account.name + '@' + userInfo.account.host,
+ start: 0,
+ count: 1,
+ sort: '-createdAt'
+ })
+
+ expect(res.body.total).to.equal(2)
+ expect(res.body.data).to.have.lengthOf(1)
+
+ const videoChannel: VideoChannel = res.body.data[ 0 ]
+ expect(videoChannel.name).to.equal('second_video_channel')
+ }
+
+ {
+ const res = await getAccountVideoChannelsList({
+ url: servers[ 0 ].url,
+ accountName: userInfo.account.name + '@' + userInfo.account.host,
+ start: 1,
+ count: 1,
+ sort: '-createdAt'
+ })
+
+ expect(res.body.total).to.equal(2)
+ expect(res.body.data).to.have.lengthOf(1)
+
+ const videoChannel: VideoChannel = res.body.data[ 0 ]
+ expect(videoChannel.name).to.equal('root_channel')
+ }
+ })
+
it('Should have one video channel when getting account channels on server 2', async function () {
- const res = await getAccountVideoChannelsList(servers[1].url, userInfo.account.name + '@' + userInfo.account.host)
+ const res = await getAccountVideoChannelsList({
+ url: servers[ 1 ].url,
+ accountName: userInfo.account.name + '@' + userInfo.account.host
+ })
+
expect(res.body.total).to.equal(1)
expect(res.body.data).to.be.an('array')
expect(res.body.data).to.have.lengthOf(1)
import * as request from 'supertest'
import { VideoChannelCreate, VideoChannelUpdate } from '../../models/videos'
-import { updateAvatarRequest } from '../requests/requests'
+import { makeGetRequest, updateAvatarRequest } from '../requests/requests'
import { getMyUserInformation, ServerInfo } from '..'
import { User } from '../..'
.expect('Content-Type', /json/)
}
-function getAccountVideoChannelsList (url: string, accountName: string, specialStatus = 200) {
+function getAccountVideoChannelsList (parameters: {
+ url: string,
+ accountName: string,
+ start?: number,
+ count?: number,
+ sort?: string,
+ specialStatus?: number
+}) {
+ const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200 } = parameters
+
const path = '/api/v1/accounts/' + accountName + '/video-channels'
- return request(url)
- .get(path)
- .set('Accept', 'application/json')
- .expect(specialStatus)
- .expect('Content-Type', /json/)
+ return makeGetRequest({
+ url,
+ path,
+ query: {
+ start,
+ count,
+ sort
+ },
+ statusCodeExpected: specialStatus
+ })
}
function addVideoChannel (