]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/videos-filter.ts
Shorter server command names
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / videos-filter.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import { expect } from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
6 import {
7 cleanupTests,
8 doubleFollow,
9 flushAndRunMultipleServers,
10 makeGetRequest,
11 ServerInfo,
12 setAccessTokensToServers
13 } from '@shared/extra-utils'
14 import { UserRole, Video, VideoPrivacy } from '@shared/models'
15
16 async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) {
17 const paths = [
18 '/api/v1/video-channels/root_channel/videos',
19 '/api/v1/accounts/root/videos',
20 '/api/v1/videos',
21 '/api/v1/search/videos'
22 ]
23
24 const videosResults: Video[][] = []
25
26 for (const path of paths) {
27 const res = await makeGetRequest({
28 url: server.url,
29 path,
30 token,
31 query: {
32 sort: 'createdAt',
33 filter
34 },
35 statusCodeExpected
36 })
37
38 videosResults.push(res.body.data.map(v => v.name))
39 }
40
41 return videosResults
42 }
43
44 describe('Test videos filter', function () {
45 let servers: ServerInfo[]
46
47 // ---------------------------------------------------------------
48
49 before(async function () {
50 this.timeout(160000)
51
52 servers = await flushAndRunMultipleServers(2)
53
54 await setAccessTokensToServers(servers)
55
56 for (const server of servers) {
57 const moderator = { username: 'moderator', password: 'my super password' }
58 await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
59 server['moderatorAccessToken'] = await server.login.getAccessToken(moderator)
60
61 await server.videos.upload({ attributes: { name: 'public ' + server.serverNumber } })
62
63 {
64 const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED }
65 await server.videos.upload({ attributes })
66 }
67
68 {
69 const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE }
70 await server.videos.upload({ attributes })
71 }
72 }
73
74 await doubleFollow(servers[0], servers[1])
75 })
76
77 describe('Check videos filter', function () {
78
79 it('Should display local videos', async function () {
80 for (const server of servers) {
81 const namesResults = await getVideosNames(server, server.accessToken, 'local')
82 for (const names of namesResults) {
83 expect(names).to.have.lengthOf(1)
84 expect(names[0]).to.equal('public ' + server.serverNumber)
85 }
86 }
87 })
88
89 it('Should display all local videos by the admin or the moderator', async function () {
90 for (const server of servers) {
91 for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
92
93 const namesResults = await getVideosNames(server, token, 'all-local')
94 for (const names of namesResults) {
95 expect(names).to.have.lengthOf(3)
96
97 expect(names[0]).to.equal('public ' + server.serverNumber)
98 expect(names[1]).to.equal('unlisted ' + server.serverNumber)
99 expect(names[2]).to.equal('private ' + server.serverNumber)
100 }
101 }
102 }
103 })
104
105 it('Should display all videos by the admin or the moderator', async function () {
106 for (const server of servers) {
107 for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
108
109 const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames(server, token, 'all')
110 expect(channelVideos).to.have.lengthOf(3)
111 expect(accountVideos).to.have.lengthOf(3)
112
113 expect(videos).to.have.lengthOf(5)
114 expect(searchVideos).to.have.lengthOf(5)
115 }
116 }
117 })
118 })
119
120 after(async function () {
121 await cleanupTests(servers)
122 })
123 })