]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import 'mocha' | |
4 | ||
5 | import { | |
6 | createUser, flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, | |
7 | uploadVideo, userLogin | |
8 | } from '../../utils' | |
9 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | |
10 | ||
11 | describe('Test video abuses API validators', function () { | |
12 | let server: ServerInfo | |
13 | let userAccessToken = '' | |
14 | ||
15 | // --------------------------------------------------------------- | |
16 | ||
17 | before(async function () { | |
18 | this.timeout(20000) | |
19 | ||
20 | await flushTests() | |
21 | ||
22 | server = await runServer(1) | |
23 | ||
24 | await setAccessTokensToServers([ server ]) | |
25 | ||
26 | const username = 'user1' | |
27 | const password = 'my super password' | |
28 | await createUser(server.url, server.accessToken, username, password) | |
29 | userAccessToken = await userLogin(server, { username, password }) | |
30 | ||
31 | const res = await uploadVideo(server.url, server.accessToken, {}) | |
32 | server.video = res.body.video | |
33 | }) | |
34 | ||
35 | describe('When listing video abuses', function () { | |
36 | const path = '/api/v1/videos/abuse' | |
37 | ||
38 | it('Should fail with a bad start pagination', async function () { | |
39 | await checkBadStartPagination(server.url, path, server.accessToken) | |
40 | }) | |
41 | ||
42 | it('Should fail with a bad count pagination', async function () { | |
43 | await checkBadCountPagination(server.url, path, server.accessToken) | |
44 | }) | |
45 | ||
46 | it('Should fail with an incorrect sort', async function () { | |
47 | await checkBadSortPagination(server.url, path, server.accessToken) | |
48 | }) | |
49 | ||
50 | it('Should fail with a non authenticated user', async function () { | |
51 | await makeGetRequest({ | |
52 | url: server.url, | |
53 | path, | |
54 | statusCodeExpected: 401 | |
55 | }) | |
56 | }) | |
57 | ||
58 | it('Should fail with a non admin user', async function () { | |
59 | await makeGetRequest({ | |
60 | url: server.url, | |
61 | path, | |
62 | token: userAccessToken, | |
63 | statusCodeExpected: 403 | |
64 | }) | |
65 | }) | |
66 | }) | |
67 | ||
68 | describe('When reporting a video abuse', function () { | |
69 | const basePath = '/api/v1/videos/' | |
70 | ||
71 | it('Should fail with nothing', async function () { | |
72 | const path = basePath + server.video.id + '/abuse' | |
73 | const fields = {} | |
74 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
75 | }) | |
76 | ||
77 | it('Should fail with a wrong video', async function () { | |
78 | const wrongPath = '/api/v1/videos/blabla/abuse' | |
79 | const fields = { | |
80 | reason: 'my super reason' | |
81 | } | |
82 | await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) | |
83 | }) | |
84 | ||
85 | it('Should fail with a non authenticated user', async function () { | |
86 | const path = basePath + server.video.id + '/abuse' | |
87 | const fields = { | |
88 | reason: 'my super reason' | |
89 | } | |
90 | await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) | |
91 | }) | |
92 | ||
93 | it('Should fail with a reason too short', async function () { | |
94 | const path = basePath + server.video.id + '/abuse' | |
95 | const fields = { | |
96 | reason: 'h' | |
97 | } | |
98 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
99 | }) | |
100 | ||
101 | it('Should fail with a reason too big', async function () { | |
102 | const path = basePath + server.video.id + '/abuse' | |
103 | const fields = { | |
104 | reason: 'super'.repeat(61) | |
105 | } | |
106 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
107 | }) | |
108 | }) | |
109 | ||
110 | after(async function () { | |
111 | killallServers([ server ]) | |
112 | ||
113 | // Keep the logs if the test failed | |
114 | if (this['ok']) { | |
115 | await flushTests() | |
116 | } | |
117 | }) | |
118 | }) |