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