diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-10 16:54:01 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-10 16:54:01 +0200 |
commit | 268eebed921ac13a9ce0f4717f4923aa24190657 (patch) | |
tree | 52f8436968c8dcc686663ef5db8dffd7ed191d34 /server/tests/api/check-params | |
parent | 904a463c7792837f0a468a522a28448323e48593 (diff) | |
download | PeerTube-268eebed921ac13a9ce0f4717f4923aa24190657.tar.gz PeerTube-268eebed921ac13a9ce0f4717f4923aa24190657.tar.zst PeerTube-268eebed921ac13a9ce0f4717f4923aa24190657.zip |
Add state and moderationComment for abuses on server side
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/video-abuses.ts | 115 |
1 files changed, 97 insertions, 18 deletions
diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts index 68b965bbe..d2bed6a2a 100644 --- a/server/tests/api/check-params/video-abuses.ts +++ b/server/tests/api/check-params/video-abuses.ts | |||
@@ -3,14 +3,26 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | 4 | ||
5 | import { | 5 | import { |
6 | createUser, flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, | 6 | createUser, |
7 | uploadVideo, userLogin | 7 | deleteVideoAbuse, |
8 | flushTests, | ||
9 | killallServers, | ||
10 | makeGetRequest, | ||
11 | makePostBodyRequest, | ||
12 | runServer, | ||
13 | ServerInfo, | ||
14 | setAccessTokensToServers, | ||
15 | updateVideoAbuse, | ||
16 | uploadVideo, | ||
17 | userLogin | ||
8 | } from '../../utils' | 18 | } from '../../utils' |
9 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | 19 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' |
20 | import { VideoAbuseState } from '../../../../shared/models/videos' | ||
10 | 21 | ||
11 | describe('Test video abuses API validators', function () { | 22 | describe('Test video abuses API validators', function () { |
12 | let server: ServerInfo | 23 | let server: ServerInfo |
13 | let userAccessToken = '' | 24 | let userAccessToken = '' |
25 | let videoAbuseId: number | ||
14 | 26 | ||
15 | // --------------------------------------------------------------- | 27 | // --------------------------------------------------------------- |
16 | 28 | ||
@@ -67,44 +79,111 @@ describe('Test video abuses API validators', function () { | |||
67 | 79 | ||
68 | describe('When reporting a video abuse', function () { | 80 | describe('When reporting a video abuse', function () { |
69 | const basePath = '/api/v1/videos/' | 81 | const basePath = '/api/v1/videos/' |
82 | let path: string | ||
83 | |||
84 | before(() => { | ||
85 | path = basePath + server.video.id + '/abuse' | ||
86 | }) | ||
70 | 87 | ||
71 | it('Should fail with nothing', async function () { | 88 | it('Should fail with nothing', async function () { |
72 | const path = basePath + server.video.id + '/abuse' | ||
73 | const fields = {} | 89 | const fields = {} |
74 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 90 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
75 | }) | 91 | }) |
76 | 92 | ||
77 | it('Should fail with a wrong video', async function () { | 93 | it('Should fail with a wrong video', async function () { |
78 | const wrongPath = '/api/v1/videos/blabla/abuse' | 94 | const wrongPath = '/api/v1/videos/blabla/abuse' |
79 | const fields = { | 95 | const fields = { reason: 'my super reason' } |
80 | reason: 'my super reason' | 96 | |
81 | } | ||
82 | await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) | 97 | await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) |
83 | }) | 98 | }) |
84 | 99 | ||
85 | it('Should fail with a non authenticated user', async function () { | 100 | it('Should fail with a non authenticated user', async function () { |
86 | const path = basePath + server.video.id + '/abuse' | 101 | const fields = { reason: 'my super reason' } |
87 | const fields = { | 102 | |
88 | reason: 'my super reason' | ||
89 | } | ||
90 | await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) | 103 | await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) |
91 | }) | 104 | }) |
92 | 105 | ||
93 | it('Should fail with a reason too short', async function () { | 106 | it('Should fail with a reason too short', async function () { |
94 | const path = basePath + server.video.id + '/abuse' | 107 | const fields = { reason: 'h' } |
95 | const fields = { | 108 | |
96 | reason: 'h' | ||
97 | } | ||
98 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 109 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
99 | }) | 110 | }) |
100 | 111 | ||
101 | it('Should fail with a reason too big', async function () { | 112 | it('Should fail with a reason too big', async function () { |
102 | const path = basePath + server.video.id + '/abuse' | 113 | const fields = { reason: 'super'.repeat(61) } |
103 | const fields = { | 114 | |
104 | reason: 'super'.repeat(61) | ||
105 | } | ||
106 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 115 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
107 | }) | 116 | }) |
117 | |||
118 | it('Should succeed with the correct parameters', async function () { | ||
119 | const fields = { reason: 'super reason' } | ||
120 | |||
121 | const res = await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 }) | ||
122 | videoAbuseId = res.body.videoAbuse.id | ||
123 | }) | ||
124 | }) | ||
125 | |||
126 | describe('When updating a video abuse', function () { | ||
127 | const basePath = '/api/v1/videos/' | ||
128 | let path: string | ||
129 | |||
130 | before(() => { | ||
131 | path = basePath + server.video.id + '/abuse/' + videoAbuseId | ||
132 | }) | ||
133 | |||
134 | it('Should fail with a non authenticated user', async function () { | ||
135 | await updateVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, {}, 401) | ||
136 | }) | ||
137 | |||
138 | it('Should fail with a non admin user', async function () { | ||
139 | await updateVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, {}, 403) | ||
140 | }) | ||
141 | |||
142 | it('Should fail with a bad video id or bad video abuse id', async function () { | ||
143 | await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, {}, 404) | ||
144 | await updateVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, {}, 404) | ||
145 | }) | ||
146 | |||
147 | it('Should fail with a bad state', async function () { | ||
148 | const body = { state: 5 } | ||
149 | await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400) | ||
150 | }) | ||
151 | |||
152 | it('Should fail with a bad moderation comment', async function () { | ||
153 | const body = { moderationComment: 'b'.repeat(305) } | ||
154 | await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400) | ||
155 | }) | ||
156 | |||
157 | it('Should succeed with the correct params', async function () { | ||
158 | const body = { state: VideoAbuseState.ACCEPTED } | ||
159 | await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body) | ||
160 | }) | ||
161 | }) | ||
162 | |||
163 | describe('When deleting a video abuse', function () { | ||
164 | const basePath = '/api/v1/videos/' | ||
165 | let path: string | ||
166 | |||
167 | before(() => { | ||
168 | path = basePath + server.video.id + '/abuse/' + videoAbuseId | ||
169 | }) | ||
170 | |||
171 | it('Should fail with a non authenticated user', async function () { | ||
172 | await deleteVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, 401) | ||
173 | }) | ||
174 | |||
175 | it('Should fail with a non admin user', async function () { | ||
176 | await deleteVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, 403) | ||
177 | }) | ||
178 | |||
179 | it('Should fail with a bad video id or bad video abuse id', async function () { | ||
180 | await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, 404) | ||
181 | await deleteVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, 404) | ||
182 | }) | ||
183 | |||
184 | it('Should succeed with the correct params', async function () { | ||
185 | await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId) | ||
186 | }) | ||
108 | }) | 187 | }) |
109 | 188 | ||
110 | after(async function () { | 189 | after(async function () { |