aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/check-params/search.ts122
-rw-r--r--server/tests/api/index-fast.ts1
-rw-r--r--server/tests/api/search/search-videos.ts299
-rw-r--r--server/tests/api/videos/single-server.ts153
-rw-r--r--server/tests/api/videos/video-nsfw.ts30
6 files changed, 459 insertions, 147 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index c0e0302df..820dde889 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -10,3 +10,4 @@ import './video-captions'
10import './video-channels' 10import './video-channels'
11import './video-comments' 11import './video-comments'
12import './videos' 12import './videos'
13import './search'
diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts
new file mode 100644
index 000000000..d35eac7fe
--- /dev/null
+++ b/server/tests/api/check-params/search.ts
@@ -0,0 +1,122 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import { flushTests, immutableAssign, killallServers, makeGetRequest, runServer, ServerInfo } from '../../utils'
6import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
7
8describe('Test videos API validator', function () {
9 const path = '/api/v1/search/videos/'
10 let server: ServerInfo
11
12 // ---------------------------------------------------------------
13
14 before(async function () {
15 this.timeout(30000)
16
17 await flushTests()
18
19 server = await runServer(1)
20 })
21
22 describe('When searching videos', function () {
23 const query = {
24 search: 'coucou'
25 }
26
27 it('Should fail with a bad start pagination', async function () {
28 await checkBadStartPagination(server.url, path, null, query)
29 })
30
31 it('Should fail with a bad count pagination', async function () {
32 await checkBadCountPagination(server.url, path, null, query)
33 })
34
35 it('Should fail with an incorrect sort', async function () {
36 await checkBadSortPagination(server.url, path, null, query)
37 })
38
39 it('Should success with the correct parameters', async function () {
40 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
41 })
42
43 it('Should fail with an invalid category', async function () {
44 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] })
45 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
46
47 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
48 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
49 })
50
51 it('Should succeed with a valid category', async function () {
52 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] })
53 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
54
55 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
56 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
57 })
58
59 it('Should fail with an invalid licence', async function () {
60 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] })
61 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
62
63 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
64 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
65 })
66
67 it('Should succeed with a valid licence', async function () {
68 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] })
69 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
70
71 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
72 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
73 })
74
75 it('Should succeed with a valid language', async function () {
76 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] })
77 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
78
79 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
80 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
81 })
82
83 it('Should succeed with valid tags', async function () {
84 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] })
85 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
86
87 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
88 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
89
90 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
91 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 })
92
93 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
94 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 })
95 })
96
97 it('Should fail with invalid durations', async function () {
98 const customQuery1 = immutableAssign(query, { durationMin: 'hello' })
99 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
100
101 const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
102 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
103 })
104
105 it('Should fail with invalid dates', async function () {
106 const customQuery1 = immutableAssign(query, { startDate: 'hello' })
107 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
108
109 const customQuery2 = immutableAssign(query, { endDate: 'hello' })
110 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
111 })
112 })
113
114 after(async function () {
115 killallServers([ server ])
116
117 // Keep the logs if the test failed
118 if (this['ok']) {
119 await flushTests()
120 }
121 })
122})
diff --git a/server/tests/api/index-fast.ts b/server/tests/api/index-fast.ts
index d530dfc06..531a09b82 100644
--- a/server/tests/api/index-fast.ts
+++ b/server/tests/api/index-fast.ts
@@ -14,3 +14,4 @@ import './videos/services'
14import './server/email' 14import './server/email'
15import './server/config' 15import './server/config'
16import './server/reverse-proxy' 16import './server/reverse-proxy'
17import './search/search-videos'
diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts
new file mode 100644
index 000000000..7fc133b46
--- /dev/null
+++ b/server/tests/api/search/search-videos.ts
@@ -0,0 +1,299 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 advancedVideosSearch,
7 flushTests,
8 killallServers,
9 runServer,
10 searchVideo,
11 ServerInfo,
12 setAccessTokensToServers,
13 uploadVideo,
14 wait,
15 immutableAssign
16} from '../../utils'
17
18const expect = chai.expect
19
20describe('Test a videos search', function () {
21 let server: ServerInfo = null
22 let startDate: string
23
24 before(async function () {
25 this.timeout(30000)
26
27 await flushTests()
28
29 server = await runServer(1)
30
31 await setAccessTokensToServers([ server ])
32
33 {
34 const attributes1 = {
35 name: '1111 2222 3333',
36 fixture: '60fps_720p_small.mp4', // 2 seconds
37 category: 1,
38 licence: 1,
39 nsfw: false,
40 language: 'fr'
41 }
42 await uploadVideo(server.url, server.accessToken, attributes1)
43
44 const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' })
45 await uploadVideo(server.url, server.accessToken, attributes2)
46
47 const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: 'en' })
48 await uploadVideo(server.url, server.accessToken, attributes3)
49
50 const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true })
51 await uploadVideo(server.url, server.accessToken, attributes4)
52
53 await wait(1000)
54
55 startDate = new Date().toISOString()
56
57 const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2 })
58 await uploadVideo(server.url, server.accessToken, attributes5)
59
60 const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2 '] })
61 await uploadVideo(server.url, server.accessToken, attributes6)
62
63 const attributes7 = immutableAssign(attributes1, { name: attributes1.name + ' - 7' })
64 await uploadVideo(server.url, server.accessToken, attributes7)
65
66 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 })
67 await uploadVideo(server.url, server.accessToken, attributes8)
68 }
69
70 {
71 const attributes = {
72 name: '3333 4444 5555',
73 fixture: 'video_short.mp4',
74 category: 2,
75 licence: 2,
76 language: 'en'
77 }
78 await uploadVideo(server.url, server.accessToken, attributes)
79
80 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' }))
81 }
82
83 {
84 const attributes = {
85 name: '6666 7777 8888',
86 fixture: 'video_short.mp4',
87 category: 3,
88 licence: 3,
89 language: 'pl'
90 }
91 await uploadVideo(server.url, server.accessToken, attributes)
92 }
93
94 {
95 const attributes1 = {
96 name: '9999',
97 tags: [ 'aaaa', 'bbbb', 'cccc' ],
98 category: 1
99 }
100 await uploadVideo(server.url, server.accessToken, attributes1)
101 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
102
103 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] }))
104 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] }))
105 }
106 })
107
108 it('Should make a simple search and not have results', async function () {
109 const res = await searchVideo(server.url, 'abc')
110
111 expect(res.body.total).to.equal(0)
112 expect(res.body.data).to.have.lengthOf(0)
113 })
114
115 it('Should make a simple search and have results', async function () {
116 const res = await searchVideo(server.url, '4444 5555 duplicate')
117
118 expect(res.body.total).to.equal(2)
119
120 const videos = res.body.data
121 expect(videos).to.have.lengthOf(2)
122
123 // bestmatch
124 expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
125 expect(videos[1].name).to.equal('3333 4444 5555')
126 })
127
128 it('Should search by tags (one of)', async function () {
129 const query = {
130 search: '9999',
131 categoryOneOf: [ 1 ],
132 tagsOneOf: [ 'aaaa', 'ffff' ]
133 }
134 const res1 = await advancedVideosSearch(server.url, query)
135 expect(res1.body.total).to.equal(2)
136
137 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] }))
138 expect(res2.body.total).to.equal(0)
139 })
140
141 it('Should search by tags (all of)', async function () {
142 const query = {
143 search: '9999',
144 categoryOneOf: [ 1 ],
145 tagsAllOf: [ 'cccc' ]
146 }
147 const res1 = await advancedVideosSearch(server.url, query)
148 expect(res1.body.total).to.equal(2)
149
150 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blabla' ] }))
151 expect(res2.body.total).to.equal(0)
152
153 const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'cccc' ] }))
154 expect(res3.body.total).to.equal(1)
155 })
156
157 it('Should search by category', async function () {
158 const query = {
159 search: '6666',
160 categoryOneOf: [ 3 ]
161 }
162 const res1 = await advancedVideosSearch(server.url, query)
163 expect(res1.body.total).to.equal(1)
164 expect(res1.body.data[0].name).to.equal('6666 7777 8888')
165
166 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] }))
167 expect(res2.body.total).to.equal(0)
168 })
169
170 it('Should search by licence', async function () {
171 const query = {
172 search: '4444 5555',
173 licenceOneOf: [ 2 ]
174 }
175 const res1 = await advancedVideosSearch(server.url, query)
176 expect(res1.body.total).to.equal(2)
177 expect(res1.body.data[0].name).to.equal('3333 4444 5555')
178 expect(res1.body.data[1].name).to.equal('3333 4444 5555 duplicate')
179
180 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] }))
181 expect(res2.body.total).to.equal(0)
182 })
183
184 it('Should search by languages', async function () {
185 const query = {
186 search: '1111 2222 3333',
187 languageOneOf: [ 'pl', 'en' ]
188 }
189 const res1 = await advancedVideosSearch(server.url, query)
190 expect(res1.body.total).to.equal(2)
191 expect(res1.body.data[0].name).to.equal('1111 2222 3333 - 3')
192 expect(res1.body.data[1].name).to.equal('1111 2222 3333 - 4')
193
194 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] }))
195 expect(res2.body.total).to.equal(0)
196 })
197
198 it('Should search by start date', async function () {
199 const query = {
200 search: '1111 2222 3333',
201 startDate
202 }
203
204 const res = await advancedVideosSearch(server.url, query)
205 expect(res.body.total).to.equal(4)
206
207 const videos = res.body.data
208 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
209 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
210 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
211 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
212 })
213
214 it('Should make an advanced search', async function () {
215 const query = {
216 search: '1111 2222 3333',
217 languageOneOf: [ 'pl', 'fr' ],
218 durationMax: 4,
219 nsfw: false,
220 licenceOneOf: [ 1, 4 ]
221 }
222
223 const res = await advancedVideosSearch(server.url, query)
224 expect(res.body.total).to.equal(4)
225
226 const videos = res.body.data
227 expect(videos[0].name).to.equal('1111 2222 3333')
228 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
229 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
230 expect(videos[3].name).to.equal('1111 2222 3333 - 8')
231 })
232
233 it('Should make an advanced search and sort results', async function () {
234 const query = {
235 search: '1111 2222 3333',
236 languageOneOf: [ 'pl', 'fr' ],
237 durationMax: 4,
238 nsfw: false,
239 licenceOneOf: [ 1, 4 ],
240 sort: '-name'
241 }
242
243 const res = await advancedVideosSearch(server.url, query)
244 expect(res.body.total).to.equal(4)
245
246 const videos = res.body.data
247 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
248 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
249 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
250 expect(videos[3].name).to.equal('1111 2222 3333')
251 })
252
253 it('Should make an advanced search and only show the first result', async function () {
254 const query = {
255 search: '1111 2222 3333',
256 languageOneOf: [ 'pl', 'fr' ],
257 durationMax: 4,
258 nsfw: false,
259 licenceOneOf: [ 1, 4 ],
260 sort: '-name',
261 start: 0,
262 count: 1
263 }
264
265 const res = await advancedVideosSearch(server.url, query)
266 expect(res.body.total).to.equal(4)
267
268 const videos = res.body.data
269 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
270 })
271
272 it('Should make an advanced search and only show the last result', async function () {
273 const query = {
274 search: '1111 2222 3333',
275 languageOneOf: [ 'pl', 'fr' ],
276 durationMax: 4,
277 nsfw: false,
278 licenceOneOf: [ 1, 4 ],
279 sort: '-name',
280 start: 3,
281 count: 1
282 }
283
284 const res = await advancedVideosSearch(server.url, query)
285 expect(res.body.total).to.equal(4)
286
287 const videos = res.body.data
288 expect(videos[0].name).to.equal('1111 2222 3333')
289 })
290
291 after(async function () {
292 killallServers([ server ])
293
294 // Keep the logs if the test failed
295 if (this['ok']) {
296 await flushTests()
297 }
298 })
299})
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index d8af94e8f..ba4920d1b 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -16,13 +16,11 @@ import {
16 getVideosList, 16 getVideosList,
17 getVideosListPagination, 17 getVideosListPagination,
18 getVideosListSort, 18 getVideosListSort,
19 getVideosWithFilters,
19 killallServers, 20 killallServers,
20 rateVideo, 21 rateVideo,
21 removeVideo, 22 removeVideo,
22 runServer, 23 runServer,
23 searchVideo,
24 searchVideoWithPagination,
25 searchVideoWithSort,
26 ServerInfo, 24 ServerInfo,
27 setAccessTokensToServers, 25 setAccessTokensToServers,
28 testImage, 26 testImage,
@@ -218,72 +216,6 @@ describe('Test a single server', function () {
218 expect(video.views).to.equal(3) 216 expect(video.views).to.equal(3)
219 }) 217 })
220 218
221 it('Should search the video by name', async function () {
222 const res = await searchVideo(server.url, 'my')
223
224 expect(res.body.total).to.equal(1)
225 expect(res.body.data).to.be.an('array')
226 expect(res.body.data.length).to.equal(1)
227
228 const video = res.body.data[0]
229 await completeVideoCheck(server.url, video, getCheckAttributes)
230 })
231
232 // Not implemented yet
233 // it('Should search the video by tag', async function () {
234 // const res = await searchVideo(server.url, 'tag1')
235 //
236 // expect(res.body.total).to.equal(1)
237 // expect(res.body.data).to.be.an('array')
238 // expect(res.body.data.length).to.equal(1)
239 //
240 // const video = res.body.data[0]
241 // expect(video.name).to.equal('my super name')
242 // expect(video.category).to.equal(2)
243 // expect(video.categoryLabel).to.equal('Films')
244 // expect(video.licence).to.equal(6)
245 // expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
246 // expect(video.language).to.equal('zh')
247 // expect(video.languageLabel).to.equal('Chinese')
248 // expect(video.nsfw).to.be.ok
249 // expect(video.description).to.equal('my super description')
250 // expect(video.account.name).to.equal('root')
251 // expect(video.account.host).to.equal('localhost:9001')
252 // expect(video.isLocal).to.be.true
253 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
254 // expect(dateIsValid(video.createdAt)).to.be.true
255 // expect(dateIsValid(video.updatedAt)).to.be.true
256 //
257 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
258 // expect(test).to.equal(true)
259 // })
260
261 it('Should not find a search by name', async function () {
262 const res = await searchVideo(server.url, 'hello')
263
264 expect(res.body.total).to.equal(0)
265 expect(res.body.data).to.be.an('array')
266 expect(res.body.data.length).to.equal(0)
267 })
268
269 // Not implemented yet
270 // it('Should not find a search by author', async function () {
271 // const res = await searchVideo(server.url, 'hello')
272 //
273 // expect(res.body.total).to.equal(0)
274 // expect(res.body.data).to.be.an('array')
275 // expect(res.body.data.length).to.equal(0)
276 // })
277 //
278 // Not implemented yet
279 // it('Should not find a search by tag', async function () {
280 // const res = await searchVideo(server.url, 'hello')
281 //
282 // expect(res.body.total).to.equal(0)
283 // expect(res.body.data).to.be.an('array')
284 // expect(res.body.data.length).to.equal(0)
285 // })
286
287 it('Should remove the video', async function () { 219 it('Should remove the video', async function () {
288 await removeVideo(server.url, server.accessToken, videoId) 220 await removeVideo(server.url, server.accessToken, videoId)
289 221
@@ -386,65 +318,6 @@ describe('Test a single server', function () {
386 expect(videos[0].name).to.equal(videosListBase[5].name) 318 expect(videos[0].name).to.equal(videosListBase[5].name)
387 }) 319 })
388 320
389 it('Should search the first video', async function () {
390 const res = await searchVideoWithPagination(server.url, 'webm', 0, 1, 'name')
391
392 const videos = res.body.data
393 expect(res.body.total).to.equal(4)
394 expect(videos.length).to.equal(1)
395 expect(videos[0].name).to.equal('video_short1.webm name')
396 })
397
398 it('Should search the last two videos', async function () {
399 const res = await searchVideoWithPagination(server.url, 'webm', 2, 2, 'name')
400
401 const videos = res.body.data
402 expect(res.body.total).to.equal(4)
403 expect(videos.length).to.equal(2)
404 expect(videos[0].name).to.equal('video_short3.webm name')
405 expect(videos[1].name).to.equal('video_short.webm name')
406 })
407
408 it('Should search all the webm videos', async function () {
409 const res = await searchVideoWithPagination(server.url, 'webm', 0, 15)
410
411 const videos = res.body.data
412 expect(res.body.total).to.equal(4)
413 expect(videos.length).to.equal(4)
414 })
415
416 // Not implemented yet
417 // it('Should search all the root author videos', async function () {
418 // const res = await searchVideoWithPagination(server.url, 'root', 0, 15)
419 //
420 // const videos = res.body.data
421 // expect(res.body.total).to.equal(6)
422 // expect(videos.length).to.equal(6)
423 // })
424
425 // Not implemented yet
426 // it('Should search all the 9001 port videos', async function () {
427 // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
428
429 // const videos = res.body.data
430 // expect(res.body.total).to.equal(6)
431 // expect(videos.length).to.equal(6)
432
433 // done()
434 // })
435 // })
436
437 // it('Should search all the localhost videos', async function () {
438 // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15)
439
440 // const videos = res.body.data
441 // expect(res.body.total).to.equal(6)
442 // expect(videos.length).to.equal(6)
443
444 // done()
445 // })
446 // })
447
448 it('Should list and sort by name in descending order', async function () { 321 it('Should list and sort by name in descending order', async function () {
449 const res = await getVideosListSort(server.url, '-name') 322 const res = await getVideosListSort(server.url, '-name')
450 323
@@ -457,21 +330,8 @@ describe('Test a single server', function () {
457 expect(videos[3].name).to.equal('video_short3.webm name') 330 expect(videos[3].name).to.equal('video_short3.webm name')
458 expect(videos[4].name).to.equal('video_short2.webm name') 331 expect(videos[4].name).to.equal('video_short2.webm name')
459 expect(videos[5].name).to.equal('video_short1.webm name') 332 expect(videos[5].name).to.equal('video_short1.webm name')
460 })
461
462 it('Should search and sort by name in ascending order', async function () {
463 const res = await searchVideoWithSort(server.url, 'webm', 'name')
464 333
465 const videos = res.body.data 334 videoId = videos[3].uuid
466 expect(res.body.total).to.equal(4)
467 expect(videos.length).to.equal(4)
468
469 expect(videos[0].name).to.equal('video_short1.webm name')
470 expect(videos[1].name).to.equal('video_short2.webm name')
471 expect(videos[2].name).to.equal('video_short3.webm name')
472 expect(videos[3].name).to.equal('video_short.webm name')
473
474 videoId = videos[2].id
475 }) 335 })
476 336
477 it('Should update a video', async function () { 337 it('Should update a video', async function () {
@@ -488,6 +348,15 @@ describe('Test a single server', function () {
488 await updateVideo(server.url, server.accessToken, videoId, attributes) 348 await updateVideo(server.url, server.accessToken, videoId, attributes)
489 }) 349 })
490 350
351 it('Should filter by tags and category', async function () {
352 const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 4 })
353 expect(res1.body.total).to.equal(1)
354 expect(res1.body.data[0].name).to.equal('my super video updated')
355
356 const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: 3 })
357 expect(res2.body.total).to.equal(0)
358 })
359
491 it('Should have the video updated', async function () { 360 it('Should have the video updated', async function () {
492 this.timeout(60000) 361 this.timeout(60000)
493 362
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts
index 6af0ca8af..38bdaa54e 100644
--- a/server/tests/api/videos/video-nsfw.ts
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -30,7 +30,7 @@ describe('Test video NSFW policy', function () {
30 let userAccessToken: string 30 let userAccessToken: string
31 let customConfig: CustomConfig 31 let customConfig: CustomConfig
32 32
33 function getVideosFunctions (token?: string) { 33 function getVideosFunctions (token?: string, query = {}) {
34 return getMyUserInformation(server.url, server.accessToken) 34 return getMyUserInformation(server.url, server.accessToken)
35 .then(res => { 35 .then(res => {
36 const user: User = res.body 36 const user: User = res.body
@@ -39,10 +39,10 @@ describe('Test video NSFW policy', function () {
39 39
40 if (token) { 40 if (token) {
41 return Promise.all([ 41 return Promise.all([
42 getVideosListWithToken(server.url, token), 42 getVideosListWithToken(server.url, token, query),
43 searchVideoWithToken(server.url, 'n', token), 43 searchVideoWithToken(server.url, 'n', token, query),
44 getAccountVideos(server.url, token, accountName, 0, 5), 44 getAccountVideos(server.url, token, accountName, 0, 5, undefined, query),
45 getVideoChannelVideos(server.url, token, videoChannelUUID, 0, 5) 45 getVideoChannelVideos(server.url, token, videoChannelUUID, 0, 5, undefined, query)
46 ]) 46 ])
47 } 47 }
48 48
@@ -200,6 +200,26 @@ describe('Test video NSFW policy', function () {
200 expect(videos[ 0 ].name).to.equal('normal') 200 expect(videos[ 0 ].name).to.equal('normal')
201 expect(videos[ 1 ].name).to.equal('nsfw') 201 expect(videos[ 1 ].name).to.equal('nsfw')
202 }) 202 })
203
204 it('Should display NSFW videos when the nsfw param === true', async function () {
205 for (const res of await getVideosFunctions(server.accessToken, { nsfw: true })) {
206 expect(res.body.total).to.equal(1)
207
208 const videos = res.body.data
209 expect(videos).to.have.lengthOf(1)
210 expect(videos[ 0 ].name).to.equal('nsfw')
211 }
212 })
213
214 it('Should hide NSFW videos when the nsfw param === true', async function () {
215 for (const res of await getVideosFunctions(server.accessToken, { nsfw: false })) {
216 expect(res.body.total).to.equal(1)
217
218 const videos = res.body.data
219 expect(videos).to.have.lengthOf(1)
220 expect(videos[ 0 ].name).to.equal('normal')
221 }
222 })
203 }) 223 })
204 224
205 after(async function () { 225 after(async function () {