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