]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/videos-filter.ts
Add playlist channel validator when playlist is public
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / videos-filter.ts
CommitLineData
1cd3facc
C
1/* tslint:disable:no-unused-expression */
2
1cd3facc
C
3import 'mocha'
4import {
5 createUser,
07b1a18a 6 createVideoPlaylist,
1cd3facc
C
7 flushTests,
8 killallServers,
9 makeGetRequest,
10 runServer,
11 ServerInfo,
12 setAccessTokensToServers,
13 userLogin
9639bd17 14} from '../../../../shared/utils'
1cd3facc 15import { UserRole } from '../../../../shared/models/users'
07b1a18a 16import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
1cd3facc 17
07b1a18a 18async function testEndpoints (server: ServerInfo, token: string, filter: string, playlistUUID: string, statusCodeExpected: number) {
1cd3facc
C
19 const paths = [
20 '/api/v1/video-channels/root_channel/videos',
21 '/api/v1/accounts/root/videos',
22 '/api/v1/videos',
07b1a18a
C
23 '/api/v1/search/videos',
24 '/api/v1/video-playlists/' + playlistUUID + '/videos'
1cd3facc
C
25 ]
26
27 for (const path of paths) {
28 await makeGetRequest({
29 url: server.url,
30 path,
31 token,
32 query: {
33 filter
34 },
35 statusCodeExpected
36 })
37 }
38}
39
40describe('Test videos filters', function () {
41 let server: ServerInfo
42 let userAccessToken: string
43 let moderatorAccessToken: string
07b1a18a 44 let playlistUUID: string
1cd3facc
C
45
46 // ---------------------------------------------------------------
47
48 before(async function () {
49 this.timeout(30000)
50
51 await flushTests()
52
53 server = await runServer(1)
54
55 await setAccessTokensToServers([ server ])
56
57 const user = { username: 'user1', password: 'my super password' }
58 await createUser(server.url, server.accessToken, user.username, user.password)
59 userAccessToken = await userLogin(server, user)
60
61 const moderator = { username: 'moderator', password: 'my super password' }
62 await createUser(
63 server.url,
64 server.accessToken,
65 moderator.username,
66 moderator.password,
67 undefined,
68 undefined,
69 UserRole.MODERATOR
70 )
71 moderatorAccessToken = await userLogin(server, moderator)
07b1a18a
C
72
73 const res = await createVideoPlaylist({
74 url: server.url,
75 token: server.accessToken,
76 playlistAttrs: {
77 displayName: 'super playlist',
78 privacy: VideoPlaylistPrivacy.PUBLIC
79 }
80 })
81 playlistUUID = res.body.videoPlaylist.uuid
1cd3facc
C
82 })
83
84 describe('When setting a video filter', function () {
85
86 it('Should fail with a bad filter', async function () {
07b1a18a 87 await testEndpoints(server, server.accessToken, 'bad-filter', playlistUUID, 400)
1cd3facc
C
88 })
89
90 it('Should succeed with a good filter', async function () {
07b1a18a 91 await testEndpoints(server, server.accessToken,'local', playlistUUID, 200)
1cd3facc
C
92 })
93
94 it('Should fail to list all-local with a simple user', async function () {
07b1a18a 95 await testEndpoints(server, userAccessToken, 'all-local', playlistUUID, 401)
1cd3facc
C
96 })
97
98 it('Should succeed to list all-local with a moderator', async function () {
07b1a18a 99 await testEndpoints(server, moderatorAccessToken, 'all-local', playlistUUID, 200)
1cd3facc
C
100 })
101
102 it('Should succeed to list all-local with an admin', async function () {
07b1a18a 103 await testEndpoints(server, server.accessToken, 'all-local', playlistUUID, 200)
1cd3facc
C
104 })
105
106 // Because we cannot authenticate the user on the RSS endpoint
107 it('Should fail on the feeds endpoint with the all-local filter', async function () {
108 await makeGetRequest({
109 url: server.url,
110 path: '/feeds/videos.json',
111 statusCodeExpected: 401,
112 query: {
113 filter: 'all-local'
114 }
115 })
116 })
117
07b1a18a 118 it('Should succeed on the feeds endpoint with the local filter', async function () {
1cd3facc
C
119 await makeGetRequest({
120 url: server.url,
121 path: '/feeds/videos.json',
122 statusCodeExpected: 200,
123 query: {
124 filter: 'local'
125 }
126 })
127 })
128 })
129
130 after(async function () {
131 killallServers([ server ])
132
133 // Keep the logs if the test failed
134 if (this['ok']) {
135 await flushTests()
136 }
137 })
138})