PeerTube/server/tests/api/videos/videos-overview.ts

151 lines
4.0 KiB
TypeScript
Raw Normal View History

2020-01-31 09:56:52 -06:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2018-08-30 07:58:00 -05:00
import 'mocha'
2020-11-10 04:06:36 -06:00
import * as chai from 'chai'
import {
cleanupTests,
flushAndRunServer,
generateUserAccessToken,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
wait
} from '../../../../shared/extra-utils'
import { getVideosOverview, getVideosOverviewWithToken } from '../../../../shared/extra-utils/overviews/overviews'
2018-08-30 07:58:00 -05:00
import { VideosOverview } from '../../../../shared/models/overviews'
2020-11-10 04:06:36 -06:00
import { addAccountToAccountBlocklist } from '@shared/extra-utils/users/blocklist'
import { Response } from 'superagent'
2018-08-30 07:58:00 -05:00
const expect = chai.expect
describe('Test a videos overview', function () {
let server: ServerInfo = null
2020-11-10 04:06:36 -06:00
function testOverviewCount (res: Response, expected: number) {
const overview: VideosOverview = res.body
expect(overview.tags).to.have.lengthOf(expected)
expect(overview.categories).to.have.lengthOf(expected)
expect(overview.channels).to.have.lengthOf(expected)
}
2018-08-30 07:58:00 -05:00
before(async function () {
this.timeout(30000)
2019-04-24 03:53:40 -05:00
server = await flushAndRunServer(1)
2018-08-30 07:58:00 -05:00
await setAccessTokensToServers([ server ])
})
it('Should send empty overview', async function () {
const res = await getVideosOverview(server.url, 1)
2018-08-30 07:58:00 -05:00
2020-11-10 04:06:36 -06:00
testOverviewCount(res, 0)
2018-08-30 07:58:00 -05:00
})
2018-08-31 10:18:13 -05:00
it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
this.timeout(15000)
await wait(3000)
await uploadVideo(server.url, server.accessToken, {
name: 'video 0',
category: 3,
tags: [ 'coucou1', 'coucou2' ]
})
2018-08-30 07:58:00 -05:00
const res = await getVideosOverview(server.url, 1)
2018-08-30 07:58:00 -05:00
2020-11-10 04:06:36 -06:00
testOverviewCount(res, 0)
2018-08-30 07:58:00 -05:00
})
it('Should upload another video and include all videos in the overview', async function () {
this.timeout(15000)
2018-08-30 07:58:00 -05:00
for (let i = 1; i < 6; i++) {
await uploadVideo(server.url, server.accessToken, {
name: 'video ' + i,
category: 3,
tags: [ 'coucou1', 'coucou2' ]
})
}
2018-08-30 07:58:00 -05:00
await wait(3000)
{
const res = await getVideosOverview(server.url, 1)
2020-11-10 04:06:36 -06:00
testOverviewCount(res, 1)
}
{
const res = await getVideosOverview(server.url, 2)
const overview: VideosOverview = res.body
expect(overview.tags).to.have.lengthOf(1)
expect(overview.categories).to.have.lengthOf(0)
expect(overview.channels).to.have.lengthOf(0)
}
2018-08-30 07:58:00 -05:00
})
it('Should have the correct overview', async function () {
const res1 = await getVideosOverview(server.url, 1)
const res2 = await getVideosOverview(server.url, 2)
2018-08-30 07:58:00 -05:00
const overview1: VideosOverview = res1.body
const overview2: VideosOverview = res2.body
const tmp = [
overview1.tags,
overview1.categories,
overview1.channels,
overview2.tags
]
for (const arr of tmp) {
expect(arr).to.have.lengthOf(1)
2018-08-30 07:58:00 -05:00
const obj = arr[0]
2018-08-30 07:58:00 -05:00
2018-08-31 10:18:13 -05:00
expect(obj.videos).to.have.lengthOf(6)
expect(obj.videos[0].name).to.equal('video 5')
expect(obj.videos[1].name).to.equal('video 4')
expect(obj.videos[2].name).to.equal('video 3')
expect(obj.videos[3].name).to.equal('video 2')
expect(obj.videos[4].name).to.equal('video 1')
expect(obj.videos[5].name).to.equal('video 0')
2018-08-30 07:58:00 -05:00
}
const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ]
expect(tags.find(t => t === 'coucou1')).to.not.be.undefined
expect(tags.find(t => t === 'coucou2')).to.not.be.undefined
2018-08-30 07:58:00 -05:00
expect(overview1.categories[0].category.id).to.equal(3)
2018-08-30 07:58:00 -05:00
expect(overview1.channels[0].channel.name).to.equal('root_channel')
2018-08-30 07:58:00 -05:00
})
2020-11-10 04:06:36 -06:00
it('Should hide muted accounts', async function () {
const token = await generateUserAccessToken(server, 'choco')
await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host)
{
const res = await getVideosOverview(server.url, 1)
testOverviewCount(res, 1)
}
{
const res = await getVideosOverviewWithToken(server.url, 1, token)
testOverviewCount(res, 0)
}
})
2019-04-24 08:10:37 -05:00
after(async function () {
await cleanupTests([ server ])
2018-08-30 07:58:00 -05:00
})
})