]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import 'mocha' | |
4 | ||
5 | import { | |
6 | createUser, flushTests, getBlacklistedVideosList, killallServers, makePostBodyRequest, removeVideoFromBlacklist, runServer, | |
7 | ServerInfo, setAccessTokensToServers, uploadVideo, userLogin | |
8 | } from '../../utils' | |
9 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | |
10 | ||
11 | describe('Test video blacklist API validators', function () { | |
12 | let server: ServerInfo | |
13 | let userAccessToken = '' | |
14 | ||
15 | // --------------------------------------------------------------- | |
16 | ||
17 | before(async function () { | |
18 | this.timeout(120000) | |
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 adding a video in blacklist', function () { | |
36 | const basePath = '/api/v1/videos/' | |
37 | ||
38 | it('Should fail with nothing', async function () { | |
39 | const path = basePath + server.video + '/blacklist' | |
40 | const fields = {} | |
41 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
42 | }) | |
43 | ||
44 | it('Should fail with a wrong video', async function () { | |
45 | const wrongPath = '/api/v1/videos/blabla/blacklist' | |
46 | const fields = {} | |
47 | await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) | |
48 | }) | |
49 | ||
50 | it('Should fail with a non authenticated user', async function () { | |
51 | const path = basePath + server.video + '/blacklist' | |
52 | const fields = {} | |
53 | await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) | |
54 | }) | |
55 | ||
56 | it('Should fail with a non admin user', async function () { | |
57 | const path = basePath + server.video + '/blacklist' | |
58 | const fields = {} | |
59 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) | |
60 | }) | |
61 | ||
62 | it('Should fail with a local video', async function () { | |
63 | const path = basePath + server.video.id + '/blacklist' | |
64 | const fields = {} | |
65 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 }) | |
66 | }) | |
67 | }) | |
68 | ||
69 | describe('When removing a video in blacklist', function () { | |
70 | it('Should fail with a non authenticated user', async function () { | |
71 | await removeVideoFromBlacklist(server.url, 'fake token', server.video.id, 401) | |
72 | }) | |
73 | ||
74 | it('Should fail with a non admin user', async function () { | |
75 | await removeVideoFromBlacklist(server.url, userAccessToken, server.video.id, 403) | |
76 | }) | |
77 | ||
78 | it('Should fail with an incorrect id', async function () { | |
79 | await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400) | |
80 | }) | |
81 | ||
82 | it('Should fail with a not blacklisted video', async function () { | |
83 | // The video was not added to the blacklist so it should fail | |
84 | await removeVideoFromBlacklist(server.url, server.accessToken, server.video.id, 404) | |
85 | }) | |
86 | }) | |
87 | ||
88 | describe('When listing videos in blacklist', function () { | |
89 | const basePath = '/api/v1/videos/blacklist/' | |
90 | ||
91 | it('Should fail with a non authenticated user', async function () { | |
92 | await getBlacklistedVideosList(server.url, 'fake token', 401) | |
93 | }) | |
94 | ||
95 | it('Should fail with a non admin user', async function () { | |
96 | await getBlacklistedVideosList(server.url, userAccessToken, 403) | |
97 | }) | |
98 | ||
99 | it('Should fail with a bad start pagination', async function () { | |
100 | await checkBadStartPagination(server.url, basePath, server.accessToken) | |
101 | }) | |
102 | ||
103 | it('Should fail with a bad count pagination', async function () { | |
104 | await checkBadCountPagination(server.url, basePath, server.accessToken) | |
105 | }) | |
106 | ||
107 | it('Should fail with an incorrect sort', async function () { | |
108 | await checkBadSortPagination(server.url, basePath, server.accessToken) | |
109 | }) | |
110 | }) | |
111 | ||
112 | after(async function () { | |
113 | killallServers([ server ]) | |
114 | ||
115 | // Keep the logs if the test failed | |
116 | if (this['ok']) { | |
117 | await flushTests() | |
118 | } | |
119 | }) | |
120 | }) |