]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
1cd3facc | 2 | |
1cd3facc C |
3 | import 'mocha' |
4 | import { | |
7c3b7976 | 5 | cleanupTests, |
1cd3facc | 6 | createUser, |
210feb6c | 7 | flushAndRunServer, |
7c3b7976 | 8 | makeGetRequest, |
1cd3facc | 9 | ServerInfo, |
7c3b7976 C |
10 | setAccessTokensToServers, |
11 | setDefaultVideoChannel, | |
1cd3facc | 12 | userLogin |
94565d52 | 13 | } from '../../../../shared/extra-utils' |
1cd3facc C |
14 | import { UserRole } from '../../../../shared/models/users' |
15 | ||
bfbd9128 | 16 | async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: number) { |
1cd3facc C |
17 | const paths = [ |
18 | '/api/v1/video-channels/root_channel/videos', | |
19 | '/api/v1/accounts/root/videos', | |
20 | '/api/v1/videos', | |
bfbd9128 | 21 | '/api/v1/search/videos' |
1cd3facc C |
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 | ||
210feb6c | 47 | server = await flushAndRunServer(1) |
1cd3facc C |
48 | |
49 | await setAccessTokensToServers([ server ]) | |
397d78fb | 50 | await setDefaultVideoChannel([ server ]) |
1cd3facc C |
51 | |
52 | const user = { username: 'user1', password: 'my super password' } | |
1eddc9a7 | 53 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
1cd3facc C |
54 | userAccessToken = await userLogin(server, user) |
55 | ||
56 | const moderator = { username: 'moderator', password: 'my super password' } | |
57 | await createUser( | |
1eddc9a7 C |
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 | } | |
1cd3facc C |
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 () { | |
bfbd9128 | 74 | await testEndpoints(server, server.accessToken, 'bad-filter', 400) |
1cd3facc C |
75 | }) |
76 | ||
77 | it('Should succeed with a good filter', async function () { | |
a1587156 | 78 | await testEndpoints(server, server.accessToken, 'local', 200) |
1cd3facc C |
79 | }) |
80 | ||
81 | it('Should fail to list all-local with a simple user', async function () { | |
bfbd9128 | 82 | await testEndpoints(server, userAccessToken, 'all-local', 401) |
1cd3facc C |
83 | }) |
84 | ||
85 | it('Should succeed to list all-local with a moderator', async function () { | |
bfbd9128 | 86 | await testEndpoints(server, moderatorAccessToken, 'all-local', 200) |
1cd3facc C |
87 | }) |
88 | ||
89 | it('Should succeed to list all-local with an admin', async function () { | |
bfbd9128 | 90 | await testEndpoints(server, server.accessToken, 'all-local', 200) |
1cd3facc C |
91 | }) |
92 | ||
93 | // Because we cannot authenticate the user on the RSS endpoint | |
94 | it('Should fail on the feeds endpoint with the all-local filter', async function () { | |
95 | await makeGetRequest({ | |
96 | url: server.url, | |
97 | path: '/feeds/videos.json', | |
98 | statusCodeExpected: 401, | |
99 | query: { | |
100 | filter: 'all-local' | |
101 | } | |
102 | }) | |
103 | }) | |
104 | ||
07b1a18a | 105 | it('Should succeed on the feeds endpoint with the local filter', async function () { |
1cd3facc C |
106 | await makeGetRequest({ |
107 | url: server.url, | |
108 | path: '/feeds/videos.json', | |
109 | statusCodeExpected: 200, | |
110 | query: { | |
111 | filter: 'local' | |
112 | } | |
113 | }) | |
114 | }) | |
115 | }) | |
116 | ||
7c3b7976 C |
117 | after(async function () { |
118 | await cleanupTests([ server ]) | |
1cd3facc C |
119 | }) |
120 | }) |