]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/videos-filter.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / videos-filter.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import {
5 cleanupTests,
6 createUser,
7 flushAndRunServer,
8 makeGetRequest,
9 ServerInfo,
10 setAccessTokensToServers,
11 setDefaultVideoChannel,
12 userLogin
13 } from '../../../../shared/extra-utils'
14 import { UserRole } from '../../../../shared/models/users'
15
16 async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: number) {
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 for (const path of paths) {
25 await makeGetRequest({
26 url: server.url,
27 path,
28 token,
29 query: {
30 filter
31 },
32 statusCodeExpected
33 })
34 }
35 }
36
37 describe('Test videos filters', function () {
38 let server: ServerInfo
39 let userAccessToken: string
40 let moderatorAccessToken: string
41
42 // ---------------------------------------------------------------
43
44 before(async function () {
45 this.timeout(30000)
46
47 server = await flushAndRunServer(1)
48
49 await setAccessTokensToServers([ server ])
50 await setDefaultVideoChannel([ server ])
51
52 const user = { username: 'user1', password: 'my super password' }
53 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
54 userAccessToken = await userLogin(server, user)
55
56 const moderator = { username: 'moderator', password: 'my super password' }
57 await createUser(
58 {
59 url: server.url,
60 accessToken: server.accessToken,
61 username: moderator.username,
62 password: moderator.password,
63 videoQuota: undefined,
64 videoQuotaDaily: undefined,
65 role: UserRole.MODERATOR
66 }
67 )
68 moderatorAccessToken = await userLogin(server, moderator)
69 })
70
71 describe('When setting a video filter', function () {
72
73 it('Should fail with a bad filter', async function () {
74 await testEndpoints(server, server.accessToken, 'bad-filter', 400)
75 })
76
77 it('Should succeed with a good filter', async function () {
78 await testEndpoints(server, server.accessToken, 'local', 200)
79 })
80
81 it('Should fail to list all-local with a simple user', async function () {
82 await testEndpoints(server, userAccessToken, 'all-local', 401)
83 })
84
85 it('Should succeed to list all-local with a moderator', async function () {
86 await testEndpoints(server, moderatorAccessToken, 'all-local', 200)
87 })
88
89 it('Should succeed to list all-local with an admin', async function () {
90 await testEndpoints(server, server.accessToken, 'all-local', 200)
91 })
92
93 // Because we cannot authenticate the user on the RSS endpoint
94 it('Should fail on the feeds endpoint with the all-local filter', async function () {
95 await makeGetRequest({
96 url: server.url,
97 path: '/feeds/videos.json',
98 statusCodeExpected: 401,
99 query: {
100 filter: 'all-local'
101 }
102 })
103 })
104
105 it('Should succeed on the feeds endpoint with the local filter', async function () {
106 await makeGetRequest({
107 url: server.url,
108 path: '/feeds/videos.json',
109 statusCodeExpected: 200,
110 query: {
111 filter: 'local'
112 }
113 })
114 })
115 })
116
117 after(async function () {
118 await cleanupTests([ server ])
119 })
120 })