1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
12 setAccessTokensToServers,
15 import { UserRole } from '../../../../shared/models/users'
17 const expect = chai.expect
19 async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: number) {
21 '/api/v1/video-channels/root_channel/videos',
22 '/api/v1/accounts/root/videos',
24 '/api/v1/search/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
45 // ---------------------------------------------------------------
47 before(async function () {
52 server = await runServer(1)
54 await setAccessTokensToServers([ server ])
56 const user = { username: 'user1', password: 'my super password' }
57 await createUser(server.url, server.accessToken, user.username, user.password)
58 userAccessToken = await userLogin(server, user)
60 const moderator = { username: 'moderator', password: 'my super password' }
70 moderatorAccessToken = await userLogin(server, moderator)
73 describe('When setting a video filter', function () {
75 it('Should fail with a bad filter', async function () {
76 await testEndpoints(server, server.accessToken, 'bad-filter', 400)
79 it('Should succeed with a good filter', async function () {
80 await testEndpoints(server, server.accessToken,'local', 200)
83 it('Should fail to list all-local with a simple user', async function () {
84 await testEndpoints(server, userAccessToken, 'all-local', 401)
87 it('Should succeed to list all-local with a moderator', async function () {
88 await testEndpoints(server, moderatorAccessToken, 'all-local', 200)
91 it('Should succeed to list all-local with an admin', async function () {
92 await testEndpoints(server, server.accessToken, 'all-local', 200)
95 // Because we cannot authenticate the user on the RSS endpoint
96 it('Should fail on the feeds endpoint with the all-local filter', async function () {
97 await makeGetRequest({
99 path: '/feeds/videos.json',
100 statusCodeExpected: 401,
107 it('Should succed on the feeds endpoint with the local filter', async function () {
108 await makeGetRequest({
110 path: '/feeds/videos.json',
111 statusCodeExpected: 200,
119 after(async function () {
120 killallServers([ server ])
122 // Keep the logs if the test failed