diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-14 09:16:32 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-14 09:27:19 +0200 |
commit | e5e7f7fe99bd0e8d6f3fa0b8ae8cf255ecaa6bf3 (patch) | |
tree | ad3bd3f278f37d22b1124d7ae99e8f2a5c2c00f1 /server/tests/api/check-params | |
parent | 191764f30b0a812bf3a9dbdc7daf1d5afe25e12a (diff) | |
download | PeerTube-e5e7f7fe99bd0e8d6f3fa0b8ae8cf255ecaa6bf3.tar.gz PeerTube-e5e7f7fe99bd0e8d6f3fa0b8ae8cf255ecaa6bf3.tar.zst PeerTube-e5e7f7fe99bd0e8d6f3fa0b8ae8cf255ecaa6bf3.zip |
Add tests when getting a blacklisted video
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/video-blacklist.ts | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index 415474718..473216236 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts | |||
@@ -5,7 +5,7 @@ import 'mocha' | |||
5 | import { | 5 | import { |
6 | createUser, | 6 | createUser, |
7 | flushTests, | 7 | flushTests, |
8 | getBlacklistedVideosList, | 8 | getBlacklistedVideosList, getVideo, getVideoWithToken, |
9 | killallServers, | 9 | killallServers, |
10 | makePostBodyRequest, | 10 | makePostBodyRequest, |
11 | makePutBodyRequest, | 11 | makePutBodyRequest, |
@@ -17,11 +17,14 @@ import { | |||
17 | userLogin | 17 | userLogin |
18 | } from '../../utils' | 18 | } from '../../utils' |
19 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 19 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' |
20 | import { VideoDetails } from '../../../../shared/models/videos' | ||
21 | import { expect } from 'chai' | ||
20 | 22 | ||
21 | describe('Test video blacklist API validators', function () { | 23 | describe('Test video blacklist API validators', function () { |
22 | let server: ServerInfo | 24 | let server: ServerInfo |
23 | let notBlacklistedVideoId: number | 25 | let notBlacklistedVideoId: number |
24 | let userAccessToken = '' | 26 | let userAccessToken1 = '' |
27 | let userAccessToken2 = '' | ||
25 | 28 | ||
26 | // --------------------------------------------------------------- | 29 | // --------------------------------------------------------------- |
27 | 30 | ||
@@ -34,13 +37,22 @@ describe('Test video blacklist API validators', function () { | |||
34 | 37 | ||
35 | await setAccessTokensToServers([ server ]) | 38 | await setAccessTokensToServers([ server ]) |
36 | 39 | ||
37 | const username = 'user1' | 40 | { |
38 | const password = 'my super password' | 41 | const username = 'user1' |
39 | await createUser(server.url, server.accessToken, username, password) | 42 | const password = 'my super password' |
40 | userAccessToken = await userLogin(server, { username, password }) | 43 | await createUser(server.url, server.accessToken, username, password) |
44 | userAccessToken1 = await userLogin(server, { username, password }) | ||
45 | } | ||
41 | 46 | ||
42 | { | 47 | { |
43 | const res = await uploadVideo(server.url, server.accessToken, {}) | 48 | const username = 'user2' |
49 | const password = 'my super password' | ||
50 | await createUser(server.url, server.accessToken, username, password) | ||
51 | userAccessToken2 = await userLogin(server, { username, password }) | ||
52 | } | ||
53 | |||
54 | { | ||
55 | const res = await uploadVideo(server.url, userAccessToken1, {}) | ||
44 | server.video = res.body.video | 56 | server.video = res.body.video |
45 | } | 57 | } |
46 | 58 | ||
@@ -74,7 +86,7 @@ describe('Test video blacklist API validators', function () { | |||
74 | it('Should fail with a non admin user', async function () { | 86 | it('Should fail with a non admin user', async function () { |
75 | const path = basePath + server.video + '/blacklist' | 87 | const path = basePath + server.video + '/blacklist' |
76 | const fields = {} | 88 | const fields = {} |
77 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) | 89 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) |
78 | }) | 90 | }) |
79 | 91 | ||
80 | it('Should fail with an invalid reason', async function () { | 92 | it('Should fail with an invalid reason', async function () { |
@@ -116,7 +128,7 @@ describe('Test video blacklist API validators', function () { | |||
116 | it('Should fail with a non admin user', async function () { | 128 | it('Should fail with a non admin user', async function () { |
117 | const path = basePath + server.video + '/blacklist' | 129 | const path = basePath + server.video + '/blacklist' |
118 | const fields = {} | 130 | const fields = {} |
119 | await makePutBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) | 131 | await makePutBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) |
120 | }) | 132 | }) |
121 | 133 | ||
122 | it('Should fail with an invalid reason', async function () { | 134 | it('Should fail with an invalid reason', async function () { |
@@ -134,13 +146,38 @@ describe('Test video blacklist API validators', function () { | |||
134 | }) | 146 | }) |
135 | }) | 147 | }) |
136 | 148 | ||
149 | describe('When getting blacklisted video', function () { | ||
150 | |||
151 | it('Should fail with a non authenticated user', async function () { | ||
152 | await getVideo(server.url, server.video.uuid, 401) | ||
153 | }) | ||
154 | |||
155 | it('Should fail with another user', async function () { | ||
156 | await getVideoWithToken(server.url, userAccessToken2, server.video.uuid, 403) | ||
157 | }) | ||
158 | |||
159 | it('Should succeed with the owner authenticated user', async function () { | ||
160 | const res = await getVideoWithToken(server.url, userAccessToken1, server.video.uuid, 200) | ||
161 | const video: VideoDetails = res.body | ||
162 | |||
163 | expect(video.blacklisted).to.be.true | ||
164 | }) | ||
165 | |||
166 | it('Should succeed with an admin', async function () { | ||
167 | const res = await getVideoWithToken(server.url, server.accessToken, server.video.uuid, 200) | ||
168 | const video: VideoDetails = res.body | ||
169 | |||
170 | expect(video.blacklisted).to.be.true | ||
171 | }) | ||
172 | }) | ||
173 | |||
137 | describe('When removing a video in blacklist', function () { | 174 | describe('When removing a video in blacklist', function () { |
138 | it('Should fail with a non authenticated user', async function () { | 175 | it('Should fail with a non authenticated user', async function () { |
139 | await removeVideoFromBlacklist(server.url, 'fake token', server.video.uuid, 401) | 176 | await removeVideoFromBlacklist(server.url, 'fake token', server.video.uuid, 401) |
140 | }) | 177 | }) |
141 | 178 | ||
142 | it('Should fail with a non admin user', async function () { | 179 | it('Should fail with a non admin user', async function () { |
143 | await removeVideoFromBlacklist(server.url, userAccessToken, server.video.uuid, 403) | 180 | await removeVideoFromBlacklist(server.url, userAccessToken2, server.video.uuid, 403) |
144 | }) | 181 | }) |
145 | 182 | ||
146 | it('Should fail with an incorrect id', async function () { | 183 | it('Should fail with an incorrect id', async function () { |
@@ -165,7 +202,7 @@ describe('Test video blacklist API validators', function () { | |||
165 | }) | 202 | }) |
166 | 203 | ||
167 | it('Should fail with a non admin user', async function () { | 204 | it('Should fail with a non admin user', async function () { |
168 | await getBlacklistedVideosList(server.url, userAccessToken, 403) | 205 | await getBlacklistedVideosList(server.url, userAccessToken2, 403) |
169 | }) | 206 | }) |
170 | 207 | ||
171 | it('Should fail with a bad start pagination', async function () { | 208 | it('Should fail with a bad start pagination', async function () { |