]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/tests/api/videos/videos-filter.ts
Introduce user command
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / videos-filter.ts
... / ...
CommitLineData
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6import {
7 cleanupTests,
8 doubleFollow,
9 flushAndRunMultipleServers,
10 makeGetRequest,
11 ServerInfo,
12 setAccessTokensToServers,
13 uploadVideo
14} from '../../../../shared/extra-utils'
15import { UserRole } from '../../../../shared/models/users'
16import { Video, VideoPrivacy } from '../../../../shared/models/videos'
17
18const expect = chai.expect
19
20async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) {
21 const paths = [
22 '/api/v1/video-channels/root_channel/videos',
23 '/api/v1/accounts/root/videos',
24 '/api/v1/videos',
25 '/api/v1/search/videos'
26 ]
27
28 const videosResults: Video[][] = []
29
30 for (const path of paths) {
31 const res = await makeGetRequest({
32 url: server.url,
33 path,
34 token,
35 query: {
36 sort: 'createdAt',
37 filter
38 },
39 statusCodeExpected
40 })
41
42 videosResults.push(res.body.data.map(v => v.name))
43 }
44
45 return videosResults
46}
47
48describe('Test videos filter', function () {
49 let servers: ServerInfo[]
50
51 // ---------------------------------------------------------------
52
53 before(async function () {
54 this.timeout(160000)
55
56 servers = await flushAndRunMultipleServers(2)
57
58 await setAccessTokensToServers(servers)
59
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)
64
65 await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber })
66
67 {
68 const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED }
69 await uploadVideo(server.url, server.accessToken, attributes)
70 }
71
72 {
73 const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE }
74 await uploadVideo(server.url, server.accessToken, attributes)
75 }
76 }
77
78 await doubleFollow(servers[0], servers[1])
79 })
80
81 describe('Check videos filter', function () {
82
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)
89 }
90 }
91 })
92
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'] ]) {
96
97 const namesResults = await getVideosNames(server, token, 'all-local')
98 for (const names of namesResults) {
99 expect(names).to.have.lengthOf(3)
100
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)
104 }
105 }
106 }
107 })
108
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'] ]) {
112
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)
116
117 expect(videos).to.have.lengthOf(5)
118 expect(searchVideos).to.have.lengthOf(5)
119 }
120 }
121 })
122 })
123
124 after(async function () {
125 await cleanupTests(servers)
126 })
127})