X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fvideos%2Fvideos-overview.ts;h=b3ab9e070e8582aaabce7aa1de4ec0718f85fdef;hb=65e6e2602c0d5521f3a6740f7469bb92830ecb53;hp=c63725d71dbcdb8ffdd7cd1fecce43834dc6f251;hpb=42e1ec25ece5ef6b7a29d64610e3729578059e52;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index c63725d71..b3ab9e070 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -1,16 +1,30 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { flushAndRunServer, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils' -import { getVideosOverview } from '../../../../shared/extra-utils/overviews/overviews' -import { VideosOverview } from '../../../../shared/models/overviews' +import * as chai from 'chai' +import { + addAccountToAccountBlocklist, + cleanupTests, + flushAndRunServer, + generateUserAccessToken, + ServerInfo, + setAccessTokensToServers, + uploadVideo, + wait +} from '@shared/extra-utils' +import { VideosOverview } from '@shared/models' const expect = chai.expect describe('Test a videos overview', function () { let server: ServerInfo = null + function testOverviewCount (overview: VideosOverview, expected: number) { + expect(overview.tags).to.have.lengthOf(expected) + expect(overview.categories).to.have.lengthOf(expected) + expect(overview.channels).to.have.lengthOf(expected) + } + before(async function () { this.timeout(30000) @@ -20,55 +34,65 @@ describe('Test a videos overview', function () { }) it('Should send empty overview', async function () { - const res = await getVideosOverview(server.url) + const body = await server.overviewsCommand.getVideos({ page: 1 }) - const overview: VideosOverview = res.body - expect(overview.tags).to.have.lengthOf(0) - expect(overview.categories).to.have.lengthOf(0) - expect(overview.channels).to.have.lengthOf(0) + testOverviewCount(body, 0) }) it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () { - this.timeout(15000) - - for (let i = 0; i < 5; i++) { - await uploadVideo(server.url, server.accessToken, { - name: 'video ' + i, - category: 3, - tags: [ 'coucou1', 'coucou2' ] - }) - } - - const res = await getVideosOverview(server.url) + this.timeout(30000) - const overview: VideosOverview = res.body - expect(overview.tags).to.have.lengthOf(0) - expect(overview.categories).to.have.lengthOf(0) - expect(overview.channels).to.have.lengthOf(0) - }) + await wait(3000) - it('Should upload another video and include all videos in the overview', async function () { await uploadVideo(server.url, server.accessToken, { - name: 'video 5', + name: 'video 0', category: 3, tags: [ 'coucou1', 'coucou2' ] }) - const res = await getVideosOverview(server.url) + const body = await server.overviewsCommand.getVideos({ page: 1 }) + + testOverviewCount(body, 0) + }) + + it('Should upload another video and include all videos in the overview', async function () { + this.timeout(30000) + + { + for (let i = 1; i < 6; i++) { + await uploadVideo(server.url, server.accessToken, { + name: 'video ' + i, + category: 3, + tags: [ 'coucou1', 'coucou2' ] + }) + } + + await wait(3000) + } + + { + const body = await server.overviewsCommand.getVideos({ page: 1 }) + + testOverviewCount(body, 1) + } - const overview: VideosOverview = res.body - expect(overview.tags).to.have.lengthOf(2) - expect(overview.categories).to.have.lengthOf(1) - expect(overview.channels).to.have.lengthOf(1) + { + const overview = await server.overviewsCommand.getVideos({ page: 2 }) + + expect(overview.tags).to.have.lengthOf(1) + expect(overview.categories).to.have.lengthOf(0) + expect(overview.channels).to.have.lengthOf(0) + } }) it('Should have the correct overview', async function () { - const res = await getVideosOverview(server.url) + const overview1 = await server.overviewsCommand.getVideos({ page: 1 }) + const overview2 = await server.overviewsCommand.getVideos({ page: 2 }) - const overview: VideosOverview = res.body + for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) { + expect(arr).to.have.lengthOf(1) - for (const attr of [ 'tags', 'categories', 'channels' ]) { - const obj = overview[attr][0] + const obj = arr[0] expect(obj.videos).to.have.lengthOf(6) expect(obj.videos[0].name).to.equal('video 5') @@ -79,15 +103,34 @@ describe('Test a videos overview', function () { expect(obj.videos[5].name).to.equal('video 0') } - expect(overview.tags.find(t => t.tag === 'coucou1')).to.not.be.undefined - expect(overview.tags.find(t => t.tag === 'coucou2')).to.not.be.undefined + 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 - expect(overview.categories[0].category.id).to.equal(3) + expect(overview1.categories[0].category.id).to.equal(3) + + expect(overview1.channels[0].channel.name).to.equal('root_channel') + }) - expect(overview.channels[0].channel.name).to.equal('root_channel') + it('Should hide muted accounts', async function () { + const token = await generateUserAccessToken(server, 'choco') + + await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host) + + { + const body = await server.overviewsCommand.getVideos({ page: 1 }) + + testOverviewCount(body, 1) + } + + { + const body = await server.overviewsCommand.getVideos({ page: 1, token }) + + testOverviewCount(body, 0) + } }) - after(function () { - killallServers([ server ]) + after(async function () { + await cleanupTests([ server ]) }) })