]>
Commit | Line | Data |
---|---|---|
1cd3facc C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
1cd3facc C |
3 | import 'mocha' |
4 | import { | |
7c3b7976 | 5 | cleanupTests, |
1cd3facc | 6 | createUser, |
07b1a18a | 7 | createVideoPlaylist, |
210feb6c | 8 | flushAndRunServer, |
7c3b7976 | 9 | makeGetRequest, |
1cd3facc | 10 | ServerInfo, |
7c3b7976 C |
11 | setAccessTokensToServers, |
12 | setDefaultVideoChannel, | |
1cd3facc | 13 | userLogin |
94565d52 | 14 | } from '../../../../shared/extra-utils' |
1cd3facc | 15 | import { UserRole } from '../../../../shared/models/users' |
07b1a18a | 16 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' |
1cd3facc | 17 | |
bfbd9128 | 18 | async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: number) { |
1cd3facc C |
19 | const paths = [ |
20 | '/api/v1/video-channels/root_channel/videos', | |
21 | '/api/v1/accounts/root/videos', | |
22 | '/api/v1/videos', | |
bfbd9128 | 23 | '/api/v1/search/videos' |
1cd3facc C |
24 | ] |
25 | ||
26 | for (const path of paths) { | |
27 | await makeGetRequest({ | |
28 | url: server.url, | |
29 | path, | |
30 | token, | |
31 | query: { | |
32 | filter | |
33 | }, | |
34 | statusCodeExpected | |
35 | }) | |
36 | } | |
37 | } | |
38 | ||
39 | describe('Test videos filters', function () { | |
40 | let server: ServerInfo | |
41 | let userAccessToken: string | |
42 | let moderatorAccessToken: string | |
43 | ||
44 | // --------------------------------------------------------------- | |
45 | ||
46 | before(async function () { | |
47 | this.timeout(30000) | |
48 | ||
210feb6c | 49 | server = await flushAndRunServer(1) |
1cd3facc C |
50 | |
51 | await setAccessTokensToServers([ server ]) | |
397d78fb | 52 | await setDefaultVideoChannel([ server ]) |
1cd3facc C |
53 | |
54 | const user = { username: 'user1', password: 'my super password' } | |
1eddc9a7 | 55 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
1cd3facc C |
56 | userAccessToken = await userLogin(server, user) |
57 | ||
58 | const moderator = { username: 'moderator', password: 'my super password' } | |
59 | await createUser( | |
1eddc9a7 C |
60 | { |
61 | url: server.url, | |
62 | accessToken: server.accessToken, | |
63 | username: moderator.username, | |
64 | password: moderator.password, | |
65 | videoQuota: undefined, | |
66 | videoQuotaDaily: undefined, | |
67 | role: UserRole.MODERATOR | |
68 | } | |
1cd3facc C |
69 | ) |
70 | moderatorAccessToken = await userLogin(server, moderator) | |
71 | }) | |
72 | ||
73 | describe('When setting a video filter', function () { | |
74 | ||
75 | it('Should fail with a bad filter', async function () { | |
bfbd9128 | 76 | await testEndpoints(server, server.accessToken, 'bad-filter', 400) |
1cd3facc C |
77 | }) |
78 | ||
79 | it('Should succeed with a good filter', async function () { | |
bfbd9128 | 80 | await testEndpoints(server, server.accessToken,'local', 200) |
1cd3facc C |
81 | }) |
82 | ||
83 | it('Should fail to list all-local with a simple user', async function () { | |
bfbd9128 | 84 | await testEndpoints(server, userAccessToken, 'all-local', 401) |
1cd3facc C |
85 | }) |
86 | ||
87 | it('Should succeed to list all-local with a moderator', async function () { | |
bfbd9128 | 88 | await testEndpoints(server, moderatorAccessToken, 'all-local', 200) |
1cd3facc C |
89 | }) |
90 | ||
91 | it('Should succeed to list all-local with an admin', async function () { | |
bfbd9128 | 92 | await testEndpoints(server, server.accessToken, 'all-local', 200) |
1cd3facc C |
93 | }) |
94 | ||
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({ | |
98 | url: server.url, | |
99 | path: '/feeds/videos.json', | |
100 | statusCodeExpected: 401, | |
101 | query: { | |
102 | filter: 'all-local' | |
103 | } | |
104 | }) | |
105 | }) | |
106 | ||
07b1a18a | 107 | it('Should succeed on the feeds endpoint with the local filter', async function () { |
1cd3facc C |
108 | await makeGetRequest({ |
109 | url: server.url, | |
110 | path: '/feeds/videos.json', | |
111 | statusCodeExpected: 200, | |
112 | query: { | |
113 | filter: 'local' | |
114 | } | |
115 | }) | |
116 | }) | |
117 | }) | |
118 | ||
7c3b7976 C |
119 | after(async function () { |
120 | await cleanupTests([ server ]) | |
1cd3facc C |
121 | }) |
122 | }) |