]>
Commit | Line | Data |
---|---|---|
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/all with a simple user', async function () { | |
82 | await testEndpoints(server, userAccessToken, 'all-local', 401) | |
83 | await testEndpoints(server, userAccessToken, 'all', 401) | |
84 | }) | |
85 | ||
86 | it('Should succeed to list all-local/all with a moderator', async function () { | |
87 | await testEndpoints(server, moderatorAccessToken, 'all-local', 200) | |
88 | await testEndpoints(server, moderatorAccessToken, 'all', 200) | |
89 | }) | |
90 | ||
91 | it('Should succeed to list all-local/all with an admin', async function () { | |
92 | await testEndpoints(server, server.accessToken, 'all-local', 200) | |
93 | await testEndpoints(server, server.accessToken, 'all', 200) | |
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/all filter', async function () { | |
98 | for (const filter of [ 'all', 'all-local' ]) { | |
99 | await makeGetRequest({ | |
100 | url: server.url, | |
101 | path: '/feeds/videos.json', | |
102 | statusCodeExpected: 401, | |
103 | query: { | |
104 | filter | |
105 | } | |
106 | }) | |
107 | } | |
108 | }) | |
109 | ||
110 | it('Should succeed on the feeds endpoint with the local filter', async function () { | |
111 | await makeGetRequest({ | |
112 | url: server.url, | |
113 | path: '/feeds/videos.json', | |
114 | statusCodeExpected: 200, | |
115 | query: { | |
116 | filter: 'local' | |
117 | } | |
118 | }) | |
119 | }) | |
120 | }) | |
121 | ||
122 | after(async function () { | |
123 | await cleanupTests([ server ]) | |
124 | }) | |
125 | }) |