aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/search
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-13 09:43:59 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit6c5065a011b099618681a37bd77eaa7bd3db752e (patch)
tree352252a00b25013c4b1902f6bcd9668aba295c7b /server/tests/api/search
parent0d8ecb7592577f54012413a2b5a9b159cfc90399 (diff)
downloadPeerTube-6c5065a011b099618681a37bd77eaa7bd3db752e.tar.gz
PeerTube-6c5065a011b099618681a37bd77eaa7bd3db752e.tar.zst
PeerTube-6c5065a011b099618681a37bd77eaa7bd3db752e.zip
Introduce server commands
Diffstat (limited to 'server/tests/api/search')
-rw-r--r--server/tests/api/search/search-index.ts24
-rw-r--r--server/tests/api/search/search-videos.ts46
2 files changed, 30 insertions, 40 deletions
diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts
index e4c5f5796..306f84c3a 100644
--- a/server/tests/api/search/search-index.ts
+++ b/server/tests/api/search/search-index.ts
@@ -2,16 +2,8 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils'
6 cleanupTests, 6import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
7 flushAndRunServer,
8 immutableAssign,
9 SearchCommand,
10 ServerInfo,
11 setAccessTokensToServers,
12 uploadVideo
13} from '@shared/extra-utils'
14import { VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
15 7
16const expect = chai.expect 8const expect = chai.expect
17 9
@@ -174,32 +166,32 @@ describe('Test videos search', function () {
174 } 166 }
175 167
176 { 168 {
177 const search = immutableAssign(baseSearch, { startDate: '2018-10-01T10:54:46.396Z' }) 169 const search = { ...baseSearch, startDate: '2018-10-01T10:54:46.396Z' }
178 await check(search, false) 170 await check(search, false)
179 } 171 }
180 172
181 { 173 {
182 const search = immutableAssign(baseSearch, { tagsAllOf: [ 'toto', 'framasoft' ] }) 174 const search = { ...baseSearch, tagsAllOf: [ 'toto', 'framasoft' ] }
183 await check(search, false) 175 await check(search, false)
184 } 176 }
185 177
186 { 178 {
187 const search = immutableAssign(baseSearch, { durationMin: 2000 }) 179 const search = { ...baseSearch, durationMin: 2000 }
188 await check(search, false) 180 await check(search, false)
189 } 181 }
190 182
191 { 183 {
192 const search = immutableAssign(baseSearch, { nsfw: 'true' }) 184 const search = { ...baseSearch, nsfw: 'true' as BooleanBothQuery }
193 await check(search, false) 185 await check(search, false)
194 } 186 }
195 187
196 { 188 {
197 const search = immutableAssign(baseSearch, { nsfw: 'false' }) 189 const search = { ...baseSearch, nsfw: 'false' as BooleanBothQuery }
198 await check(search, true) 190 await check(search, true)
199 } 191 }
200 192
201 { 193 {
202 const search = immutableAssign(baseSearch, { nsfw: 'both' }) 194 const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery }
203 await check(search, true) 195 await check(search, true)
204 } 196 }
205 }) 197 })
diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts
index 513538917..66f5f3182 100644
--- a/server/tests/api/search/search-videos.ts
+++ b/server/tests/api/search/search-videos.ts
@@ -5,7 +5,6 @@ import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 flushAndRunServer, 7 flushAndRunServer,
8 immutableAssign,
9 SearchCommand, 8 SearchCommand,
10 ServerInfo, 9 ServerInfo,
11 setAccessTokensToServers, 10 setAccessTokensToServers,
@@ -44,11 +43,11 @@ describe('Test videos search', function () {
44 } 43 }
45 await uploadVideo(server.url, server.accessToken, attributes1) 44 await uploadVideo(server.url, server.accessToken, attributes1)
46 45
47 const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }) 46 const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }
48 await uploadVideo(server.url, server.accessToken, attributes2) 47 await uploadVideo(server.url, server.accessToken, attributes2)
49 48
50 { 49 {
51 const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: undefined }) 50 const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined }
52 const res = await uploadVideo(server.url, server.accessToken, attributes3) 51 const res = await uploadVideo(server.url, server.accessToken, attributes3)
53 const videoId = res.body.video.id 52 const videoId = res.body.video.id
54 videoUUID = res.body.video.uuid 53 videoUUID = res.body.video.uuid
@@ -68,26 +67,23 @@ describe('Test videos search', function () {
68 }) 67 })
69 } 68 }
70 69
71 const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true }) 70 const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true }
72 await uploadVideo(server.url, server.accessToken, attributes4) 71 await uploadVideo(server.url, server.accessToken, attributes4)
73 72
74 await wait(1000) 73 await wait(1000)
75 74
76 startDate = new Date().toISOString() 75 startDate = new Date().toISOString()
77 76
78 const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2, language: undefined }) 77 const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined }
79 await uploadVideo(server.url, server.accessToken, attributes5) 78 await uploadVideo(server.url, server.accessToken, attributes5)
80 79
81 const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }) 80 const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }
82 await uploadVideo(server.url, server.accessToken, attributes6) 81 await uploadVideo(server.url, server.accessToken, attributes6)
83 82
84 const attributes7 = immutableAssign(attributes1, { 83 const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' }
85 name: attributes1.name + ' - 7',
86 originallyPublishedAt: '2019-02-12T09:58:08.286Z'
87 })
88 await uploadVideo(server.url, server.accessToken, attributes7) 84 await uploadVideo(server.url, server.accessToken, attributes7)
89 85
90 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 }) 86 const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 }
91 await uploadVideo(server.url, server.accessToken, attributes8) 87 await uploadVideo(server.url, server.accessToken, attributes8)
92 } 88 }
93 89
@@ -101,7 +97,7 @@ describe('Test videos search', function () {
101 } 97 }
102 await uploadVideo(server.url, server.accessToken, attributes) 98 await uploadVideo(server.url, server.accessToken, attributes)
103 99
104 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' })) 100 await uploadVideo(server.url, server.accessToken, { ...attributes, name: attributes.name + ' duplicate' })
105 } 101 }
106 102
107 { 103 {
@@ -122,10 +118,10 @@ describe('Test videos search', function () {
122 category: 1 118 category: 1
123 } 119 }
124 await uploadVideo(server.url, server.accessToken, attributes1) 120 await uploadVideo(server.url, server.accessToken, attributes1)
125 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) 121 await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 })
126 122
127 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] })) 123 await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'cccc', 'dddd' ] })
128 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] })) 124 await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'eeee', 'ffff' ] })
129 } 125 }
130 126
131 { 127 {
@@ -134,7 +130,7 @@ describe('Test videos search', function () {
134 category: 1 130 category: 1
135 } 131 }
136 await uploadVideo(server.url, server.accessToken, attributes1) 132 await uploadVideo(server.url, server.accessToken, attributes1)
137 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) 133 await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 })
138 } 134 }
139 135
140 command = server.searchCommand 136 command = server.searchCommand
@@ -414,7 +410,7 @@ describe('Test videos search', function () {
414 } 410 }
415 411
416 { 412 {
417 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }) 413 const query = { ...baseQuery, originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }
418 const body = await command.advancedVideoSearch({ search: query }) 414 const body = await command.advancedVideoSearch({ search: query })
419 415
420 expect(body.total).to.equal(1) 416 expect(body.total).to.equal(1)
@@ -422,7 +418,7 @@ describe('Test videos search', function () {
422 } 418 }
423 419
424 { 420 {
425 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }) 421 const query = { ...baseQuery, originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }
426 const body = await command.advancedVideoSearch({ search: query }) 422 const body = await command.advancedVideoSearch({ search: query })
427 423
428 expect(body.total).to.equal(1) 424 expect(body.total).to.equal(1)
@@ -430,34 +426,36 @@ describe('Test videos search', function () {
430 } 426 }
431 427
432 { 428 {
433 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }) 429 const query = { ...baseQuery, originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }
434 const body = await command.advancedVideoSearch({ search: query }) 430 const body = await command.advancedVideoSearch({ search: query })
435 431
436 expect(body.total).to.equal(0) 432 expect(body.total).to.equal(0)
437 } 433 }
438 434
439 { 435 {
440 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }) 436 const query = { ...baseQuery, originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }
441 const body = await command.advancedVideoSearch({ search: query }) 437 const body = await command.advancedVideoSearch({ search: query })
442 438
443 expect(body.total).to.equal(0) 439 expect(body.total).to.equal(0)
444 } 440 }
445 441
446 { 442 {
447 const query = immutableAssign(baseQuery, { 443 const query = {
444 ...baseQuery,
448 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', 445 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
449 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z' 446 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
450 }) 447 }
451 const body = await command.advancedVideoSearch({ search: query }) 448 const body = await command.advancedVideoSearch({ search: query })
452 449
453 expect(body.total).to.equal(0) 450 expect(body.total).to.equal(0)
454 } 451 }
455 452
456 { 453 {
457 const query = immutableAssign(baseQuery, { 454 const query = {
455 ...baseQuery,
458 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', 456 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
459 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z' 457 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
460 }) 458 }
461 const body = await command.advancedVideoSearch({ search: query }) 459 const body = await command.advancedVideoSearch({ search: query })
462 460
463 expect(body.total).to.equal(1) 461 expect(body.total).to.equal(1)