X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fvideos%2Fvideos-overview.ts;h=c012d47c3fd6b1010bce894f1d1599b0c291b97d;hb=b1dbb9fefc870a90b25f5c0153589f45c9e75e3e;hp=1514d1bda07992c9a1fc3fe20619d2777d434609;hpb=2d3741d6d92e9bd1f41694c7442a6d1da434e1f2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index 1514d1bda..c012d47c3 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -1,96 +1,129 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' -import 'mocha' -import { flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils' -import { getVideosOverview } from '../../utils/overviews/overviews' -import { VideosOverview } from '../../../../shared/models/overviews' - -const expect = chai.expect +import { expect } from 'chai' +import { wait } from '@shared/core-utils' +import { VideosOverview } from '@shared/models' +import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' describe('Test a videos overview', function () { - let server: ServerInfo = null + let server: PeerTubeServer = 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) - await flushTests() - - server = await runServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) }) it('Should send empty overview', async function () { - const res = await getVideosOverview(server.url) + const body = await server.overviews.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 3 videos in a specific category, tag and channel but not include them in overview', async function () { - for (let i = 0; i < 3; i++) { - await uploadVideo(server.url, server.accessToken, { - name: 'video ' + i, + it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () { + this.timeout(30000) + + await wait(3000) + + await server.videos.upload({ + attributes: { + name: 'video 0', category: 3, tags: [ 'coucou1', 'coucou2' ] - }) - } + } + }) - const res = await getVideosOverview(server.url) + const body = await server.overviews.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 another video and include all videos in the overview', async function () { - await uploadVideo(server.url, server.accessToken, { - name: 'video 3', - category: 3, - tags: [ 'coucou1', 'coucou2' ] - }) + this.timeout(30000) - const res = await getVideosOverview(server.url) + { + for (let i = 1; i < 6; i++) { + await server.videos.upload({ + attributes: { + name: 'video ' + i, + category: 3, + tags: [ 'coucou1', 'coucou2' ] + } + }) + } + + await wait(3000) + } + + { + const body = await server.overviews.getVideos({ page: 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) + testOverviewCount(body, 1) + } + + { + const overview = await server.overviews.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.overviews.getVideos({ page: 1 }) + const overview2 = await server.overviews.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(4) - expect(obj.videos[0].name).to.equal('video 3') - expect(obj.videos[1].name).to.equal('video 2') - expect(obj.videos[2].name).to.equal('video 1') - expect(obj.videos[3].name).to.equal('video 0') + 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') } - 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(overview.channels[0].channel.name).to.equal('root_channel') + expect(overview1.channels[0].channel.name).to.equal('root_channel') }) - after(async function () { - killallServers([ server ]) + it('Should hide muted accounts', async function () { + const token = await server.users.generateUserAndToken('choco') + + await server.blocklist.addToMyBlocklist({ token, account: 'root@' + server.host }) + + { + const body = await server.overviews.getVideos({ page: 1 }) - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() + testOverviewCount(body, 1) } + + { + const body = await server.overviews.getVideos({ page: 1, token }) + + testOverviewCount(body, 0) + } + }) + + after(async function () { + await cleanupTests([ server ]) }) })