]>
Commit | Line | Data |
---|---|---|
792dbaf0 GS |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import 'mocha' | |
792dbaf0 GS |
4 | |
5 | import { | |
26b7305a C |
6 | createUser, |
7 | flushTests, | |
8 | getBlacklistedVideosList, | |
9 | killallServers, | |
10 | makePostBodyRequest, | |
11 | makePutBodyRequest, | |
12 | removeVideoFromBlacklist, | |
13 | runServer, | |
14 | ServerInfo, | |
15 | setAccessTokensToServers, | |
16 | uploadVideo, | |
17 | userLogin | |
792dbaf0 | 18 | } from '../../utils' |
11ba2ab3 | 19 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' |
792dbaf0 GS |
20 | |
21 | describe('Test video blacklist API validators', function () { | |
22 | let server: ServerInfo | |
26b7305a | 23 | let notBlacklistedVideoId: number |
792dbaf0 GS |
24 | let userAccessToken = '' |
25 | ||
26 | // --------------------------------------------------------------- | |
27 | ||
28 | before(async function () { | |
29 | this.timeout(120000) | |
30 | ||
31 | await flushTests() | |
32 | ||
33 | server = await runServer(1) | |
34 | ||
35 | await setAccessTokensToServers([ server ]) | |
36 | ||
37 | const username = 'user1' | |
38 | const password = 'my super password' | |
39 | await createUser(server.url, server.accessToken, username, password) | |
eec63bbc | 40 | userAccessToken = await userLogin(server, { username, password }) |
792dbaf0 | 41 | |
26b7305a C |
42 | { |
43 | const res = await uploadVideo(server.url, server.accessToken, {}) | |
44 | server.video = res.body.video | |
45 | } | |
46 | ||
47 | { | |
48 | const res = await uploadVideo(server.url, server.accessToken, {}) | |
49 | notBlacklistedVideoId = res.body.video.uuid | |
50 | } | |
792dbaf0 GS |
51 | }) |
52 | ||
53 | describe('When adding a video in blacklist', function () { | |
54 | const basePath = '/api/v1/videos/' | |
55 | ||
56 | it('Should fail with nothing', async function () { | |
57 | const path = basePath + server.video + '/blacklist' | |
58 | const fields = {} | |
59 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
60 | }) | |
61 | ||
62 | it('Should fail with a wrong video', async function () { | |
63 | const wrongPath = '/api/v1/videos/blabla/blacklist' | |
64 | const fields = {} | |
65 | await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) | |
66 | }) | |
67 | ||
68 | it('Should fail with a non authenticated user', async function () { | |
792dbaf0 | 69 | const path = basePath + server.video + '/blacklist' |
11ba2ab3 | 70 | const fields = {} |
792dbaf0 GS |
71 | await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) |
72 | }) | |
73 | ||
74 | it('Should fail with a non admin user', async function () { | |
792dbaf0 | 75 | const path = basePath + server.video + '/blacklist' |
11ba2ab3 | 76 | const fields = {} |
792dbaf0 GS |
77 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) |
78 | }) | |
79 | ||
26b7305a C |
80 | it('Should fail with an invalid reason', async function () { |
81 | const path = basePath + server.video.uuid + '/blacklist' | |
82 | const fields = { reason: 'a'.repeat(305) } | |
83 | ||
84 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
85 | }) | |
86 | ||
87 | it('Should succeed with the correct params', async function () { | |
88 | const path = basePath + server.video.uuid + '/blacklist' | |
89 | const fields = { } | |
90 | ||
91 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
92 | }) | |
93 | }) | |
94 | ||
95 | describe('When updating a video in blacklist', function () { | |
96 | const basePath = '/api/v1/videos/' | |
97 | ||
98 | it('Should fail with a wrong video', async function () { | |
99 | const wrongPath = '/api/v1/videos/blabla/blacklist' | |
100 | const fields = {} | |
101 | await makePutBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) | |
102 | }) | |
103 | ||
104 | it('Should fail with a video not blacklisted', async function () { | |
105 | const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist' | |
106 | const fields = {} | |
107 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) | |
108 | }) | |
109 | ||
110 | it('Should fail with a non authenticated user', async function () { | |
111 | const path = basePath + server.video + '/blacklist' | |
112 | const fields = {} | |
113 | await makePutBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) | |
114 | }) | |
115 | ||
116 | it('Should fail with a non admin user', async function () { | |
117 | const path = basePath + server.video + '/blacklist' | |
11ba2ab3 | 118 | const fields = {} |
26b7305a C |
119 | await makePutBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) |
120 | }) | |
121 | ||
122 | it('Should fail with an invalid reason', async function () { | |
123 | const path = basePath + server.video.uuid + '/blacklist' | |
124 | const fields = { reason: 'a'.repeat(305) } | |
125 | ||
126 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
127 | }) | |
128 | ||
129 | it('Should succeed with the correct params', async function () { | |
130 | const path = basePath + server.video.uuid + '/blacklist' | |
131 | const fields = { reason: 'hello' } | |
132 | ||
133 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
792dbaf0 GS |
134 | }) |
135 | }) | |
136 | ||
137 | describe('When removing a video in blacklist', function () { | |
792dbaf0 | 138 | it('Should fail with a non authenticated user', async function () { |
26b7305a | 139 | await removeVideoFromBlacklist(server.url, 'fake token', server.video.uuid, 401) |
792dbaf0 GS |
140 | }) |
141 | ||
142 | it('Should fail with a non admin user', async function () { | |
26b7305a | 143 | await removeVideoFromBlacklist(server.url, userAccessToken, server.video.uuid, 403) |
792dbaf0 GS |
144 | }) |
145 | ||
146 | it('Should fail with an incorrect id', async function () { | |
11ba2ab3 | 147 | await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400) |
792dbaf0 GS |
148 | }) |
149 | ||
150 | it('Should fail with a not blacklisted video', async function () { | |
151 | // The video was not added to the blacklist so it should fail | |
26b7305a C |
152 | await removeVideoFromBlacklist(server.url, server.accessToken, notBlacklistedVideoId, 404) |
153 | }) | |
154 | ||
155 | it('Should succeed with the correct params', async function () { | |
156 | await removeVideoFromBlacklist(server.url, server.accessToken, server.video.uuid, 204) | |
792dbaf0 GS |
157 | }) |
158 | }) | |
159 | ||
160 | describe('When listing videos in blacklist', function () { | |
35bf0c83 | 161 | const basePath = '/api/v1/videos/blacklist/' |
792dbaf0 GS |
162 | |
163 | it('Should fail with a non authenticated user', async function () { | |
11ba2ab3 | 164 | await getBlacklistedVideosList(server.url, 'fake token', 401) |
792dbaf0 GS |
165 | }) |
166 | ||
167 | it('Should fail with a non admin user', async function () { | |
11ba2ab3 | 168 | await getBlacklistedVideosList(server.url, userAccessToken, 403) |
792dbaf0 GS |
169 | }) |
170 | ||
171 | it('Should fail with a bad start pagination', async function () { | |
11ba2ab3 | 172 | await checkBadStartPagination(server.url, basePath, server.accessToken) |
792dbaf0 GS |
173 | }) |
174 | ||
175 | it('Should fail with a bad count pagination', async function () { | |
11ba2ab3 | 176 | await checkBadCountPagination(server.url, basePath, server.accessToken) |
792dbaf0 GS |
177 | }) |
178 | ||
179 | it('Should fail with an incorrect sort', async function () { | |
11ba2ab3 | 180 | await checkBadSortPagination(server.url, basePath, server.accessToken) |
792dbaf0 GS |
181 | }) |
182 | }) | |
183 | ||
184 | after(async function () { | |
185 | killallServers([ server ]) | |
186 | ||
187 | // Keep the logs if the test failed | |
188 | if (this['ok']) { | |
189 | await flushTests() | |
190 | } | |
191 | }) | |
192 | }) |