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