1 /* tslint:disable:no-unused-expression */
12 setAccessTokensToServers,
14 } from '../../../../shared/utils'
15 import { UserRole } from '../../../../shared/models/users'
16 import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
18 async function testEndpoints (server: ServerInfo, token: string, filter: string, playlistUUID: string, statusCodeExpected: number) {
20 '/api/v1/video-channels/root_channel/videos',
21 '/api/v1/accounts/root/videos',
23 '/api/v1/search/videos',
24 '/api/v1/video-playlists/' + playlistUUID + '/videos'
27 for (const path of paths) {
28 await makeGetRequest({
40 describe('Test videos filters', function () {
41 let server: ServerInfo
42 let userAccessToken: string
43 let moderatorAccessToken: string
44 let playlistUUID: string
46 // ---------------------------------------------------------------
48 before(async function () {
53 server = await runServer(1)
55 await setAccessTokensToServers([ server ])
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)
61 const moderator = { username: 'moderator', password: 'my super password' }
71 moderatorAccessToken = await userLogin(server, moderator)
73 const res = await createVideoPlaylist({
75 token: server.accessToken,
77 displayName: 'super playlist',
78 privacy: VideoPlaylistPrivacy.PUBLIC
81 playlistUUID = res.body.videoPlaylist.uuid
84 describe('When setting a video filter', function () {
86 it('Should fail with a bad filter', async function () {
87 await testEndpoints(server, server.accessToken, 'bad-filter', playlistUUID, 400)
90 it('Should succeed with a good filter', async function () {
91 await testEndpoints(server, server.accessToken,'local', playlistUUID, 200)
94 it('Should fail to list all-local with a simple user', async function () {
95 await testEndpoints(server, userAccessToken, 'all-local', playlistUUID, 401)
98 it('Should succeed to list all-local with a moderator', async function () {
99 await testEndpoints(server, moderatorAccessToken, 'all-local', playlistUUID, 200)
102 it('Should succeed to list all-local with an admin', async function () {
103 await testEndpoints(server, server.accessToken, 'all-local', playlistUUID, 200)
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({
110 path: '/feeds/videos.json',
111 statusCodeExpected: 401,
118 it('Should succeed on the feeds endpoint with the local filter', async function () {
119 await makeGetRequest({
121 path: '/feeds/videos.json',
122 statusCodeExpected: 200,
130 after(async function () {
131 killallServers([ server ])
133 // Keep the logs if the test failed