aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/config.ts19
-rw-r--r--server/tests/api/check-params/users.ts6
-rw-r--r--server/tests/api/index-fast.ts1
-rw-r--r--server/tests/api/server/config.ts5
-rw-r--r--server/tests/api/users/users.ts26
-rw-r--r--server/tests/api/videos/video-nsfw.ts197
-rw-r--r--server/tests/utils/users/users.ts5
-rw-r--r--server/tests/utils/videos/videos.ts30
8 files changed, 268 insertions, 21 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 3fe517fad..58b780f38 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -6,7 +6,7 @@ import { CustomConfig } from '../../../../shared/models/server/custom-config.mod
6 6
7import { 7import {
8 createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo, 8 createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo,
9 setAccessTokensToServers, userLogin 9 setAccessTokensToServers, userLogin, immutableAssign
10} from '../../utils' 10} from '../../utils'
11 11
12describe('Test config API validators', function () { 12describe('Test config API validators', function () {
@@ -20,6 +20,7 @@ describe('Test config API validators', function () {
20 description: 'my super description', 20 description: 'my super description',
21 terms: 'my super terms', 21 terms: 'my super terms',
22 defaultClientRoute: '/videos/recently-added', 22 defaultClientRoute: '/videos/recently-added',
23 defaultNSFWPolicy: 'blur',
23 customizations: { 24 customizations: {
24 javascript: 'alert("coucou")', 25 javascript: 'alert("coucou")',
25 css: 'body { background-color: red; }' 26 css: 'body { background-color: red; }'
@@ -122,6 +123,22 @@ describe('Test config API validators', function () {
122 }) 123 })
123 }) 124 })
124 125
126 it('Should fail with a bad default NSFW policy', async function () {
127 const newUpdateParams = immutableAssign(updateParams, {
128 instance: {
129 defaultNSFWPolicy: 'hello'
130 }
131 })
132
133 await makePutBodyRequest({
134 url: server.url,
135 path,
136 fields: newUpdateParams,
137 token: server.accessToken,
138 statusCodeExpected: 400
139 })
140 })
141
125 it('Should success with the correct parameters', async function () { 142 it('Should success with the correct parameters', async function () {
126 await makePutBodyRequest({ 143 await makePutBodyRequest({
127 url: server.url, 144 url: server.url,
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index a3e415b94..e8a6ffd19 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -231,9 +231,9 @@ describe('Test users API validators', function () {
231 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 231 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
232 }) 232 })
233 233
234 it('Should fail with an invalid display NSFW attribute', async function () { 234 it('Should fail with an invalid NSFW policy attribute', async function () {
235 const fields = { 235 const fields = {
236 displayNSFW: -1 236 nsfwPolicy: 'hello'
237 } 237 }
238 238
239 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 239 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
@@ -266,7 +266,7 @@ describe('Test users API validators', function () {
266 it('Should succeed with the correct params', async function () { 266 it('Should succeed with the correct params', async function () {
267 const fields = { 267 const fields = {
268 password: 'my super password', 268 password: 'my super password',
269 displayNSFW: true, 269 nsfwPolicy: 'blur',
270 autoPlayVideo: false, 270 autoPlayVideo: false,
271 email: 'super_email@example.com' 271 email: 'super_email@example.com'
272 } 272 }
diff --git a/server/tests/api/index-fast.ts b/server/tests/api/index-fast.ts
index aa063b97a..2454ec2f9 100644
--- a/server/tests/api/index-fast.ts
+++ b/server/tests/api/index-fast.ts
@@ -7,6 +7,7 @@ import './videos/video-abuse'
7import './videos/video-blacklist' 7import './videos/video-blacklist'
8import './videos/video-blacklist-management' 8import './videos/video-blacklist-management'
9import './videos/video-description' 9import './videos/video-description'
10import './videos/video-nsfw'
10import './videos/video-privacy' 11import './videos/video-privacy'
11import './videos/services' 12import './videos/services'
12import './server/email' 13import './server/email'
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index e17588142..3f1b1532c 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -59,6 +59,7 @@ describe('Test config', function () {
59 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!') 59 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
60 expect(data.instance.terms).to.equal('No terms for now.') 60 expect(data.instance.terms).to.equal('No terms for now.')
61 expect(data.instance.defaultClientRoute).to.equal('/videos/trending') 61 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
62 expect(data.instance.defaultNSFWPolicy).to.equal('display')
62 expect(data.instance.customizations.css).to.be.empty 63 expect(data.instance.customizations.css).to.be.empty
63 expect(data.instance.customizations.javascript).to.be.empty 64 expect(data.instance.customizations.javascript).to.be.empty
64 expect(data.cache.previews.size).to.equal(1) 65 expect(data.cache.previews.size).to.equal(1)
@@ -83,6 +84,7 @@ describe('Test config', function () {
83 description: 'my super description', 84 description: 'my super description',
84 terms: 'my super terms', 85 terms: 'my super terms',
85 defaultClientRoute: '/videos/recently-added', 86 defaultClientRoute: '/videos/recently-added',
87 defaultNSFWPolicy: 'blur' as 'blur',
86 customizations: { 88 customizations: {
87 javascript: 'alert("coucou")', 89 javascript: 'alert("coucou")',
88 css: 'body { background-color: red; }' 90 css: 'body { background-color: red; }'
@@ -125,6 +127,7 @@ describe('Test config', function () {
125 expect(data.instance.description).to.equal('my super description') 127 expect(data.instance.description).to.equal('my super description')
126 expect(data.instance.terms).to.equal('my super terms') 128 expect(data.instance.terms).to.equal('my super terms')
127 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added') 129 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
130 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
128 expect(data.instance.customizations.javascript).to.equal('alert("coucou")') 131 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
129 expect(data.instance.customizations.css).to.equal('body { background-color: red; }') 132 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
130 expect(data.cache.previews.size).to.equal(2) 133 expect(data.cache.previews.size).to.equal(2)
@@ -156,6 +159,7 @@ describe('Test config', function () {
156 expect(data.instance.description).to.equal('my super description') 159 expect(data.instance.description).to.equal('my super description')
157 expect(data.instance.terms).to.equal('my super terms') 160 expect(data.instance.terms).to.equal('my super terms')
158 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added') 161 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
162 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
159 expect(data.instance.customizations.javascript).to.equal('alert("coucou")') 163 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
160 expect(data.instance.customizations.css).to.equal('body { background-color: red; }') 164 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
161 expect(data.cache.previews.size).to.equal(2) 165 expect(data.cache.previews.size).to.equal(2)
@@ -198,6 +202,7 @@ describe('Test config', function () {
198 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!') 202 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
199 expect(data.instance.terms).to.equal('No terms for now.') 203 expect(data.instance.terms).to.equal('No terms for now.')
200 expect(data.instance.defaultClientRoute).to.equal('/videos/trending') 204 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
205 expect(data.instance.defaultNSFWPolicy).to.equal('display')
201 expect(data.instance.customizations.css).to.be.empty 206 expect(data.instance.customizations.css).to.be.empty
202 expect(data.instance.customizations.javascript).to.be.empty 207 expect(data.instance.customizations.javascript).to.be.empty
203 expect(data.cache.previews.size).to.equal(1) 208 expect(data.cache.previews.size).to.equal(1)
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index b6ab4f660..1192ef9e4 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -168,7 +168,7 @@ describe('Test users', function () {
168 168
169 expect(user.username).to.equal('user_1') 169 expect(user.username).to.equal('user_1')
170 expect(user.email).to.equal('user_1@example.com') 170 expect(user.email).to.equal('user_1@example.com')
171 expect(user.displayNSFW).to.be.false 171 expect(user.nsfwPolicy).to.equal('display')
172 expect(user.videoQuota).to.equal(2 * 1024 * 1024) 172 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
173 expect(user.roleLabel).to.equal('User') 173 expect(user.roleLabel).to.equal('User')
174 expect(user.id).to.be.a('number') 174 expect(user.id).to.be.a('number')
@@ -215,12 +215,12 @@ describe('Test users', function () {
215 const user = users[ 0 ] 215 const user = users[ 0 ]
216 expect(user.username).to.equal('user_1') 216 expect(user.username).to.equal('user_1')
217 expect(user.email).to.equal('user_1@example.com') 217 expect(user.email).to.equal('user_1@example.com')
218 expect(user.displayNSFW).to.be.false 218 expect(user.nsfwPolicy).to.equal('display')
219 219
220 const rootUser = users[ 1 ] 220 const rootUser = users[ 1 ]
221 expect(rootUser.username).to.equal('root') 221 expect(rootUser.username).to.equal('root')
222 expect(rootUser.email).to.equal('admin1@example.com') 222 expect(rootUser.email).to.equal('admin1@example.com')
223 expect(rootUser.displayNSFW).to.be.false 223 expect(user.nsfwPolicy).to.equal('display')
224 224
225 userId = user.id 225 userId = user.id
226 }) 226 })
@@ -239,7 +239,7 @@ describe('Test users', function () {
239 expect(user.username).to.equal('root') 239 expect(user.username).to.equal('root')
240 expect(user.email).to.equal('admin1@example.com') 240 expect(user.email).to.equal('admin1@example.com')
241 expect(user.roleLabel).to.equal('Administrator') 241 expect(user.roleLabel).to.equal('Administrator')
242 expect(user.displayNSFW).to.be.false 242 expect(user.nsfwPolicy).to.equal('display')
243 }) 243 })
244 244
245 it('Should list only the first user by username desc', async function () { 245 it('Should list only the first user by username desc', async function () {
@@ -254,7 +254,7 @@ describe('Test users', function () {
254 const user = users[ 0 ] 254 const user = users[ 0 ]
255 expect(user.username).to.equal('user_1') 255 expect(user.username).to.equal('user_1')
256 expect(user.email).to.equal('user_1@example.com') 256 expect(user.email).to.equal('user_1@example.com')
257 expect(user.displayNSFW).to.be.false 257 expect(user.nsfwPolicy).to.equal('display')
258 }) 258 })
259 259
260 it('Should list only the second user by createdAt desc', async function () { 260 it('Should list only the second user by createdAt desc', async function () {
@@ -269,7 +269,7 @@ describe('Test users', function () {
269 const user = users[ 0 ] 269 const user = users[ 0 ]
270 expect(user.username).to.equal('user_1') 270 expect(user.username).to.equal('user_1')
271 expect(user.email).to.equal('user_1@example.com') 271 expect(user.email).to.equal('user_1@example.com')
272 expect(user.displayNSFW).to.be.false 272 expect(user.nsfwPolicy).to.equal('display')
273 }) 273 })
274 274
275 it('Should list all the users by createdAt asc', async function () { 275 it('Should list all the users by createdAt asc', async function () {
@@ -283,11 +283,11 @@ describe('Test users', function () {
283 283
284 expect(users[ 0 ].username).to.equal('root') 284 expect(users[ 0 ].username).to.equal('root')
285 expect(users[ 0 ].email).to.equal('admin1@example.com') 285 expect(users[ 0 ].email).to.equal('admin1@example.com')
286 expect(users[ 0 ].displayNSFW).to.be.false 286 expect(users[ 0 ].nsfwPolicy).to.equal('display')
287 287
288 expect(users[ 1 ].username).to.equal('user_1') 288 expect(users[ 1 ].username).to.equal('user_1')
289 expect(users[ 1 ].email).to.equal('user_1@example.com') 289 expect(users[ 1 ].email).to.equal('user_1@example.com')
290 expect(users[ 1 ].displayNSFW).to.be.false 290 expect(users[ 1 ].nsfwPolicy).to.equal('display')
291 }) 291 })
292 292
293 it('Should update my password', async function () { 293 it('Should update my password', async function () {
@@ -305,7 +305,7 @@ describe('Test users', function () {
305 await updateMyUser({ 305 await updateMyUser({
306 url: server.url, 306 url: server.url,
307 accessToken: accessTokenUser, 307 accessToken: accessTokenUser,
308 displayNSFW: true 308 nsfwPolicy: 'do_not_list'
309 }) 309 })
310 310
311 const res = await getMyUserInformation(server.url, accessTokenUser) 311 const res = await getMyUserInformation(server.url, accessTokenUser)
@@ -313,7 +313,7 @@ describe('Test users', function () {
313 313
314 expect(user.username).to.equal('user_1') 314 expect(user.username).to.equal('user_1')
315 expect(user.email).to.equal('user_1@example.com') 315 expect(user.email).to.equal('user_1@example.com')
316 expect(user.displayNSFW).to.be.ok 316 expect(user.nsfwPolicy).to.equal('do_not_list')
317 expect(user.videoQuota).to.equal(2 * 1024 * 1024) 317 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
318 expect(user.id).to.be.a('number') 318 expect(user.id).to.be.a('number')
319 expect(user.account.description).to.be.null 319 expect(user.account.description).to.be.null
@@ -344,7 +344,7 @@ describe('Test users', function () {
344 344
345 expect(user.username).to.equal('user_1') 345 expect(user.username).to.equal('user_1')
346 expect(user.email).to.equal('updated@example.com') 346 expect(user.email).to.equal('updated@example.com')
347 expect(user.displayNSFW).to.be.ok 347 expect(user.nsfwPolicy).to.equal('do_not_list')
348 expect(user.videoQuota).to.equal(2 * 1024 * 1024) 348 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
349 expect(user.id).to.be.a('number') 349 expect(user.id).to.be.a('number')
350 expect(user.account.description).to.be.null 350 expect(user.account.description).to.be.null
@@ -377,7 +377,7 @@ describe('Test users', function () {
377 377
378 expect(user.username).to.equal('user_1') 378 expect(user.username).to.equal('user_1')
379 expect(user.email).to.equal('updated@example.com') 379 expect(user.email).to.equal('updated@example.com')
380 expect(user.displayNSFW).to.be.ok 380 expect(user.nsfwPolicy).to.equal('do_not_list')
381 expect(user.videoQuota).to.equal(2 * 1024 * 1024) 381 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
382 expect(user.id).to.be.a('number') 382 expect(user.id).to.be.a('number')
383 expect(user.account.description).to.equal('my super description updated') 383 expect(user.account.description).to.equal('my super description updated')
@@ -398,7 +398,7 @@ describe('Test users', function () {
398 398
399 expect(user.username).to.equal('user_1') 399 expect(user.username).to.equal('user_1')
400 expect(user.email).to.equal('updated2@example.com') 400 expect(user.email).to.equal('updated2@example.com')
401 expect(user.displayNSFW).to.be.ok 401 expect(user.nsfwPolicy).to.equal('do_not_list')
402 expect(user.videoQuota).to.equal(42) 402 expect(user.videoQuota).to.equal(42)
403 expect(user.roleLabel).to.equal('Moderator') 403 expect(user.roleLabel).to.equal('Moderator')
404 expect(user.id).to.be.a('number') 404 expect(user.id).to.be.a('number')
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts
new file mode 100644
index 000000000..4e5ab11ce
--- /dev/null
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -0,0 +1,197 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils/index'
6import { userLogin } from '../../utils/users/login'
7import { createUser } from '../../utils/users/users'
8import { getMyVideos } from '../../utils/videos/videos'
9import {
10 getConfig, getCustomConfig,
11 getMyUserInformation,
12 getVideosListWithToken,
13 runServer,
14 searchVideo,
15 searchVideoWithToken, updateCustomConfig,
16 updateMyUser
17} from '../../utils'
18import { ServerConfig } from '../../../../shared/models'
19import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
20
21const expect = chai.expect
22
23describe('Test video NSFW policy', function () {
24 let server: ServerInfo
25 let userAccessToken: string
26 let customConfig: CustomConfig
27
28 before(async function () {
29 this.timeout(50000)
30
31 await flushTests()
32 server = await runServer(1)
33
34 // Get the access tokens
35 await setAccessTokensToServers([ server ])
36
37 {
38 const attributes = { name: 'nsfw', nsfw: true }
39 await uploadVideo(server.url, server.accessToken, attributes)
40 }
41
42 {
43 const attributes = { name: 'normal', nsfw: false }
44 await uploadVideo(server.url, server.accessToken, attributes)
45 }
46
47 {
48 const res = await getCustomConfig(server.url, server.accessToken)
49 customConfig = res.body
50 }
51 })
52
53 describe('Instance default NSFW policy', function () {
54 it('Should display NSFW videos with display default NSFW policy', async function () {
55 const resConfig = await getConfig(server.url)
56 const serverConfig: ServerConfig = resConfig.body
57 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display')
58
59 for (const res of [ await getVideosList(server.url), await searchVideo(server.url, 'n') ]) {
60 expect(res.body.total).to.equal(2)
61
62 const videos = res.body.data
63 expect(videos).to.have.lengthOf(2)
64 expect(videos[ 0 ].name).to.equal('normal')
65 expect(videos[ 1 ].name).to.equal('nsfw')
66 }
67 })
68
69 it('Should not display NSFW videos with do_not_list default NSFW policy', async function () {
70 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
71 await updateCustomConfig(server.url, server.accessToken, customConfig)
72
73 const resConfig = await getConfig(server.url)
74 const serverConfig: ServerConfig = resConfig.body
75 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list')
76
77 for (const res of [ await getVideosList(server.url), await searchVideo(server.url, 'n') ]) {
78 expect(res.body.total).to.equal(1)
79
80 const videos = res.body.data
81 expect(videos).to.have.lengthOf(1)
82 expect(videos[ 0 ].name).to.equal('normal')
83 }
84 })
85
86 it('Should display NSFW videos with blur default NSFW policy', async function () {
87 customConfig.instance.defaultNSFWPolicy = 'blur'
88 await updateCustomConfig(server.url, server.accessToken, customConfig)
89
90 const resConfig = await getConfig(server.url)
91 const serverConfig: ServerConfig = resConfig.body
92 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur')
93
94 for (const res of [ await getVideosList(server.url), await searchVideo(server.url, 'n') ]) {
95 expect(res.body.total).to.equal(2)
96
97 const videos = res.body.data
98 expect(videos).to.have.lengthOf(2)
99 expect(videos[ 0 ].name).to.equal('normal')
100 expect(videos[ 1 ].name).to.equal('nsfw')
101 }
102 })
103 })
104
105 describe('User NSFW policy', function () {
106
107 it('Should create a user having the default nsfw policy', async function () {
108 const username = 'user1'
109 const password = 'my super password'
110 await createUser(server.url, server.accessToken, username, password)
111
112 userAccessToken = await userLogin(server, { username, password })
113
114 const res = await getMyUserInformation(server.url, userAccessToken)
115 const user = res.body
116
117 expect(user.nsfwPolicy).to.equal('blur')
118 })
119
120 it('Should display NSFW videos with blur user NSFW policy', async function () {
121 const results = [
122 await getVideosListWithToken(server.url, userAccessToken),
123 await searchVideoWithToken(server.url, 'n', userAccessToken)
124 ]
125
126 for (const res of results) {
127 expect(res.body.total).to.equal(2)
128
129 const videos = res.body.data
130 expect(videos).to.have.lengthOf(2)
131 expect(videos[ 0 ].name).to.equal('normal')
132 expect(videos[ 1 ].name).to.equal('nsfw')
133 }
134 })
135
136 it('Should display NSFW videos with display user NSFW policy', async function () {
137 await updateMyUser({
138 url: server.url,
139 accessToken: server.accessToken,
140 nsfwPolicy: 'display'
141 })
142
143 const results = [
144 await getVideosListWithToken(server.url, server.accessToken),
145 await searchVideoWithToken(server.url, 'n', server.accessToken)
146 ]
147
148 for (const res of results) {
149 expect(res.body.total).to.equal(2)
150
151 const videos = res.body.data
152 expect(videos).to.have.lengthOf(2)
153 expect(videos[ 0 ].name).to.equal('normal')
154 expect(videos[ 1 ].name).to.equal('nsfw')
155 }
156 })
157
158 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
159 await updateMyUser({
160 url: server.url,
161 accessToken: server.accessToken,
162 nsfwPolicy: 'do_not_list'
163 })
164
165 const results = [
166 await getVideosListWithToken(server.url, server.accessToken),
167 await searchVideoWithToken(server.url, 'n', server.accessToken)
168 ]
169 for (const res of results) {
170 expect(res.body.total).to.equal(1)
171
172 const videos = res.body.data
173 expect(videos).to.have.lengthOf(1)
174 expect(videos[ 0 ].name).to.equal('normal')
175 }
176 })
177
178 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () {
179 const res = await getMyVideos(server.url, server.accessToken, 0, 5)
180 expect(res.body.total).to.equal(2)
181
182 const videos = res.body.data
183 expect(videos).to.have.lengthOf(2)
184 expect(videos[ 0 ].name).to.equal('normal')
185 expect(videos[ 1 ].name).to.equal('nsfw')
186 })
187 })
188
189 after(async function () {
190 killallServers([ server ])
191
192 // Keep the logs if the test failed
193 if (this['ok']) {
194 await flushTests()
195 }
196 })
197})
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts
index daf731a14..fc6b26c50 100644
--- a/server/tests/utils/users/users.ts
+++ b/server/tests/utils/users/users.ts
@@ -3,6 +3,7 @@ import * as request from 'supertest'
3import { makePostBodyRequest, makeUploadRequest, makePutBodyRequest } from '../' 3import { makePostBodyRequest, makeUploadRequest, makePutBodyRequest } from '../'
4 4
5import { UserRole } from '../../../../shared/index' 5import { UserRole } from '../../../../shared/index'
6import { NSFWPolicyType } from '../../../../shared/models/videos/nsfw-policy.type'
6 7
7function createUser ( 8function createUser (
8 url: string, 9 url: string,
@@ -128,7 +129,7 @@ function updateMyUser (options: {
128 url: string 129 url: string
129 accessToken: string, 130 accessToken: string,
130 newPassword?: string, 131 newPassword?: string,
131 displayNSFW?: boolean, 132 nsfwPolicy?: NSFWPolicyType,
132 email?: string, 133 email?: string,
133 autoPlayVideo?: boolean 134 autoPlayVideo?: boolean
134 description?: string 135 description?: string
@@ -137,7 +138,7 @@ function updateMyUser (options: {
137 138
138 const toSend = {} 139 const toSend = {}
139 if (options.newPassword !== undefined && options.newPassword !== null) toSend['password'] = options.newPassword 140 if (options.newPassword !== undefined && options.newPassword !== null) toSend['password'] = options.newPassword
140 if (options.displayNSFW !== undefined && options.displayNSFW !== null) toSend['displayNSFW'] = options.displayNSFW 141 if (options.nsfwPolicy !== undefined && options.nsfwPolicy !== null) toSend['nsfwPolicy'] = options.nsfwPolicy
141 if (options.autoPlayVideo !== undefined && options.autoPlayVideo !== null) toSend['autoPlayVideo'] = options.autoPlayVideo 142 if (options.autoPlayVideo !== undefined && options.autoPlayVideo !== null) toSend['autoPlayVideo'] = options.autoPlayVideo
142 if (options.email !== undefined && options.email !== null) toSend['email'] = options.email 143 if (options.email !== undefined && options.email !== null) toSend['email'] = options.email
143 if (options.description !== undefined && options.description !== null) toSend['description'] = options.description 144 if (options.description !== undefined && options.description !== null) toSend['description'] = options.description
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index 01e7fa5a1..5e186147e 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -128,6 +128,18 @@ function getVideosList (url: string) {
128 .expect('Content-Type', /json/) 128 .expect('Content-Type', /json/)
129} 129}
130 130
131function getVideosListWithToken (url: string, token: string) {
132 const path = '/api/v1/videos'
133
134 return request(url)
135 .get(path)
136 .set('Authorization', 'Bearer ' + token)
137 .query({ sort: 'name' })
138 .set('Accept', 'application/json')
139 .expect(200)
140 .expect('Content-Type', /json/)
141}
142
131function getLocalVideos (url: string) { 143function getLocalVideos (url: string) {
132 const path = '/api/v1/videos' 144 const path = '/api/v1/videos'
133 145
@@ -202,6 +214,18 @@ function searchVideo (url: string, search: string) {
202 .expect('Content-Type', /json/) 214 .expect('Content-Type', /json/)
203} 215}
204 216
217function searchVideoWithToken (url: string, search: string, token: string) {
218 const path = '/api/v1/videos'
219 const req = request(url)
220 .get(path + '/search')
221 .set('Authorization', 'Bearer ' + token)
222 .query({ search })
223 .set('Accept', 'application/json')
224
225 return req.expect(200)
226 .expect('Content-Type', /json/)
227}
228
205function searchVideoWithPagination (url: string, search: string, start: number, count: number, sort?: string) { 229function searchVideoWithPagination (url: string, search: string, start: number, count: number, sort?: string) {
206 const path = '/api/v1/videos' 230 const path = '/api/v1/videos'
207 231
@@ -418,6 +442,8 @@ async function completeVideoCheck (
418 expect(video.licence.label).to.equal(VIDEO_LICENCES[attributes.licence] || 'Unknown') 442 expect(video.licence.label).to.equal(VIDEO_LICENCES[attributes.licence] || 'Unknown')
419 expect(video.language.id).to.equal(attributes.language) 443 expect(video.language.id).to.equal(attributes.language)
420 expect(video.language.label).to.equal(VIDEO_LANGUAGES[attributes.language] || 'Unknown') 444 expect(video.language.label).to.equal(VIDEO_LANGUAGES[attributes.language] || 'Unknown')
445 expect(video.privacy.id).to.deep.equal(attributes.privacy)
446 expect(video.privacy.label).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy])
421 expect(video.nsfw).to.equal(attributes.nsfw) 447 expect(video.nsfw).to.equal(attributes.nsfw)
422 expect(video.description).to.equal(attributes.description) 448 expect(video.description).to.equal(attributes.description)
423 expect(video.account.host).to.equal(attributes.account.host) 449 expect(video.account.host).to.equal(attributes.account.host)
@@ -435,8 +461,6 @@ async function completeVideoCheck (
435 461
436 expect(videoDetails.files).to.have.lengthOf(attributes.files.length) 462 expect(videoDetails.files).to.have.lengthOf(attributes.files.length)
437 expect(videoDetails.tags).to.deep.equal(attributes.tags) 463 expect(videoDetails.tags).to.deep.equal(attributes.tags)
438 expect(videoDetails.privacy.id).to.deep.equal(attributes.privacy)
439 expect(videoDetails.privacy.label).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy])
440 expect(videoDetails.account.name).to.equal(attributes.account.name) 464 expect(videoDetails.account.name).to.equal(attributes.account.name)
441 expect(videoDetails.account.host).to.equal(attributes.account.host) 465 expect(videoDetails.account.host).to.equal(attributes.account.host)
442 expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled) 466 expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled)
@@ -490,6 +514,7 @@ export {
490 getVideoPrivacies, 514 getVideoPrivacies,
491 getVideoLanguages, 515 getVideoLanguages,
492 getMyVideos, 516 getMyVideos,
517 searchVideoWithToken,
493 getVideo, 518 getVideo,
494 getVideoWithToken, 519 getVideoWithToken,
495 getVideosList, 520 getVideosList,
@@ -499,6 +524,7 @@ export {
499 searchVideo, 524 searchVideo,
500 searchVideoWithPagination, 525 searchVideoWithPagination,
501 searchVideoWithSort, 526 searchVideoWithSort,
527 getVideosListWithToken,
502 uploadVideo, 528 uploadVideo,
503 updateVideo, 529 updateVideo,
504 rateVideo, 530 rateVideo,