]>
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, |
210feb6c | 6 | flushAndRunServer, |
7c3b7976 | 7 | makeGetRequest, |
1cd3facc | 8 | ServerInfo, |
7c3b7976 | 9 | setAccessTokensToServers, |
41d1d075 | 10 | setDefaultVideoChannel |
94565d52 | 11 | } from '../../../../shared/extra-utils' |
1cd3facc | 12 | import { UserRole } from '../../../../shared/models/users' |
2d53be02 | 13 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
1cd3facc | 14 | |
2d53be02 | 15 | async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: HttpStatusCode) { |
1cd3facc C |
16 | const paths = [ |
17 | '/api/v1/video-channels/root_channel/videos', | |
18 | '/api/v1/accounts/root/videos', | |
19 | '/api/v1/videos', | |
bfbd9128 | 20 | '/api/v1/search/videos' |
1cd3facc C |
21 | ] |
22 | ||
23 | for (const path of paths) { | |
24 | await makeGetRequest({ | |
25 | url: server.url, | |
26 | path, | |
27 | token, | |
28 | query: { | |
29 | filter | |
30 | }, | |
31 | statusCodeExpected | |
32 | }) | |
33 | } | |
34 | } | |
35 | ||
3124b469 | 36 | describe('Test video filters validators', function () { |
1cd3facc C |
37 | let server: ServerInfo |
38 | let userAccessToken: string | |
39 | let moderatorAccessToken: string | |
40 | ||
41 | // --------------------------------------------------------------- | |
42 | ||
43 | before(async function () { | |
44 | this.timeout(30000) | |
45 | ||
210feb6c | 46 | server = await flushAndRunServer(1) |
1cd3facc C |
47 | |
48 | await setAccessTokensToServers([ server ]) | |
397d78fb | 49 | await setDefaultVideoChannel([ server ]) |
1cd3facc C |
50 | |
51 | const user = { username: 'user1', password: 'my super password' } | |
89d241a7 C |
52 | await server.users.create({ username: user.username, password: user.password }) |
53 | userAccessToken = await server.login.getAccessToken(user) | |
1cd3facc C |
54 | |
55 | const moderator = { username: 'moderator', password: 'my super password' } | |
89d241a7 | 56 | await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) |
7926c5f9 | 57 | |
89d241a7 | 58 | moderatorAccessToken = await server.login.getAccessToken(moderator) |
1cd3facc C |
59 | }) |
60 | ||
61 | describe('When setting a video filter', function () { | |
62 | ||
63 | it('Should fail with a bad filter', async function () { | |
2d53be02 | 64 | await testEndpoints(server, server.accessToken, 'bad-filter', HttpStatusCode.BAD_REQUEST_400) |
1cd3facc C |
65 | }) |
66 | ||
67 | it('Should succeed with a good filter', async function () { | |
2d53be02 | 68 | await testEndpoints(server, server.accessToken, 'local', HttpStatusCode.OK_200) |
1cd3facc C |
69 | }) |
70 | ||
0aa52e17 | 71 | it('Should fail to list all-local/all with a simple user', async function () { |
2d53be02 RK |
72 | await testEndpoints(server, userAccessToken, 'all-local', HttpStatusCode.UNAUTHORIZED_401) |
73 | await testEndpoints(server, userAccessToken, 'all', HttpStatusCode.UNAUTHORIZED_401) | |
1cd3facc C |
74 | }) |
75 | ||
0aa52e17 | 76 | it('Should succeed to list all-local/all with a moderator', async function () { |
2d53be02 RK |
77 | await testEndpoints(server, moderatorAccessToken, 'all-local', HttpStatusCode.OK_200) |
78 | await testEndpoints(server, moderatorAccessToken, 'all', HttpStatusCode.OK_200) | |
1cd3facc C |
79 | }) |
80 | ||
0aa52e17 | 81 | it('Should succeed to list all-local/all with an admin', async function () { |
2d53be02 RK |
82 | await testEndpoints(server, server.accessToken, 'all-local', HttpStatusCode.OK_200) |
83 | await testEndpoints(server, server.accessToken, 'all', HttpStatusCode.OK_200) | |
1cd3facc C |
84 | }) |
85 | ||
86 | // Because we cannot authenticate the user on the RSS endpoint | |
0aa52e17 C |
87 | it('Should fail on the feeds endpoint with the all-local/all filter', async function () { |
88 | for (const filter of [ 'all', 'all-local' ]) { | |
89 | await makeGetRequest({ | |
90 | url: server.url, | |
91 | path: '/feeds/videos.json', | |
2d53be02 | 92 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401, |
0aa52e17 C |
93 | query: { |
94 | filter | |
95 | } | |
96 | }) | |
97 | } | |
1cd3facc C |
98 | }) |
99 | ||
07b1a18a | 100 | it('Should succeed on the feeds endpoint with the local filter', async function () { |
1cd3facc C |
101 | await makeGetRequest({ |
102 | url: server.url, | |
103 | path: '/feeds/videos.json', | |
2d53be02 | 104 | statusCodeExpected: HttpStatusCode.OK_200, |
1cd3facc C |
105 | query: { |
106 | filter: 'local' | |
107 | } | |
108 | }) | |
109 | }) | |
110 | }) | |
111 | ||
7c3b7976 C |
112 | after(async function () { |
113 | await cleanupTests([ server ]) | |
1cd3facc C |
114 | }) |
115 | }) |