1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
9 flushAndRunMultipleServers,
12 setAccessTokensToServers,
14 } from '../../../../shared/extra-utils'
15 import { UserRole } from '../../../../shared/models/users'
16 import { Video, VideoPrivacy } from '../../../../shared/models/videos'
18 const expect = chai.expect
20 async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) {
22 '/api/v1/video-channels/root_channel/videos',
23 '/api/v1/accounts/root/videos',
25 '/api/v1/search/videos'
28 const videosResults: Video[][] = []
30 for (const path of paths) {
31 const res = await makeGetRequest({
42 videosResults.push(res.body.data.map(v => v.name))
48 describe('Test videos filter', function () {
49 let servers: ServerInfo[]
51 // ---------------------------------------------------------------
53 before(async function () {
56 servers = await flushAndRunMultipleServers(2)
58 await setAccessTokensToServers(servers)
60 for (const server of servers) {
61 const moderator = { username: 'moderator', password: 'my super password' }
62 await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
63 server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator)
65 await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber })
68 const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED }
69 await uploadVideo(server.url, server.accessToken, attributes)
73 const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE }
74 await uploadVideo(server.url, server.accessToken, attributes)
78 await doubleFollow(servers[0], servers[1])
81 describe('Check videos filter', function () {
83 it('Should display local videos', async function () {
84 for (const server of servers) {
85 const namesResults = await getVideosNames(server, server.accessToken, 'local')
86 for (const names of namesResults) {
87 expect(names).to.have.lengthOf(1)
88 expect(names[0]).to.equal('public ' + server.serverNumber)
93 it('Should display all local videos by the admin or the moderator', async function () {
94 for (const server of servers) {
95 for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
97 const namesResults = await getVideosNames(server, token, 'all-local')
98 for (const names of namesResults) {
99 expect(names).to.have.lengthOf(3)
101 expect(names[0]).to.equal('public ' + server.serverNumber)
102 expect(names[1]).to.equal('unlisted ' + server.serverNumber)
103 expect(names[2]).to.equal('private ' + server.serverNumber)
109 it('Should display all videos by the admin or the moderator', async function () {
110 for (const server of servers) {
111 for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
113 const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames(server, token, 'all')
114 expect(channelVideos).to.have.lengthOf(3)
115 expect(accountVideos).to.have.lengthOf(3)
117 expect(videos).to.have.lengthOf(5)
118 expect(searchVideos).to.have.lengthOf(5)
124 after(async function () {
125 await cleanupTests(servers)