]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/videos-filter.ts
Introduce user command
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / videos-filter.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
1cd3facc 2
1cd3facc 3import 'mocha'
41d1d075
C
4import * as chai from 'chai'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
1cd3facc 6import {
7c3b7976 7 cleanupTests,
1cd3facc
C
8 doubleFollow,
9 flushAndRunMultipleServers,
1cd3facc
C
10 makeGetRequest,
11 ServerInfo,
12 setAccessTokensToServers,
41d1d075 13 uploadVideo
94565d52 14} from '../../../../shared/extra-utils'
1cd3facc 15import { UserRole } from '../../../../shared/models/users'
41d1d075 16import { Video, VideoPrivacy } from '../../../../shared/models/videos'
1cd3facc
C
17
18const expect = chai.expect
19
2d53be02 20async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) {
1cd3facc
C
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
3124b469 48describe('Test videos filter', function () {
1cd3facc
C
49 let servers: ServerInfo[]
50
51 // ---------------------------------------------------------------
52
53 before(async function () {
3124b469 54 this.timeout(160000)
1cd3facc 55
1cd3facc
C
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' }
7926c5f9 62 await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
41d1d075 63 server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator)
1cd3facc
C
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)
a1587156 88 expect(names[0]).to.equal('public ' + server.serverNumber)
1cd3facc
C
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
a1587156
C
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)
1cd3facc
C
104 }
105 }
106 }
107 })
0aa52e17
C
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 })
1cd3facc
C
122 })
123
7c3b7976
C
124 after(async function () {
125 await cleanupTests(servers)
1cd3facc
C
126 })
127})