aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-06 15:22:51 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:17 +0200
commitaf971e06c620bd46a5aa64c8833364e7022b5e3d (patch)
tree4288b66b79fe4dd1ab9496e85a3abf7d747ad03a
parent23a3a8827cb8b862f5cc7ee2819f39918303beca (diff)
downloadPeerTube-af971e06c620bd46a5aa64c8833364e7022b5e3d.tar.gz
PeerTube-af971e06c620bd46a5aa64c8833364e7022b5e3d.tar.zst
PeerTube-af971e06c620bd46a5aa64c8833364e7022b5e3d.zip
Introduce search command
-rw-r--r--server/tests/api/moderation/video-blacklist.ts31
-rw-r--r--server/tests/api/search/search-activitypub-video-channels.ts83
-rw-r--r--server/tests/api/search/search-activitypub-video-playlists.ts84
-rw-r--r--server/tests/api/search/search-activitypub-videos.ts81
-rw-r--r--server/tests/api/search/search-channels.ts29
-rw-r--r--server/tests/api/search/search-index.ts129
-rw-r--r--server/tests/api/search/search-playlists.ts36
-rw-r--r--server/tests/api/search/search-videos.ts211
-rw-r--r--server/tests/api/videos/video-nsfw.ts14
-rw-r--r--server/tests/api/videos/videos-history.ts15
-rw-r--r--server/tests/plugins/filter-hooks.ts62
-rw-r--r--shared/extra-utils/index.ts4
-rw-r--r--shared/extra-utils/overviews/overviews-command.ts1
-rw-r--r--shared/extra-utils/search/index.ts1
-rw-r--r--shared/extra-utils/search/search-command.ts101
-rw-r--r--shared/extra-utils/search/video-channels.ts36
-rw-r--r--shared/extra-utils/search/video-playlists.ts36
-rw-r--r--shared/extra-utils/search/videos.ts64
-rw-r--r--shared/extra-utils/server/servers.ts3
-rw-r--r--shared/extra-utils/videos/videos.ts8
20 files changed, 519 insertions, 510 deletions
diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts
index 52cac20d9..4a4930c98 100644
--- a/server/tests/api/moderation/video-blacklist.ts
+++ b/server/tests/api/moderation/video-blacklist.ts
@@ -7,6 +7,7 @@ import {
7 addVideoToBlacklist, 7 addVideoToBlacklist,
8 cleanupTests, 8 cleanupTests,
9 createUser, 9 createUser,
10 doubleFollow,
10 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
11 getBlacklistedVideosList, 12 getBlacklistedVideosList,
12 getMyUserInformation, 13 getMyUserInformation,
@@ -15,20 +16,16 @@ import {
15 killallServers, 16 killallServers,
16 removeVideoFromBlacklist, 17 removeVideoFromBlacklist,
17 reRunServer, 18 reRunServer,
18 searchVideo,
19 ServerInfo, 19 ServerInfo,
20 setAccessTokensToServers, 20 setAccessTokensToServers,
21 updateVideo, 21 updateVideo,
22 updateVideoBlacklist, 22 updateVideoBlacklist,
23 uploadVideo, 23 uploadVideo,
24 userLogin 24 userLogin,
25} from '../../../../shared/extra-utils/index' 25 waitJobs
26import { doubleFollow } from '../../../../shared/extra-utils/server/follows' 26} from '@shared/extra-utils'
27import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 27import { getGoodVideoUrl, getMagnetURI, importVideo } from '@shared/extra-utils/videos/video-imports'
28import { getGoodVideoUrl, getMagnetURI, importVideo } from '../../../../shared/extra-utils/videos/video-imports' 28import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
29import { User, UserRole } from '../../../../shared/models/users'
30import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
31import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos'
32 29
33const expect = chai.expect 30const expect = chai.expect
34 31
@@ -80,11 +77,11 @@ describe('Test video blacklist', function () {
80 } 77 }
81 78
82 { 79 {
83 const res = await searchVideo(servers[0].url, 'name') 80 const body = await servers[0].searchCommand.searchVideos({ search: 'name' })
84 81
85 expect(res.body.total).to.equal(0) 82 expect(body.total).to.equal(0)
86 expect(res.body.data).to.be.an('array') 83 expect(body.data).to.be.an('array')
87 expect(res.body.data.length).to.equal(0) 84 expect(body.data.length).to.equal(0)
88 } 85 }
89 }) 86 })
90 87
@@ -98,11 +95,11 @@ describe('Test video blacklist', function () {
98 } 95 }
99 96
100 { 97 {
101 const res = await searchVideo(servers[1].url, 'video') 98 const body = await servers[1].searchCommand.searchVideos({ search: 'name' })
102 99
103 expect(res.body.total).to.equal(2) 100 expect(body.total).to.equal(2)
104 expect(res.body.data).to.be.an('array') 101 expect(body.data).to.be.an('array')
105 expect(res.body.data.length).to.equal(2) 102 expect(body.data.length).to.equal(2)
106 } 103 }
107 }) 104 })
108 }) 105 })
diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts
index e83eb7171..cf5158b66 100644
--- a/server/tests/api/search/search-activitypub-video-channels.ts
+++ b/server/tests/api/search/search-activitypub-video-channels.ts
@@ -1,7 +1,7 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { 5import {
6 addVideoChannel, 6 addVideoChannel,
7 cleanupTests, 7 cleanupTests,
@@ -10,6 +10,7 @@ import {
10 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
11 getVideoChannelsList, 11 getVideoChannelsList,
12 getVideoChannelVideos, 12 getVideoChannelVideos,
13 SearchCommand,
13 ServerInfo, 14 ServerInfo,
14 setAccessTokensToServers, 15 setAccessTokensToServers,
15 updateMyUser, 16 updateMyUser,
@@ -17,11 +18,10 @@ import {
17 updateVideoChannel, 18 updateVideoChannel,
18 uploadVideo, 19 uploadVideo,
19 userLogin, 20 userLogin,
20 wait 21 wait,
21} from '../../../../shared/extra-utils' 22 waitJobs
22import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 23} from '@shared/extra-utils'
23import { VideoChannel } from '../../../../shared/models/videos' 24import { VideoChannel } from '@shared/models'
24import { searchVideoChannel } from '../../../../shared/extra-utils/search/video-channels'
25 25
26const expect = chai.expect 26const expect = chai.expect
27 27
@@ -30,6 +30,7 @@ describe('Test ActivityPub video channels search', function () {
30 let userServer2Token: string 30 let userServer2Token: string
31 let videoServer2UUID: string 31 let videoServer2UUID: string
32 let channelIdServer2: number 32 let channelIdServer2: number
33 let command: SearchCommand
33 34
34 before(async function () { 35 before(async function () {
35 this.timeout(120000) 36 this.timeout(120000)
@@ -64,6 +65,8 @@ describe('Test ActivityPub video channels search', function () {
64 } 65 }
65 66
66 await waitJobs(servers) 67 await waitJobs(servers)
68
69 command = servers[0].searchCommand
67 }) 70 })
68 71
69 it('Should not find a remote video channel', async function () { 72 it('Should not find a remote video channel', async function () {
@@ -71,21 +74,21 @@ describe('Test ActivityPub video channels search', function () {
71 74
72 { 75 {
73 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3' 76 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3'
74 const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) 77 const body = await command.searchChannels({ search, token: servers[0].accessToken })
75 78
76 expect(res.body.total).to.equal(0) 79 expect(body.total).to.equal(0)
77 expect(res.body.data).to.be.an('array') 80 expect(body.data).to.be.an('array')
78 expect(res.body.data).to.have.lengthOf(0) 81 expect(body.data).to.have.lengthOf(0)
79 } 82 }
80 83
81 { 84 {
82 // Without token 85 // Without token
83 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' 86 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
84 const res = await searchVideoChannel(servers[0].url, search) 87 const body = await command.searchChannels({ search })
85 88
86 expect(res.body.total).to.equal(0) 89 expect(body.total).to.equal(0)
87 expect(res.body.data).to.be.an('array') 90 expect(body.data).to.be.an('array')
88 expect(res.body.data).to.have.lengthOf(0) 91 expect(body.data).to.have.lengthOf(0)
89 } 92 }
90 }) 93 })
91 94
@@ -96,13 +99,13 @@ describe('Test ActivityPub video channels search', function () {
96 ] 99 ]
97 100
98 for (const search of searches) { 101 for (const search of searches) {
99 const res = await searchVideoChannel(servers[0].url, search) 102 const body = await command.searchChannels({ search })
100 103
101 expect(res.body.total).to.equal(1) 104 expect(body.total).to.equal(1)
102 expect(res.body.data).to.be.an('array') 105 expect(body.data).to.be.an('array')
103 expect(res.body.data).to.have.lengthOf(1) 106 expect(body.data).to.have.lengthOf(1)
104 expect(res.body.data[0].name).to.equal('channel1_server1') 107 expect(body.data[0].name).to.equal('channel1_server1')
105 expect(res.body.data[0].displayName).to.equal('Channel 1 server 1') 108 expect(body.data[0].displayName).to.equal('Channel 1 server 1')
106 } 109 }
107 }) 110 })
108 111
@@ -110,13 +113,13 @@ describe('Test ActivityPub video channels search', function () {
110 const search = 'http://localhost:' + servers[0].port + '/c/channel1_server1' 113 const search = 'http://localhost:' + servers[0].port + '/c/channel1_server1'
111 114
112 for (const token of [ undefined, servers[0].accessToken ]) { 115 for (const token of [ undefined, servers[0].accessToken ]) {
113 const res = await searchVideoChannel(servers[0].url, search, token) 116 const body = await command.searchChannels({ search, token })
114 117
115 expect(res.body.total).to.equal(1) 118 expect(body.total).to.equal(1)
116 expect(res.body.data).to.be.an('array') 119 expect(body.data).to.be.an('array')
117 expect(res.body.data).to.have.lengthOf(1) 120 expect(body.data).to.have.lengthOf(1)
118 expect(res.body.data[0].name).to.equal('channel1_server1') 121 expect(body.data[0].name).to.equal('channel1_server1')
119 expect(res.body.data[0].displayName).to.equal('Channel 1 server 1') 122 expect(body.data[0].displayName).to.equal('Channel 1 server 1')
120 } 123 }
121 }) 124 })
122 125
@@ -129,13 +132,13 @@ describe('Test ActivityPub video channels search', function () {
129 ] 132 ]
130 133
131 for (const search of searches) { 134 for (const search of searches) {
132 const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) 135 const body = await command.searchChannels({ search, token: servers[0].accessToken })
133 136
134 expect(res.body.total).to.equal(1) 137 expect(body.total).to.equal(1)
135 expect(res.body.data).to.be.an('array') 138 expect(body.data).to.be.an('array')
136 expect(res.body.data).to.have.lengthOf(1) 139 expect(body.data).to.have.lengthOf(1)
137 expect(res.body.data[0].name).to.equal('channel1_server2') 140 expect(body.data[0].name).to.equal('channel1_server2')
138 expect(res.body.data[0].displayName).to.equal('Channel 1 server 2') 141 expect(body.data[0].displayName).to.equal('Channel 1 server 2')
139 } 142 }
140 }) 143 })
141 144
@@ -176,11 +179,11 @@ describe('Test ActivityPub video channels search', function () {
176 await wait(10000) 179 await wait(10000)
177 180
178 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' 181 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
179 const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) 182 const body = await command.searchChannels({ search, token: servers[0].accessToken })
180 expect(res.body.total).to.equal(1) 183 expect(body.total).to.equal(1)
181 expect(res.body.data).to.have.lengthOf(1) 184 expect(body.data).to.have.lengthOf(1)
182 185
183 const videoChannel: VideoChannel = res.body.data[0] 186 const videoChannel: VideoChannel = body.data[0]
184 expect(videoChannel.displayName).to.equal('channel updated') 187 expect(videoChannel.displayName).to.equal('channel updated')
185 188
186 // We don't return the owner account for now 189 // We don't return the owner account for now
@@ -199,7 +202,7 @@ describe('Test ActivityPub video channels search', function () {
199 await wait(10000) 202 await wait(10000)
200 203
201 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' 204 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
202 await searchVideoChannel(servers[0].url, search, servers[0].accessToken) 205 await command.searchChannels({ search, token: servers[0].accessToken })
203 206
204 await waitJobs(servers) 207 await waitJobs(servers)
205 208
@@ -221,9 +224,9 @@ describe('Test ActivityPub video channels search', function () {
221 await wait(10000) 224 await wait(10000)
222 225
223 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' 226 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
224 const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) 227 const body = await command.searchChannels({ search, token: servers[0].accessToken })
225 expect(res.body.total).to.equal(0) 228 expect(body.total).to.equal(0)
226 expect(res.body.data).to.have.lengthOf(0) 229 expect(body.data).to.have.lengthOf(0)
227 }) 230 })
228 231
229 after(async function () { 232 after(async function () {
diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts
index 4c08e9548..1df18173a 100644
--- a/server/tests/api/search/search-activitypub-video-playlists.ts
+++ b/server/tests/api/search/search-activitypub-video-playlists.ts
@@ -9,15 +9,15 @@ import {
9 deleteVideoPlaylist, 9 deleteVideoPlaylist,
10 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
11 getVideoPlaylistsList, 11 getVideoPlaylistsList,
12 searchVideoPlaylists, 12 SearchCommand,
13 ServerInfo, 13 ServerInfo,
14 setAccessTokensToServers, 14 setAccessTokensToServers,
15 setDefaultVideoChannel, 15 setDefaultVideoChannel,
16 uploadVideoAndGetId, 16 uploadVideoAndGetId,
17 wait 17 wait,
18} from '../../../../shared/extra-utils' 18 waitJobs
19import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 19} from '@shared/extra-utils'
20import { VideoPlaylist, VideoPlaylistPrivacy } from '../../../../shared/models/videos' 20import { VideoPlaylistPrivacy } from '@shared/models'
21 21
22const expect = chai.expect 22const expect = chai.expect
23 23
@@ -27,6 +27,8 @@ describe('Test ActivityPub playlists search', function () {
27 let playlistServer2UUID: string 27 let playlistServer2UUID: string
28 let video2Server2: string 28 let video2Server2: string
29 29
30 let command: SearchCommand
31
30 before(async function () { 32 before(async function () {
31 this.timeout(120000) 33 this.timeout(120000)
32 34
@@ -78,38 +80,40 @@ describe('Test ActivityPub playlists search', function () {
78 } 80 }
79 81
80 await waitJobs(servers) 82 await waitJobs(servers)
83
84 command = servers[0].searchCommand
81 }) 85 })
82 86
83 it('Should not find a remote playlist', async function () { 87 it('Should not find a remote playlist', async function () {
84 { 88 {
85 const search = 'http://localhost:' + servers[1].port + '/video-playlists/43' 89 const search = 'http://localhost:' + servers[1].port + '/video-playlists/43'
86 const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) 90 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
87 91
88 expect(res.body.total).to.equal(0) 92 expect(body.total).to.equal(0)
89 expect(res.body.data).to.be.an('array') 93 expect(body.data).to.be.an('array')
90 expect(res.body.data).to.have.lengthOf(0) 94 expect(body.data).to.have.lengthOf(0)
91 } 95 }
92 96
93 { 97 {
94 // Without token 98 // Without token
95 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID 99 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID
96 const res = await searchVideoPlaylists(servers[0].url, search) 100 const body = await command.searchPlaylists({ search })
97 101
98 expect(res.body.total).to.equal(0) 102 expect(body.total).to.equal(0)
99 expect(res.body.data).to.be.an('array') 103 expect(body.data).to.be.an('array')
100 expect(res.body.data).to.have.lengthOf(0) 104 expect(body.data).to.have.lengthOf(0)
101 } 105 }
102 }) 106 })
103 107
104 it('Should search a local playlist', async function () { 108 it('Should search a local playlist', async function () {
105 const search = 'http://localhost:' + servers[0].port + '/video-playlists/' + playlistServer1UUID 109 const search = 'http://localhost:' + servers[0].port + '/video-playlists/' + playlistServer1UUID
106 const res = await searchVideoPlaylists(servers[0].url, search) 110 const body = await command.searchPlaylists({ search })
107 111
108 expect(res.body.total).to.equal(1) 112 expect(body.total).to.equal(1)
109 expect(res.body.data).to.be.an('array') 113 expect(body.data).to.be.an('array')
110 expect(res.body.data).to.have.lengthOf(1) 114 expect(body.data).to.have.lengthOf(1)
111 expect(res.body.data[0].displayName).to.equal('playlist 1 on server 1') 115 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
112 expect(res.body.data[0].videosLength).to.equal(2) 116 expect(body.data[0].videosLength).to.equal(2)
113 }) 117 })
114 118
115 it('Should search a local playlist with an alternative URL', async function () { 119 it('Should search a local playlist with an alternative URL', async function () {
@@ -120,13 +124,13 @@ describe('Test ActivityPub playlists search', function () {
120 124
121 for (const search of searches) { 125 for (const search of searches) {
122 for (const token of [ undefined, servers[0].accessToken ]) { 126 for (const token of [ undefined, servers[0].accessToken ]) {
123 const res = await searchVideoPlaylists(servers[0].url, search, token) 127 const body = await command.searchPlaylists({ search, token })
124 128
125 expect(res.body.total).to.equal(1) 129 expect(body.total).to.equal(1)
126 expect(res.body.data).to.be.an('array') 130 expect(body.data).to.be.an('array')
127 expect(res.body.data).to.have.lengthOf(1) 131 expect(body.data).to.have.lengthOf(1)
128 expect(res.body.data[0].displayName).to.equal('playlist 1 on server 1') 132 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
129 expect(res.body.data[0].videosLength).to.equal(2) 133 expect(body.data[0].videosLength).to.equal(2)
130 } 134 }
131 } 135 }
132 }) 136 })
@@ -139,13 +143,13 @@ describe('Test ActivityPub playlists search', function () {
139 ] 143 ]
140 144
141 for (const search of searches) { 145 for (const search of searches) {
142 const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) 146 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
143 147
144 expect(res.body.total).to.equal(1) 148 expect(body.total).to.equal(1)
145 expect(res.body.data).to.be.an('array') 149 expect(body.data).to.be.an('array')
146 expect(res.body.data).to.have.lengthOf(1) 150 expect(body.data).to.have.lengthOf(1)
147 expect(res.body.data[0].displayName).to.equal('playlist 1 on server 2') 151 expect(body.data[0].displayName).to.equal('playlist 1 on server 2')
148 expect(res.body.data[0].videosLength).to.equal(1) 152 expect(body.data[0].videosLength).to.equal(1)
149 } 153 }
150 }) 154 })
151 155
@@ -172,16 +176,16 @@ describe('Test ActivityPub playlists search', function () {
172 176
173 // Will run refresh async 177 // Will run refresh async
174 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID 178 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID
175 await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) 179 await command.searchPlaylists({ search, token: servers[0].accessToken })
176 180
177 // Wait refresh 181 // Wait refresh
178 await wait(5000) 182 await wait(5000)
179 183
180 const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) 184 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
181 expect(res.body.total).to.equal(1) 185 expect(body.total).to.equal(1)
182 expect(res.body.data).to.have.lengthOf(1) 186 expect(body.data).to.have.lengthOf(1)
183 187
184 const playlist: VideoPlaylist = res.body.data[0] 188 const playlist = body.data[0]
185 expect(playlist.videosLength).to.equal(2) 189 expect(playlist.videosLength).to.equal(2)
186 }) 190 })
187 191
@@ -196,14 +200,14 @@ describe('Test ActivityPub playlists search', function () {
196 200
197 // Will run refresh async 201 // Will run refresh async
198 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID 202 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID
199 await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) 203 await command.searchPlaylists({ search, token: servers[0].accessToken })
200 204
201 // Wait refresh 205 // Wait refresh
202 await wait(5000) 206 await wait(5000)
203 207
204 const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) 208 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
205 expect(res.body.total).to.equal(0) 209 expect(body.total).to.equal(0)
206 expect(res.body.data).to.have.lengthOf(0) 210 expect(body.data).to.have.lengthOf(0)
207 }) 211 })
208 212
209 after(async function () { 213 after(async function () {
diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts
index e9b4978da..1a5130ce9 100644
--- a/server/tests/api/search/search-activitypub-videos.ts
+++ b/server/tests/api/search/search-activitypub-videos.ts
@@ -1,15 +1,14 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { 5import {
6 addVideoChannel, 6 addVideoChannel,
7 cleanupTests, 7 cleanupTests,
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
9 getVideosList, 9 getVideosList,
10 removeVideo, 10 removeVideo,
11 searchVideo, 11 SearchCommand,
12 searchVideoWithToken,
13 ServerInfo, 12 ServerInfo,
14 setAccessTokensToServers, 13 setAccessTokensToServers,
15 updateVideo, 14 updateVideo,
@@ -17,7 +16,7 @@ import {
17 wait 16 wait
18} from '../../../../shared/extra-utils' 17} from '../../../../shared/extra-utils'
19import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 18import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
20import { Video, VideoPrivacy } from '../../../../shared/models/videos' 19import { VideoPrivacy } from '../../../../shared/models/videos'
21 20
22const expect = chai.expect 21const expect = chai.expect
23 22
@@ -26,6 +25,8 @@ describe('Test ActivityPub videos search', function () {
26 let videoServer1UUID: string 25 let videoServer1UUID: string
27 let videoServer2UUID: string 26 let videoServer2UUID: string
28 27
28 let command: SearchCommand
29
29 before(async function () { 30 before(async function () {
30 this.timeout(120000) 31 this.timeout(120000)
31 32
@@ -44,49 +45,51 @@ describe('Test ActivityPub videos search', function () {
44 } 45 }
45 46
46 await waitJobs(servers) 47 await waitJobs(servers)
48
49 command = servers[0].searchCommand
47 }) 50 })
48 51
49 it('Should not find a remote video', async function () { 52 it('Should not find a remote video', async function () {
50 { 53 {
51 const search = 'http://localhost:' + servers[1].port + '/videos/watch/43' 54 const search = 'http://localhost:' + servers[1].port + '/videos/watch/43'
52 const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) 55 const body = await command.searchVideos({ search, token: servers[0].accessToken })
53 56
54 expect(res.body.total).to.equal(0) 57 expect(body.total).to.equal(0)
55 expect(res.body.data).to.be.an('array') 58 expect(body.data).to.be.an('array')
56 expect(res.body.data).to.have.lengthOf(0) 59 expect(body.data).to.have.lengthOf(0)
57 } 60 }
58 61
59 { 62 {
60 // Without token 63 // Without token
61 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID 64 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
62 const res = await searchVideo(servers[0].url, search) 65 const body = await command.searchVideos({ search })
63 66
64 expect(res.body.total).to.equal(0) 67 expect(body.total).to.equal(0)
65 expect(res.body.data).to.be.an('array') 68 expect(body.data).to.be.an('array')
66 expect(res.body.data).to.have.lengthOf(0) 69 expect(body.data).to.have.lengthOf(0)
67 } 70 }
68 }) 71 })
69 72
70 it('Should search a local video', async function () { 73 it('Should search a local video', async function () {
71 const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID 74 const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID
72 const res = await searchVideo(servers[0].url, search) 75 const body = await command.searchVideos({ search })
73 76
74 expect(res.body.total).to.equal(1) 77 expect(body.total).to.equal(1)
75 expect(res.body.data).to.be.an('array') 78 expect(body.data).to.be.an('array')
76 expect(res.body.data).to.have.lengthOf(1) 79 expect(body.data).to.have.lengthOf(1)
77 expect(res.body.data[0].name).to.equal('video 1 on server 1') 80 expect(body.data[0].name).to.equal('video 1 on server 1')
78 }) 81 })
79 82
80 it('Should search a local video with an alternative URL', async function () { 83 it('Should search a local video with an alternative URL', async function () {
81 const search = 'http://localhost:' + servers[0].port + '/w/' + videoServer1UUID 84 const search = 'http://localhost:' + servers[0].port + '/w/' + videoServer1UUID
82 const res1 = await searchVideo(servers[0].url, search) 85 const body1 = await command.searchVideos({ search })
83 const res2 = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) 86 const body2 = await command.searchVideos({ search, token: servers[0].accessToken })
84 87
85 for (const res of [ res1, res2 ]) { 88 for (const body of [ body1, body2 ]) {
86 expect(res.body.total).to.equal(1) 89 expect(body.total).to.equal(1)
87 expect(res.body.data).to.be.an('array') 90 expect(body.data).to.be.an('array')
88 expect(res.body.data).to.have.lengthOf(1) 91 expect(body.data).to.have.lengthOf(1)
89 expect(res.body.data[0].name).to.equal('video 1 on server 1') 92 expect(body.data[0].name).to.equal('video 1 on server 1')
90 } 93 }
91 }) 94 })
92 95
@@ -97,12 +100,12 @@ describe('Test ActivityPub videos search', function () {
97 ] 100 ]
98 101
99 for (const search of searches) { 102 for (const search of searches) {
100 const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) 103 const body = await command.searchVideos({ search, token: servers[0].accessToken })
101 104
102 expect(res.body.total).to.equal(1) 105 expect(body.total).to.equal(1)
103 expect(res.body.data).to.be.an('array') 106 expect(body.data).to.be.an('array')
104 expect(res.body.data).to.have.lengthOf(1) 107 expect(body.data).to.have.lengthOf(1)
105 expect(res.body.data[0].name).to.equal('video 1 on server 2') 108 expect(body.data[0].name).to.equal('video 1 on server 2')
106 } 109 }
107 }) 110 })
108 111
@@ -137,16 +140,16 @@ describe('Test ActivityPub videos search', function () {
137 140
138 // Will run refresh async 141 // Will run refresh async
139 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID 142 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
140 await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) 143 await command.searchVideos({ search, token: servers[0].accessToken })
141 144
142 // Wait refresh 145 // Wait refresh
143 await wait(5000) 146 await wait(5000)
144 147
145 const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) 148 const body = await command.searchVideos({ search, token: servers[0].accessToken })
146 expect(res.body.total).to.equal(1) 149 expect(body.total).to.equal(1)
147 expect(res.body.data).to.have.lengthOf(1) 150 expect(body.data).to.have.lengthOf(1)
148 151
149 const video: Video = res.body.data[0] 152 const video = body.data[0]
150 expect(video.name).to.equal('updated') 153 expect(video.name).to.equal('updated')
151 expect(video.channel.name).to.equal('super_channel') 154 expect(video.channel.name).to.equal('super_channel')
152 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) 155 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
@@ -163,14 +166,14 @@ describe('Test ActivityPub videos search', function () {
163 166
164 // Will run refresh async 167 // Will run refresh async
165 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID 168 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
166 await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) 169 await command.searchVideos({ search, token: servers[0].accessToken })
167 170
168 // Wait refresh 171 // Wait refresh
169 await wait(5000) 172 await wait(5000)
170 173
171 const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) 174 const body = await command.searchVideos({ search, token: servers[0].accessToken })
172 expect(res.body.total).to.equal(0) 175 expect(body.total).to.equal(0)
173 expect(res.body.data).to.have.lengthOf(0) 176 expect(body.data).to.have.lengthOf(0)
174 }) 177 })
175 178
176 after(async function () { 179 after(async function () {
diff --git a/server/tests/api/search/search-channels.ts b/server/tests/api/search/search-channels.ts
index daca2aebe..307bc063d 100644
--- a/server/tests/api/search/search-channels.ts
+++ b/server/tests/api/search/search-channels.ts
@@ -2,21 +2,22 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { searchVideoChannel, advancedVideoChannelSearch } from '@shared/extra-utils/search/video-channels'
6import { 5import {
7 addVideoChannel, 6 addVideoChannel,
8 cleanupTests, 7 cleanupTests,
9 createUser, 8 createUser,
10 flushAndRunServer, 9 flushAndRunServer,
10 SearchCommand,
11 ServerInfo, 11 ServerInfo,
12 setAccessTokensToServers 12 setAccessTokensToServers
13} from '../../../../shared/extra-utils' 13} from '@shared/extra-utils'
14import { VideoChannel } from '@shared/models' 14import { VideoChannel } from '@shared/models'
15 15
16const expect = chai.expect 16const expect = chai.expect
17 17
18describe('Test channels search', function () { 18describe('Test channels search', function () {
19 let server: ServerInfo = null 19 let server: ServerInfo = null
20 let command: SearchCommand
20 21
21 before(async function () { 22 before(async function () {
22 this.timeout(30000) 23 this.timeout(30000)
@@ -33,13 +34,15 @@ describe('Test channels search', function () {
33 } 34 }
34 await addVideoChannel(server.url, server.accessToken, channel) 35 await addVideoChannel(server.url, server.accessToken, channel)
35 } 36 }
37
38 command = server.searchCommand
36 }) 39 })
37 40
38 it('Should make a simple search and not have results', async function () { 41 it('Should make a simple search and not have results', async function () {
39 const res = await searchVideoChannel(server.url, 'abc') 42 const body = await command.searchChannels({ search: 'abc' })
40 43
41 expect(res.body.total).to.equal(0) 44 expect(body.total).to.equal(0)
42 expect(res.body.data).to.have.lengthOf(0) 45 expect(body.data).to.have.lengthOf(0)
43 }) 46 })
44 47
45 it('Should make a search and have results', async function () { 48 it('Should make a search and have results', async function () {
@@ -49,11 +52,11 @@ describe('Test channels search', function () {
49 start: 0, 52 start: 0,
50 count: 1 53 count: 1
51 } 54 }
52 const res = await advancedVideoChannelSearch(server.url, search) 55 const body = await command.advancedChannelSearch({ search })
53 expect(res.body.total).to.equal(1) 56 expect(body.total).to.equal(1)
54 expect(res.body.data).to.have.lengthOf(1) 57 expect(body.data).to.have.lengthOf(1)
55 58
56 const channel: VideoChannel = res.body.data[0] 59 const channel: VideoChannel = body.data[0]
57 expect(channel.name).to.equal('squall_channel') 60 expect(channel.name).to.equal('squall_channel')
58 expect(channel.displayName).to.equal('Squall channel') 61 expect(channel.displayName).to.equal('Squall channel')
59 } 62 }
@@ -65,11 +68,9 @@ describe('Test channels search', function () {
65 count: 1 68 count: 1
66 } 69 }
67 70
68 const res = await advancedVideoChannelSearch(server.url, search) 71 const body = await command.advancedChannelSearch({ search })
69 72 expect(body.total).to.equal(1)
70 expect(res.body.total).to.equal(1) 73 expect(body.data).to.have.lengthOf(0)
71
72 expect(res.body.data).to.have.lengthOf(0)
73 } 74 }
74 }) 75 })
75 76
diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts
index 00f79232a..b2c0857a7 100644
--- a/server/tests/api/search/search-index.ts
+++ b/server/tests/api/search/search-index.ts
@@ -2,28 +2,26 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { advancedVideoChannelSearch, searchVideoChannel } from '@shared/extra-utils/search/video-channels'
6import { Video, VideoChannel, VideoPlaylist, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
7import { 5import {
8 advancedVideoPlaylistSearch,
9 advancedVideosSearch,
10 cleanupTests, 6 cleanupTests,
11 flushAndRunServer, 7 flushAndRunServer,
12 immutableAssign, 8 immutableAssign,
13 searchVideo, 9 SearchCommand,
14 searchVideoPlaylists,
15 ServerInfo, 10 ServerInfo,
16 setAccessTokensToServers, 11 setAccessTokensToServers,
17 updateCustomSubConfig, 12 updateCustomSubConfig,
18 uploadVideo 13 uploadVideo
19} from '../../../../shared/extra-utils' 14} from '@shared/extra-utils'
15import { VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
20 16
21const expect = chai.expect 17const expect = chai.expect
22 18
23describe('Test videos search', function () { 19describe('Test videos search', function () {
24 let server: ServerInfo = null
25 const localVideoName = 'local video' + new Date().toISOString() 20 const localVideoName = 'local video' + new Date().toISOString()
26 21
22 let server: ServerInfo = null
23 let command: SearchCommand
24
27 before(async function () { 25 before(async function () {
28 this.timeout(30000) 26 this.timeout(30000)
29 27
@@ -32,6 +30,8 @@ describe('Test videos search', function () {
32 await setAccessTokensToServers([ server ]) 30 await setAccessTokensToServers([ server ])
33 31
34 await uploadVideo(server.url, server.accessToken, { name: localVideoName }) 32 await uploadVideo(server.url, server.accessToken, { name: localVideoName })
33
34 command = server.searchCommand
35 }) 35 })
36 36
37 describe('Default search', async function () { 37 describe('Default search', async function () {
@@ -49,18 +49,18 @@ describe('Test videos search', function () {
49 } 49 }
50 }) 50 })
51 51
52 const res = await searchVideo(server.url, 'local video') 52 const body = await command.searchVideos({ search: 'local video' })
53 53
54 expect(res.body.total).to.equal(1) 54 expect(body.total).to.equal(1)
55 expect(res.body.data[0].name).to.equal(localVideoName) 55 expect(body.data[0].name).to.equal(localVideoName)
56 }) 56 })
57 57
58 it('Should make a local channels search by default', async function () { 58 it('Should make a local channels search by default', async function () {
59 const res = await searchVideoChannel(server.url, 'root') 59 const body = await command.searchChannels({ search: 'root' })
60 60
61 expect(res.body.total).to.equal(1) 61 expect(body.total).to.equal(1)
62 expect(res.body.data[0].name).to.equal('root_channel') 62 expect(body.data[0].name).to.equal('root_channel')
63 expect(res.body.data[0].host).to.equal('localhost:' + server.port) 63 expect(body.data[0].host).to.equal('localhost:' + server.port)
64 }) 64 })
65 65
66 it('Should make an index videos search by default', async function () { 66 it('Should make an index videos search by default', async function () {
@@ -74,13 +74,13 @@ describe('Test videos search', function () {
74 } 74 }
75 }) 75 })
76 76
77 const res = await searchVideo(server.url, 'local video') 77 const body = await command.searchVideos({ search: 'local video' })
78 expect(res.body.total).to.be.greaterThan(2) 78 expect(body.total).to.be.greaterThan(2)
79 }) 79 })
80 80
81 it('Should make an index channels search by default', async function () { 81 it('Should make an index channels search by default', async function () {
82 const res = await searchVideoChannel(server.url, 'root') 82 const body = await command.searchChannels({ search: 'root' })
83 expect(res.body.total).to.be.greaterThan(2) 83 expect(body.total).to.be.greaterThan(2)
84 }) 84 })
85 85
86 it('Should make an index videos search if local search is disabled', async function () { 86 it('Should make an index videos search if local search is disabled', async function () {
@@ -94,46 +94,46 @@ describe('Test videos search', function () {
94 } 94 }
95 }) 95 })
96 96
97 const res = await searchVideo(server.url, 'local video') 97 const body = await command.searchVideos({ search: 'local video' })
98 expect(res.body.total).to.be.greaterThan(2) 98 expect(body.total).to.be.greaterThan(2)
99 }) 99 })
100 100
101 it('Should make an index channels search if local search is disabled', async function () { 101 it('Should make an index channels search if local search is disabled', async function () {
102 const res = await searchVideoChannel(server.url, 'root') 102 const body = await command.searchChannels({ search: 'root' })
103 expect(res.body.total).to.be.greaterThan(2) 103 expect(body.total).to.be.greaterThan(2)
104 }) 104 })
105 }) 105 })
106 106
107 describe('Videos search', async function () { 107 describe('Videos search', async function () {
108 108
109 it('Should make a simple search and not have results', async function () { 109 it('Should make a simple search and not have results', async function () {
110 const res = await searchVideo(server.url, 'djidane'.repeat(50)) 110 const body = await command.searchVideos({ search: 'djidane'.repeat(50) })
111 111
112 expect(res.body.total).to.equal(0) 112 expect(body.total).to.equal(0)
113 expect(res.body.data).to.have.lengthOf(0) 113 expect(body.data).to.have.lengthOf(0)
114 }) 114 })
115 115
116 it('Should make a simple search and have results', async function () { 116 it('Should make a simple search and have results', async function () {
117 const res = await searchVideo(server.url, 'What is PeerTube') 117 const body = await command.searchVideos({ search: 'What is PeerTube' })
118 118
119 expect(res.body.total).to.be.greaterThan(1) 119 expect(body.total).to.be.greaterThan(1)
120 }) 120 })
121 121
122 it('Should make a complex search', async function () { 122 it('Should make a complex search', async function () {
123 123
124 async function check (search: VideosSearchQuery, exists = true) { 124 async function check (search: VideosSearchQuery, exists = true) {
125 const res = await advancedVideosSearch(server.url, search) 125 const body = await command.advancedVideoSearch({ search })
126 126
127 if (exists === false) { 127 if (exists === false) {
128 expect(res.body.total).to.equal(0) 128 expect(body.total).to.equal(0)
129 expect(res.body.data).to.have.lengthOf(0) 129 expect(body.data).to.have.lengthOf(0)
130 return 130 return
131 } 131 }
132 132
133 expect(res.body.total).to.equal(1) 133 expect(body.total).to.equal(1)
134 expect(res.body.data).to.have.lengthOf(1) 134 expect(body.data).to.have.lengthOf(1)
135 135
136 const video: Video = res.body.data[0] 136 const video = body.data[0]
137 137
138 expect(video.name).to.equal('What is PeerTube?') 138 expect(video.name).to.equal('What is PeerTube?')
139 expect(video.category.label).to.equal('Science & Technology') 139 expect(video.category.label).to.equal('Science & Technology')
@@ -206,10 +206,10 @@ describe('Test videos search', function () {
206 count: 5 206 count: 5
207 } 207 }
208 208
209 const res = await advancedVideosSearch(server.url, search) 209 const body = await command.advancedVideoSearch({ search })
210 210
211 expect(res.body.total).to.be.greaterThan(5) 211 expect(body.total).to.be.greaterThan(5)
212 expect(res.body.data).to.have.lengthOf(5) 212 expect(body.data).to.have.lengthOf(5)
213 }) 213 })
214 214
215 it('Should use the nsfw instance policy as default', async function () { 215 it('Should use the nsfw instance policy as default', async function () {
@@ -218,10 +218,10 @@ describe('Test videos search', function () {
218 { 218 {
219 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'display' } }) 219 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'display' } })
220 220
221 const res = await searchVideo(server.url, 'NSFW search index', '-match') 221 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
222 const video = res.body.data[0] as Video 222 expect(body.data).to.have.length.greaterThan(0)
223 223
224 expect(res.body.data).to.have.length.greaterThan(0) 224 const video = body.data[0]
225 expect(video.nsfw).to.be.true 225 expect(video.nsfw).to.be.true
226 226
227 nsfwUUID = video.uuid 227 nsfwUUID = video.uuid
@@ -230,13 +230,12 @@ describe('Test videos search', function () {
230 { 230 {
231 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'do_not_list' } }) 231 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'do_not_list' } })
232 232
233 const res = await searchVideo(server.url, 'NSFW search index', '-match') 233 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
234 234
235 try { 235 try {
236 expect(res.body.data).to.have.lengthOf(0) 236 expect(body.data).to.have.lengthOf(0)
237 } catch (err) { 237 } catch {
238 // 238 const video = body.data[0]
239 const video = res.body.data[0] as Video
240 239
241 expect(video.uuid).not.equal(nsfwUUID) 240 expect(video.uuid).not.equal(nsfwUUID)
242 } 241 }
@@ -247,19 +246,19 @@ describe('Test videos search', function () {
247 describe('Channels search', async function () { 246 describe('Channels search', async function () {
248 247
249 it('Should make a simple search and not have results', async function () { 248 it('Should make a simple search and not have results', async function () {
250 const res = await searchVideoChannel(server.url, 'a'.repeat(500)) 249 const body = await command.searchChannels({ search: 'a'.repeat(500) })
251 250
252 expect(res.body.total).to.equal(0) 251 expect(body.total).to.equal(0)
253 expect(res.body.data).to.have.lengthOf(0) 252 expect(body.data).to.have.lengthOf(0)
254 }) 253 })
255 254
256 it('Should make a search and have results', async function () { 255 it('Should make a search and have results', async function () {
257 const res = await advancedVideoChannelSearch(server.url, { search: 'Framasoft', sort: 'createdAt' }) 256 const body = await command.advancedChannelSearch({ search: { search: 'Framasoft', sort: 'createdAt' } })
258 257
259 expect(res.body.total).to.be.greaterThan(0) 258 expect(body.total).to.be.greaterThan(0)
260 expect(res.body.data).to.have.length.greaterThan(0) 259 expect(body.data).to.have.length.greaterThan(0)
261 260
262 const videoChannel: VideoChannel = res.body.data[0] 261 const videoChannel = body.data[0]
263 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') 262 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
264 expect(videoChannel.host).to.equal('framatube.org') 263 expect(videoChannel.host).to.equal('framatube.org')
265 expect(videoChannel.avatar).to.exist 264 expect(videoChannel.avatar).to.exist
@@ -272,29 +271,29 @@ describe('Test videos search', function () {
272 }) 271 })
273 272
274 it('Should have a correct pagination', async function () { 273 it('Should have a correct pagination', async function () {
275 const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 }) 274 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
276 275
277 expect(res.body.total).to.be.greaterThan(2) 276 expect(body.total).to.be.greaterThan(2)
278 expect(res.body.data).to.have.lengthOf(2) 277 expect(body.data).to.have.lengthOf(2)
279 }) 278 })
280 }) 279 })
281 280
282 describe('Playlists search', async function () { 281 describe('Playlists search', async function () {
283 282
284 it('Should make a simple search and not have results', async function () { 283 it('Should make a simple search and not have results', async function () {
285 const res = await searchVideoPlaylists(server.url, 'a'.repeat(500)) 284 const body = await command.searchPlaylists({ search: 'a'.repeat(500) })
286 285
287 expect(res.body.total).to.equal(0) 286 expect(body.total).to.equal(0)
288 expect(res.body.data).to.have.lengthOf(0) 287 expect(body.data).to.have.lengthOf(0)
289 }) 288 })
290 289
291 it('Should make a search and have results', async function () { 290 it('Should make a search and have results', async function () {
292 const res = await advancedVideoPlaylistSearch(server.url, { search: 'E2E playlist', sort: '-match' }) 291 const body = await command.advancedPlaylistSearch({ search: { search: 'E2E playlist', sort: '-match' } })
293 292
294 expect(res.body.total).to.be.greaterThan(0) 293 expect(body.total).to.be.greaterThan(0)
295 expect(res.body.data).to.have.length.greaterThan(0) 294 expect(body.data).to.have.length.greaterThan(0)
296 295
297 const videoPlaylist: VideoPlaylist = res.body.data[0] 296 const videoPlaylist = body.data[0]
298 297
299 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') 298 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
300 expect(videoPlaylist.thumbnailUrl).to.exist 299 expect(videoPlaylist.thumbnailUrl).to.exist
@@ -322,10 +321,10 @@ describe('Test videos search', function () {
322 }) 321 })
323 322
324 it('Should have a correct pagination', async function () { 323 it('Should have a correct pagination', async function () {
325 const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 }) 324 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
326 325
327 expect(res.body.total).to.be.greaterThan(2) 326 expect(body.total).to.be.greaterThan(2)
328 expect(res.body.data).to.have.lengthOf(2) 327 expect(body.data).to.have.lengthOf(2)
329 }) 328 })
330 }) 329 })
331 330
diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts
index ab17d55e9..1862ecd31 100644
--- a/server/tests/api/search/search-playlists.ts
+++ b/server/tests/api/search/search-playlists.ts
@@ -2,14 +2,13 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoPlaylist, VideoPlaylistPrivacy } from '@shared/models' 5import { VideoPlaylistPrivacy } from '@shared/models'
6import { 6import {
7 addVideoInPlaylist, 7 addVideoInPlaylist,
8 advancedVideoPlaylistSearch,
9 cleanupTests, 8 cleanupTests,
10 createVideoPlaylist, 9 createVideoPlaylist,
11 flushAndRunServer, 10 flushAndRunServer,
12 searchVideoPlaylists, 11 SearchCommand,
13 ServerInfo, 12 ServerInfo,
14 setAccessTokensToServers, 13 setAccessTokensToServers,
15 setDefaultVideoChannel, 14 setDefaultVideoChannel,
@@ -20,6 +19,7 @@ const expect = chai.expect
20 19
21describe('Test playlists search', function () { 20describe('Test playlists search', function () {
22 let server: ServerInfo = null 21 let server: ServerInfo = null
22 let command: SearchCommand
23 23
24 before(async function () { 24 before(async function () {
25 this.timeout(30000) 25 this.timeout(30000)
@@ -71,13 +71,15 @@ describe('Test playlists search', function () {
71 } 71 }
72 await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) 72 await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes })
73 } 73 }
74
75 command = server.searchCommand
74 }) 76 })
75 77
76 it('Should make a simple search and not have results', async function () { 78 it('Should make a simple search and not have results', async function () {
77 const res = await searchVideoPlaylists(server.url, 'abc') 79 const body = await command.searchPlaylists({ search: 'abc' })
78 80
79 expect(res.body.total).to.equal(0) 81 expect(body.total).to.equal(0)
80 expect(res.body.data).to.have.lengthOf(0) 82 expect(body.data).to.have.lengthOf(0)
81 }) 83 })
82 84
83 it('Should make a search and have results', async function () { 85 it('Should make a search and have results', async function () {
@@ -87,11 +89,11 @@ describe('Test playlists search', function () {
87 start: 0, 89 start: 0,
88 count: 1 90 count: 1
89 } 91 }
90 const res = await advancedVideoPlaylistSearch(server.url, search) 92 const body = await command.advancedPlaylistSearch({ search })
91 expect(res.body.total).to.equal(1) 93 expect(body.total).to.equal(1)
92 expect(res.body.data).to.have.lengthOf(1) 94 expect(body.data).to.have.lengthOf(1)
93 95
94 const playlist: VideoPlaylist = res.body.data[0] 96 const playlist = body.data[0]
95 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos') 97 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
96 expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid) 98 expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid)
97 } 99 }
@@ -102,11 +104,11 @@ describe('Test playlists search', function () {
102 start: 0, 104 start: 0,
103 count: 1 105 count: 1
104 } 106 }
105 const res = await advancedVideoPlaylistSearch(server.url, search) 107 const body = await command.advancedPlaylistSearch({ search })
106 expect(res.body.total).to.equal(1) 108 expect(body.total).to.equal(1)
107 expect(res.body.data).to.have.lengthOf(1) 109 expect(body.data).to.have.lengthOf(1)
108 110
109 const playlist: VideoPlaylist = res.body.data[0] 111 const playlist = body.data[0]
110 expect(playlist.displayName).to.equal('Johan & Anna Libert musics') 112 expect(playlist.displayName).to.equal('Johan & Anna Libert musics')
111 } 113 }
112 }) 114 })
@@ -117,9 +119,9 @@ describe('Test playlists search', function () {
117 start: 0, 119 start: 0,
118 count: 1 120 count: 1
119 } 121 }
120 const res = await advancedVideoPlaylistSearch(server.url, search) 122 const body = await command.advancedPlaylistSearch({ search })
121 expect(res.body.total).to.equal(0) 123 expect(body.total).to.equal(0)
122 expect(res.body.data).to.have.lengthOf(0) 124 expect(body.data).to.have.lengthOf(0)
123 }) 125 })
124 126
125 after(async function () { 127 after(async function () {
diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts
index 5b8907961..f0482c7e0 100644
--- a/server/tests/api/search/search-videos.ts
+++ b/server/tests/api/search/search-videos.ts
@@ -4,12 +4,11 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoPrivacy } from '@shared/models' 5import { VideoPrivacy } from '@shared/models'
6import { 6import {
7 advancedVideosSearch,
8 cleanupTests, 7 cleanupTests,
9 createLive, 8 createLive,
10 flushAndRunServer, 9 flushAndRunServer,
11 immutableAssign, 10 immutableAssign,
12 searchVideo, 11 SearchCommand,
13 sendRTMPStreamInVideo, 12 sendRTMPStreamInVideo,
14 ServerInfo, 13 ServerInfo,
15 setAccessTokensToServers, 14 setAccessTokensToServers,
@@ -29,6 +28,8 @@ describe('Test videos search', function () {
29 let startDate: string 28 let startDate: string
30 let videoUUID: string 29 let videoUUID: string
31 30
31 let command: SearchCommand
32
32 before(async function () { 33 before(async function () {
33 this.timeout(60000) 34 this.timeout(60000)
34 35
@@ -144,21 +145,23 @@ describe('Test videos search', function () {
144 await uploadVideo(server.url, server.accessToken, attributes1) 145 await uploadVideo(server.url, server.accessToken, attributes1)
145 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) 146 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 }))
146 } 147 }
148
149 command = server.searchCommand
147 }) 150 })
148 151
149 it('Should make a simple search and not have results', async function () { 152 it('Should make a simple search and not have results', async function () {
150 const res = await searchVideo(server.url, 'abc') 153 const body = await command.searchVideos({ search: 'abc' })
151 154
152 expect(res.body.total).to.equal(0) 155 expect(body.total).to.equal(0)
153 expect(res.body.data).to.have.lengthOf(0) 156 expect(body.data).to.have.lengthOf(0)
154 }) 157 })
155 158
156 it('Should make a simple search and have results', async function () { 159 it('Should make a simple search and have results', async function () {
157 const res = await searchVideo(server.url, '4444 5555 duplicate') 160 const body = await command.searchVideos({ search: '4444 5555 duplicate' })
158 161
159 expect(res.body.total).to.equal(2) 162 expect(body.total).to.equal(2)
160 163
161 const videos = res.body.data 164 const videos = body.data
162 expect(videos).to.have.lengthOf(2) 165 expect(videos).to.have.lengthOf(2)
163 166
164 // bestmatch 167 // bestmatch
@@ -167,15 +170,15 @@ describe('Test videos search', function () {
167 }) 170 })
168 171
169 it('Should make a search on tags too, and have results', async function () { 172 it('Should make a search on tags too, and have results', async function () {
170 const query = { 173 const search = {
171 search: 'aaaa', 174 search: 'aaaa',
172 categoryOneOf: [ 1 ] 175 categoryOneOf: [ 1 ]
173 } 176 }
174 const res = await advancedVideosSearch(server.url, query) 177 const body = await command.advancedVideoSearch({ search })
175 178
176 expect(res.body.total).to.equal(2) 179 expect(body.total).to.equal(2)
177 180
178 const videos = res.body.data 181 const videos = body.data
179 expect(videos).to.have.lengthOf(2) 182 expect(videos).to.have.lengthOf(2)
180 183
181 // bestmatch 184 // bestmatch
@@ -184,14 +187,14 @@ describe('Test videos search', function () {
184 }) 187 })
185 188
186 it('Should filter on tags without a search', async function () { 189 it('Should filter on tags without a search', async function () {
187 const query = { 190 const search = {
188 tagsAllOf: [ 'bbbb' ] 191 tagsAllOf: [ 'bbbb' ]
189 } 192 }
190 const res = await advancedVideosSearch(server.url, query) 193 const body = await command.advancedVideoSearch({ search })
191 194
192 expect(res.body.total).to.equal(2) 195 expect(body.total).to.equal(2)
193 196
194 const videos = res.body.data 197 const videos = body.data
195 expect(videos).to.have.lengthOf(2) 198 expect(videos).to.have.lengthOf(2)
196 199
197 expect(videos[0].name).to.equal('9999') 200 expect(videos[0].name).to.equal('9999')
@@ -199,14 +202,14 @@ describe('Test videos search', function () {
199 }) 202 })
200 203
201 it('Should filter on category without a search', async function () { 204 it('Should filter on category without a search', async function () {
202 const query = { 205 const search = {
203 categoryOneOf: [ 3 ] 206 categoryOneOf: [ 3 ]
204 } 207 }
205 const res = await advancedVideosSearch(server.url, query) 208 const body = await command.advancedVideoSearch({ search: search })
206 209
207 expect(res.body.total).to.equal(1) 210 expect(body.total).to.equal(1)
208 211
209 const videos = res.body.data 212 const videos = body.data
210 expect(videos).to.have.lengthOf(1) 213 expect(videos).to.have.lengthOf(1)
211 214
212 expect(videos[0].name).to.equal('6666 7777 8888') 215 expect(videos[0].name).to.equal('6666 7777 8888')
@@ -218,11 +221,16 @@ describe('Test videos search', function () {
218 categoryOneOf: [ 1 ], 221 categoryOneOf: [ 1 ],
219 tagsOneOf: [ 'aAaa', 'ffff' ] 222 tagsOneOf: [ 'aAaa', 'ffff' ]
220 } 223 }
221 const res1 = await advancedVideosSearch(server.url, query)
222 expect(res1.body.total).to.equal(2)
223 224
224 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] })) 225 {
225 expect(res2.body.total).to.equal(0) 226 const body = await command.advancedVideoSearch({ search: query })
227 expect(body.total).to.equal(2)
228 }
229
230 {
231 const body = await command.advancedVideoSearch({ search: { ...query, tagsOneOf: [ 'blabla' ] } })
232 expect(body.total).to.equal(0)
233 }
226 }) 234 })
227 235
228 it('Should search by tags (all of)', async function () { 236 it('Should search by tags (all of)', async function () {
@@ -231,14 +239,21 @@ describe('Test videos search', function () {
231 categoryOneOf: [ 1 ], 239 categoryOneOf: [ 1 ],
232 tagsAllOf: [ 'CCcc' ] 240 tagsAllOf: [ 'CCcc' ]
233 } 241 }
234 const res1 = await advancedVideosSearch(server.url, query)
235 expect(res1.body.total).to.equal(2)
236 242
237 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blAbla' ] })) 243 {
238 expect(res2.body.total).to.equal(0) 244 const body = await command.advancedVideoSearch({ search: query })
245 expect(body.total).to.equal(2)
246 }
239 247
240 const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'CCCC' ] })) 248 {
241 expect(res3.body.total).to.equal(1) 249 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'blAbla' ] } })
250 expect(body.total).to.equal(0)
251 }
252
253 {
254 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'bbbb', 'CCCC' ] } })
255 expect(body.total).to.equal(1)
256 }
242 }) 257 })
243 258
244 it('Should search by category', async function () { 259 it('Should search by category', async function () {
@@ -246,12 +261,17 @@ describe('Test videos search', function () {
246 search: '6666', 261 search: '6666',
247 categoryOneOf: [ 3 ] 262 categoryOneOf: [ 3 ]
248 } 263 }
249 const res1 = await advancedVideosSearch(server.url, query)
250 expect(res1.body.total).to.equal(1)
251 expect(res1.body.data[0].name).to.equal('6666 7777 8888')
252 264
253 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] })) 265 {
254 expect(res2.body.total).to.equal(0) 266 const body = await command.advancedVideoSearch({ search: query })
267 expect(body.total).to.equal(1)
268 expect(body.data[0].name).to.equal('6666 7777 8888')
269 }
270
271 {
272 const body = await command.advancedVideoSearch({ search: { ...query, categoryOneOf: [ 2 ] } })
273 expect(body.total).to.equal(0)
274 }
255 }) 275 })
256 276
257 it('Should search by licence', async function () { 277 it('Should search by licence', async function () {
@@ -259,13 +279,18 @@ describe('Test videos search', function () {
259 search: '4444 5555', 279 search: '4444 5555',
260 licenceOneOf: [ 2 ] 280 licenceOneOf: [ 2 ]
261 } 281 }
262 const res1 = await advancedVideosSearch(server.url, query)
263 expect(res1.body.total).to.equal(2)
264 expect(res1.body.data[0].name).to.equal('3333 4444 5555')
265 expect(res1.body.data[1].name).to.equal('3333 4444 5555 duplicate')
266 282
267 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] })) 283 {
268 expect(res2.body.total).to.equal(0) 284 const body = await command.advancedVideoSearch({ search: query })
285 expect(body.total).to.equal(2)
286 expect(body.data[0].name).to.equal('3333 4444 5555')
287 expect(body.data[1].name).to.equal('3333 4444 5555 duplicate')
288 }
289
290 {
291 const body = await command.advancedVideoSearch({ search: { ...query, licenceOneOf: [ 3 ] } })
292 expect(body.total).to.equal(0)
293 }
269 }) 294 })
270 295
271 it('Should search by languages', async function () { 296 it('Should search by languages', async function () {
@@ -275,23 +300,23 @@ describe('Test videos search', function () {
275 } 300 }
276 301
277 { 302 {
278 const res = await advancedVideosSearch(server.url, query) 303 const body = await command.advancedVideoSearch({ search: query })
279 expect(res.body.total).to.equal(2) 304 expect(body.total).to.equal(2)
280 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') 305 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
281 expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4') 306 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
282 } 307 }
283 308
284 { 309 {
285 const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'pl', 'en', '_unknown' ] })) 310 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'pl', 'en', '_unknown' ] } })
286 expect(res.body.total).to.equal(3) 311 expect(body.total).to.equal(3)
287 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') 312 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
288 expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4') 313 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
289 expect(res.body.data[2].name).to.equal('1111 2222 3333 - 5') 314 expect(body.data[2].name).to.equal('1111 2222 3333 - 5')
290 } 315 }
291 316
292 { 317 {
293 const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] })) 318 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'eo' ] } })
294 expect(res.body.total).to.equal(0) 319 expect(body.total).to.equal(0)
295 } 320 }
296 }) 321 })
297 322
@@ -301,10 +326,10 @@ describe('Test videos search', function () {
301 startDate 326 startDate
302 } 327 }
303 328
304 const res = await advancedVideosSearch(server.url, query) 329 const body = await command.advancedVideoSearch({ search: query })
305 expect(res.body.total).to.equal(4) 330 expect(body.total).to.equal(4)
306 331
307 const videos = res.body.data 332 const videos = body.data
308 expect(videos[0].name).to.equal('1111 2222 3333 - 5') 333 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
309 expect(videos[1].name).to.equal('1111 2222 3333 - 6') 334 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
310 expect(videos[2].name).to.equal('1111 2222 3333 - 7') 335 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
@@ -320,10 +345,10 @@ describe('Test videos search', function () {
320 licenceOneOf: [ 1, 4 ] 345 licenceOneOf: [ 1, 4 ]
321 } 346 }
322 347
323 const res = await advancedVideosSearch(server.url, query) 348 const body = await command.advancedVideoSearch({ search: query })
324 expect(res.body.total).to.equal(4) 349 expect(body.total).to.equal(4)
325 350
326 const videos = res.body.data 351 const videos = body.data
327 expect(videos[0].name).to.equal('1111 2222 3333') 352 expect(videos[0].name).to.equal('1111 2222 3333')
328 expect(videos[1].name).to.equal('1111 2222 3333 - 6') 353 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
329 expect(videos[2].name).to.equal('1111 2222 3333 - 7') 354 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
@@ -340,10 +365,10 @@ describe('Test videos search', function () {
340 sort: '-name' 365 sort: '-name'
341 } 366 }
342 367
343 const res = await advancedVideosSearch(server.url, query) 368 const body = await command.advancedVideoSearch({ search: query })
344 expect(res.body.total).to.equal(4) 369 expect(body.total).to.equal(4)
345 370
346 const videos = res.body.data 371 const videos = body.data
347 expect(videos[0].name).to.equal('1111 2222 3333 - 8') 372 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
348 expect(videos[1].name).to.equal('1111 2222 3333 - 7') 373 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
349 expect(videos[2].name).to.equal('1111 2222 3333 - 6') 374 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
@@ -362,10 +387,10 @@ describe('Test videos search', function () {
362 count: 1 387 count: 1
363 } 388 }
364 389
365 const res = await advancedVideosSearch(server.url, query) 390 const body = await command.advancedVideoSearch({ search: query })
366 expect(res.body.total).to.equal(4) 391 expect(body.total).to.equal(4)
367 392
368 const videos = res.body.data 393 const videos = body.data
369 expect(videos[0].name).to.equal('1111 2222 3333 - 8') 394 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
370 }) 395 })
371 396
@@ -381,10 +406,10 @@ describe('Test videos search', function () {
381 count: 1 406 count: 1
382 } 407 }
383 408
384 const res = await advancedVideosSearch(server.url, query) 409 const body = await command.advancedVideoSearch({ search: query })
385 expect(res.body.total).to.equal(4) 410 expect(body.total).to.equal(4)
386 411
387 const videos = res.body.data 412 const videos = body.data
388 expect(videos[0].name).to.equal('1111 2222 3333') 413 expect(videos[0].name).to.equal('1111 2222 3333')
389 }) 414 })
390 415
@@ -399,32 +424,32 @@ describe('Test videos search', function () {
399 424
400 { 425 {
401 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }) 426 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
402 const res = await advancedVideosSearch(server.url, query) 427 const body = await command.advancedVideoSearch({ search: query })
403 428
404 expect(res.body.total).to.equal(1) 429 expect(body.total).to.equal(1)
405 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') 430 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
406 } 431 }
407 432
408 { 433 {
409 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }) 434 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' })
410 const res = await advancedVideosSearch(server.url, query) 435 const body = await command.advancedVideoSearch({ search: query })
411 436
412 expect(res.body.total).to.equal(1) 437 expect(body.total).to.equal(1)
413 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') 438 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
414 } 439 }
415 440
416 { 441 {
417 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }) 442 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' })
418 const res = await advancedVideosSearch(server.url, query) 443 const body = await command.advancedVideoSearch({ search: query })
419 444
420 expect(res.body.total).to.equal(0) 445 expect(body.total).to.equal(0)
421 } 446 }
422 447
423 { 448 {
424 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }) 449 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
425 const res = await advancedVideosSearch(server.url, query) 450 const body = await command.advancedVideoSearch({ search: query })
426 451
427 expect(res.body.total).to.equal(0) 452 expect(body.total).to.equal(0)
428 } 453 }
429 454
430 { 455 {
@@ -432,9 +457,9 @@ describe('Test videos search', function () {
432 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', 457 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
433 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z' 458 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
434 }) 459 })
435 const res = await advancedVideosSearch(server.url, query) 460 const body = await command.advancedVideoSearch({ search: query })
436 461
437 expect(res.body.total).to.equal(0) 462 expect(body.total).to.equal(0)
438 } 463 }
439 464
440 { 465 {
@@ -442,19 +467,19 @@ describe('Test videos search', function () {
442 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', 467 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
443 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z' 468 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
444 }) 469 })
445 const res = await advancedVideosSearch(server.url, query) 470 const body = await command.advancedVideoSearch({ search: query })
446 471
447 expect(res.body.total).to.equal(1) 472 expect(body.total).to.equal(1)
448 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') 473 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
449 } 474 }
450 }) 475 })
451 476
452 it('Should search by UUID', async function () { 477 it('Should search by UUID', async function () {
453 const search = videoUUID 478 const search = videoUUID
454 const res = await advancedVideosSearch(server.url, { search }) 479 const body = await command.advancedVideoSearch({ search: { search } })
455 480
456 expect(res.body.total).to.equal(1) 481 expect(body.total).to.equal(1)
457 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') 482 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
458 }) 483 })
459 484
460 it('Should search by live', async function () { 485 it('Should search by live', async function () {
@@ -471,10 +496,10 @@ describe('Test videos search', function () {
471 } 496 }
472 497
473 { 498 {
474 const res = await advancedVideosSearch(server.url, { isLive: true }) 499 const body = await command.advancedVideoSearch({ search: { isLive: true } })
475 500
476 expect(res.body.total).to.equal(0) 501 expect(body.total).to.equal(0)
477 expect(res.body.data).to.have.lengthOf(0) 502 expect(body.data).to.have.lengthOf(0)
478 } 503 }
479 504
480 { 505 {
@@ -482,15 +507,15 @@ describe('Test videos search', function () {
482 const resLive = await createLive(server.url, server.accessToken, liveOptions) 507 const resLive = await createLive(server.url, server.accessToken, liveOptions)
483 const liveVideoId = resLive.body.video.uuid 508 const liveVideoId = resLive.body.video.uuid
484 509
485 const command = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId) 510 const ffmpegCommand = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId)
486 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) 511 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId)
487 512
488 const res = await advancedVideosSearch(server.url, { isLive: true }) 513 const body = await command.advancedVideoSearch({ search: { isLive: true } })
489 514
490 expect(res.body.total).to.equal(1) 515 expect(body.total).to.equal(1)
491 expect(res.body.data[0].name).to.equal('live') 516 expect(body.data[0].name).to.equal('live')
492 517
493 await stopFfmpeg(command) 518 await stopFfmpeg(ffmpegCommand)
494 } 519 }
495 }) 520 })
496 521
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts
index 6c98c9f12..24a4c6152 100644
--- a/server/tests/api/videos/video-nsfw.ts
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -14,8 +14,6 @@ import {
14 getVideoChannelVideos, 14 getVideoChannelVideos,
15 getVideosList, 15 getVideosList,
16 getVideosListWithToken, 16 getVideosListWithToken,
17 searchVideo,
18 searchVideoWithToken,
19 ServerInfo, 17 ServerInfo,
20 setAccessTokensToServers, 18 setAccessTokensToServers,
21 updateCustomConfig, 19 updateCustomConfig,
@@ -23,7 +21,7 @@ import {
23 uploadVideo, 21 uploadVideo,
24 userLogin 22 userLogin
25} from '@shared/extra-utils' 23} from '@shared/extra-utils'
26import { CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models' 24import { BooleanBothQuery, CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models'
27 25
28const expect = chai.expect 26const expect = chai.expect
29 27
@@ -37,7 +35,7 @@ describe('Test video NSFW policy', function () {
37 let userAccessToken: string 35 let userAccessToken: string
38 let customConfig: CustomConfig 36 let customConfig: CustomConfig
39 37
40 function getVideosFunctions (token?: string, query = {}) { 38 function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) {
41 return getMyUserInformation(server.url, server.accessToken) 39 return getMyUserInformation(server.url, server.accessToken)
42 .then(res => { 40 .then(res => {
43 const user: User = res.body 41 const user: User = res.body
@@ -49,7 +47,7 @@ describe('Test video NSFW policy', function () {
49 if (token) { 47 if (token) {
50 promises = [ 48 promises = [
51 getVideosListWithToken(server.url, token, query), 49 getVideosListWithToken(server.url, token, query),
52 searchVideoWithToken(server.url, 'n', token, query), 50 server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', ...query } }),
53 getAccountVideos(server.url, token, accountName, 0, 5, undefined, query), 51 getAccountVideos(server.url, token, accountName, 0, 5, undefined, query),
54 getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query) 52 getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query)
55 ] 53 ]
@@ -66,7 +64,7 @@ describe('Test video NSFW policy', function () {
66 64
67 promises = [ 65 promises = [
68 getVideosList(server.url), 66 getVideosList(server.url),
69 searchVideo(server.url, 'n'), 67 server.searchCommand.searchVideos({ search: 'n' }),
70 getAccountVideos(server.url, undefined, accountName, 0, 5), 68 getAccountVideos(server.url, undefined, accountName, 0, 5),
71 getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5) 69 getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5)
72 ] 70 ]
@@ -230,7 +228,7 @@ describe('Test video NSFW policy', function () {
230 }) 228 })
231 229
232 it('Should display NSFW videos when the nsfw param === true', async function () { 230 it('Should display NSFW videos when the nsfw param === true', async function () {
233 for (const res of await getVideosFunctions(server.accessToken, { nsfw: true })) { 231 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'true' })) {
234 expect(res.body.total).to.equal(1) 232 expect(res.body.total).to.equal(1)
235 233
236 const videos = res.body.data 234 const videos = res.body.data
@@ -240,7 +238,7 @@ describe('Test video NSFW policy', function () {
240 }) 238 })
241 239
242 it('Should hide NSFW videos when the nsfw param === true', async function () { 240 it('Should hide NSFW videos when the nsfw param === true', async function () {
243 for (const res of await getVideosFunctions(server.accessToken, { nsfw: false })) { 241 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'false' })) {
244 expect(res.body.total).to.equal(1) 242 expect(res.body.total).to.equal(1)
245 243
246 const videos = res.body.data 244 const videos = res.body.data
diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts
index b25cff879..209b93014 100644
--- a/server/tests/api/videos/videos-history.ts
+++ b/server/tests/api/videos/videos-history.ts
@@ -1,7 +1,8 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils'
5import { 6import {
6 cleanupTests, 7 cleanupTests,
7 createUser, 8 createUser,
@@ -10,17 +11,15 @@ import {
10 getVideoWithToken, 11 getVideoWithToken,
11 killallServers, 12 killallServers,
12 reRunServer, 13 reRunServer,
13 searchVideoWithToken,
14 ServerInfo, 14 ServerInfo,
15 setAccessTokensToServers, 15 setAccessTokensToServers,
16 updateMyUser, 16 updateMyUser,
17 uploadVideo, 17 uploadVideo,
18 userLogin, 18 userLogin,
19 wait 19 wait
20} from '../../../../shared/extra-utils' 20} from '@shared/extra-utils'
21import { Video, VideoDetails } from '../../../../shared/models/videos' 21import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '@shared/extra-utils/videos/video-history'
22import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '../../../../shared/extra-utils/videos/video-history' 22import { Video, VideoDetails } from '@shared/models'
23import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
24 23
25const expect = chai.expect 24const expect = chai.expect
26 25
@@ -89,8 +88,8 @@ describe('Test videos history', function () {
89 } 88 }
90 89
91 { 90 {
92 const res = await searchVideoWithToken(server.url, 'video', server.accessToken) 91 const body = await server.searchCommand.searchVideos({ token: server.accessToken, search: 'video' })
93 videosOfVideos.push(res.body.data) 92 videosOfVideos.push(body.data)
94 } 93 }
95 94
96 for (const videos of videosOfVideos) { 95 for (const videos of videosOfVideos) {
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index 644b41dea..e2ec5457b 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -2,17 +2,15 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { advancedVideoChannelSearch } from '@shared/extra-utils/search/video-channels' 5import { HttpStatusCode } from '@shared/core-utils'
6import { ServerConfig } from '@shared/models'
7import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
8import { 6import {
9 addVideoCommentReply, 7 addVideoCommentReply,
10 addVideoCommentThread, 8 addVideoCommentThread,
11 advancedVideoPlaylistSearch, 9 cleanupTests,
12 advancedVideosSearch,
13 createLive, 10 createLive,
14 createVideoPlaylist, 11 createVideoPlaylist,
15 doubleFollow, 12 doubleFollow,
13 flushAndRunMultipleServers,
16 getAccountVideos, 14 getAccountVideos,
17 getConfig, 15 getConfig,
18 getMyVideos, 16 getMyVideos,
@@ -28,17 +26,19 @@ import {
28 installPlugin, 26 installPlugin,
29 makeRawRequest, 27 makeRawRequest,
30 registerUser, 28 registerUser,
29 ServerInfo,
31 setAccessTokensToServers, 30 setAccessTokensToServers,
32 setDefaultVideoChannel, 31 setDefaultVideoChannel,
33 updateCustomSubConfig, 32 updateCustomSubConfig,
34 updateVideo, 33 updateVideo,
35 uploadVideo, 34 uploadVideo,
36 uploadVideoAndGetId, 35 uploadVideoAndGetId,
37 waitJobs 36 waitJobs,
38} from '../../../shared/extra-utils' 37 waitUntilLog
39import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' 38} from '@shared/extra-utils'
40import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports' 39import { getGoodVideoUrl, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports'
41import { 40import {
41 ServerConfig,
42 VideoCommentThreadTree, 42 VideoCommentThreadTree,
43 VideoDetails, 43 VideoDetails,
44 VideoImport, 44 VideoImport,
@@ -46,7 +46,7 @@ import {
46 VideoPlaylist, 46 VideoPlaylist,
47 VideoPlaylistPrivacy, 47 VideoPlaylistPrivacy,
48 VideoPrivacy 48 VideoPrivacy
49} from '../../../shared/models/videos' 49} from '@shared/models'
50 50
51const expect = chai.expect 51const expect = chai.expect
52 52
@@ -486,8 +486,10 @@ describe('Test plugin filter hooks', function () {
486 }) 486 })
487 487
488 it('Should run filter:api.search.videos.local.list.{params,result}', async function () { 488 it('Should run filter:api.search.videos.local.list.{params,result}', async function () {
489 await advancedVideosSearch(servers[0].url, { 489 await servers[0].searchCommand.advancedVideoSearch({
490 search: 'Sun Quan' 490 search: {
491 search: 'Sun Quan'
492 }
491 }) 493 })
492 494
493 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1) 495 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1)
@@ -495,9 +497,11 @@ describe('Test plugin filter hooks', function () {
495 }) 497 })
496 498
497 it('Should run filter:api.search.videos.index.list.{params,result}', async function () { 499 it('Should run filter:api.search.videos.index.list.{params,result}', async function () {
498 await advancedVideosSearch(servers[0].url, { 500 await servers[0].searchCommand.advancedVideoSearch({
499 search: 'Sun Quan', 501 search: {
500 searchTarget: 'search-index' 502 search: 'Sun Quan',
503 searchTarget: 'search-index'
504 }
501 }) 505 })
502 506
503 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1) 507 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1)
@@ -507,8 +511,10 @@ describe('Test plugin filter hooks', function () {
507 }) 511 })
508 512
509 it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () { 513 it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () {
510 await advancedVideoChannelSearch(servers[0].url, { 514 await servers[0].searchCommand.advancedChannelSearch({
511 search: 'Sun Ce' 515 search: {
516 search: 'Sun Ce'
517 }
512 }) 518 })
513 519
514 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1) 520 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1)
@@ -516,9 +522,11 @@ describe('Test plugin filter hooks', function () {
516 }) 522 })
517 523
518 it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () { 524 it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () {
519 await advancedVideoChannelSearch(servers[0].url, { 525 await servers[0].searchCommand.advancedChannelSearch({
520 search: 'Sun Ce', 526 search: {
521 searchTarget: 'search-index' 527 search: 'Sun Ce',
528 searchTarget: 'search-index'
529 }
522 }) 530 })
523 531
524 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1) 532 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1)
@@ -528,8 +536,10 @@ describe('Test plugin filter hooks', function () {
528 }) 536 })
529 537
530 it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () { 538 it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () {
531 await advancedVideoPlaylistSearch(servers[0].url, { 539 await servers[0].searchCommand.advancedPlaylistSearch({
532 search: 'Sun Jian' 540 search: {
541 search: 'Sun Jian'
542 }
533 }) 543 })
534 544
535 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1) 545 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1)
@@ -537,9 +547,11 @@ describe('Test plugin filter hooks', function () {
537 }) 547 })
538 548
539 it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () { 549 it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () {
540 await advancedVideoPlaylistSearch(servers[0].url, { 550 await servers[0].searchCommand.advancedPlaylistSearch({
541 search: 'Sun Jian', 551 search: {
542 searchTarget: 'search-index' 552 search: 'Sun Jian',
553 searchTarget: 'search-index'
554 }
543 }) 555 })
544 556
545 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1) 557 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1)
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts
index 38c8c4c1c..067e6fb65 100644
--- a/shared/extra-utils/index.ts
+++ b/shared/extra-utils/index.ts
@@ -11,9 +11,7 @@ export * from './overviews'
11export * from './requests/check-api-params' 11export * from './requests/check-api-params'
12export * from './requests/requests' 12export * from './requests/requests'
13 13
14export * from './search/video-channels' 14export * from './search'
15export * from './search/video-playlists'
16export * from './search/videos'
17 15
18export * from './server/activitypub' 16export * from './server/activitypub'
19export * from './server/clients' 17export * from './server/clients'
diff --git a/shared/extra-utils/overviews/overviews-command.ts b/shared/extra-utils/overviews/overviews-command.ts
index 0ac3cbd33..6f56b0ce4 100644
--- a/shared/extra-utils/overviews/overviews-command.ts
+++ b/shared/extra-utils/overviews/overviews-command.ts
@@ -6,7 +6,6 @@ export class OverviewsCommand extends AbstractCommand {
6 6
7 getVideos (options: OverrideCommandOptions & { 7 getVideos (options: OverrideCommandOptions & {
8 page: number 8 page: number
9 token?: string
10 }) { 9 }) {
11 const { token, page } = options 10 const { token, page } = options
12 const path = '/api/v1/overviews/videos' 11 const path = '/api/v1/overviews/videos'
diff --git a/shared/extra-utils/search/index.ts b/shared/extra-utils/search/index.ts
new file mode 100644
index 000000000..48dbe8ae9
--- /dev/null
+++ b/shared/extra-utils/search/index.ts
@@ -0,0 +1 @@
export * from './search-command'
diff --git a/shared/extra-utils/search/search-command.ts b/shared/extra-utils/search/search-command.ts
new file mode 100644
index 000000000..d4cfab32b
--- /dev/null
+++ b/shared/extra-utils/search/search-command.ts
@@ -0,0 +1,101 @@
1import {
2 ResultList,
3 Video,
4 VideoChannel,
5 VideoChannelsSearchQuery,
6 VideoPlaylist,
7 VideoPlaylistsSearchQuery,
8 VideosSearchQuery
9} from '@shared/models'
10import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
11import { AbstractCommand, OverrideCommandOptions } from '../shared'
12
13export class SearchCommand extends AbstractCommand {
14
15 searchChannels (options: OverrideCommandOptions & {
16 search: string
17 }) {
18 return this.advancedChannelSearch({
19 ...options,
20
21 search: { search: options.search }
22 })
23 }
24
25 advancedChannelSearch (options: OverrideCommandOptions & {
26 search: VideoChannelsSearchQuery
27 }) {
28 const { search, token } = options
29 const path = '/api/v1/search/video-channels'
30
31 return this.getRequestBody<ResultList<VideoChannel>>({
32 ...options,
33
34 token: token || null,
35
36 path,
37 query: search,
38 defaultExpectedStatus: HttpStatusCode.OK_200
39 })
40 }
41
42 searchPlaylists (options: OverrideCommandOptions & {
43 search: string
44 }) {
45 return this.advancedPlaylistSearch({
46 ...options,
47
48 search: { search: options.search }
49 })
50 }
51
52 advancedPlaylistSearch (options: OverrideCommandOptions & {
53 search: VideoPlaylistsSearchQuery
54 }) {
55 const { search, token } = options
56 const path = '/api/v1/search/video-playlists'
57
58 return this.getRequestBody<ResultList<VideoPlaylist>>({
59 ...options,
60
61 token: token || null,
62
63 path,
64 query: search,
65 defaultExpectedStatus: HttpStatusCode.OK_200
66 })
67 }
68
69 searchVideos (options: OverrideCommandOptions & {
70 search: string
71 sort?: string
72 }) {
73 const { search, sort } = options
74
75 return this.advancedVideoSearch({
76 ...options,
77
78 search: {
79 search: search,
80 sort: sort ?? '-publishedAt'
81 }
82 })
83 }
84
85 advancedVideoSearch (options: OverrideCommandOptions & {
86 search: VideosSearchQuery
87 }) {
88 const { search, token } = options
89 const path = '/api/v1/search/videos'
90
91 return this.getRequestBody<ResultList<Video>>({
92 ...options,
93
94 token: token || null,
95
96 path,
97 query: search,
98 defaultExpectedStatus: HttpStatusCode.OK_200
99 })
100 }
101}
diff --git a/shared/extra-utils/search/video-channels.ts b/shared/extra-utils/search/video-channels.ts
deleted file mode 100644
index 8e0f42578..000000000
--- a/shared/extra-utils/search/video-channels.ts
+++ /dev/null
@@ -1,36 +0,0 @@
1import { VideoChannelsSearchQuery } from '@shared/models'
2import { makeGetRequest } from '../requests/requests'
3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4
5function searchVideoChannel (url: string, search: string, token?: string, statusCodeExpected = HttpStatusCode.OK_200) {
6 const path = '/api/v1/search/video-channels'
7
8 return makeGetRequest({
9 url,
10 path,
11 query: {
12 sort: '-createdAt',
13 search
14 },
15 token,
16 statusCodeExpected
17 })
18}
19
20function advancedVideoChannelSearch (url: string, search: VideoChannelsSearchQuery) {
21 const path = '/api/v1/search/video-channels'
22
23 return makeGetRequest({
24 url,
25 path,
26 query: search,
27 statusCodeExpected: HttpStatusCode.OK_200
28 })
29}
30
31// ---------------------------------------------------------------------------
32
33export {
34 searchVideoChannel,
35 advancedVideoChannelSearch
36}
diff --git a/shared/extra-utils/search/video-playlists.ts b/shared/extra-utils/search/video-playlists.ts
deleted file mode 100644
index c22831df7..000000000
--- a/shared/extra-utils/search/video-playlists.ts
+++ /dev/null
@@ -1,36 +0,0 @@
1import { VideoPlaylistsSearchQuery } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
3import { makeGetRequest } from '../requests/requests'
4
5function searchVideoPlaylists (url: string, search: string, token?: string, statusCodeExpected = HttpStatusCode.OK_200) {
6 const path = '/api/v1/search/video-playlists'
7
8 return makeGetRequest({
9 url,
10 path,
11 query: {
12 sort: '-createdAt',
13 search
14 },
15 token,
16 statusCodeExpected
17 })
18}
19
20function advancedVideoPlaylistSearch (url: string, search: VideoPlaylistsSearchQuery) {
21 const path = '/api/v1/search/video-playlists'
22
23 return makeGetRequest({
24 url,
25 path,
26 query: search,
27 statusCodeExpected: HttpStatusCode.OK_200
28 })
29}
30
31// ---------------------------------------------------------------------------
32
33export {
34 searchVideoPlaylists,
35 advancedVideoPlaylistSearch
36}
diff --git a/shared/extra-utils/search/videos.ts b/shared/extra-utils/search/videos.ts
deleted file mode 100644
index db6edbd58..000000000
--- a/shared/extra-utils/search/videos.ts
+++ /dev/null
@@ -1,64 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import * as request from 'supertest'
4import { VideosSearchQuery } from '../../models/search'
5import { immutableAssign } from '../miscs/miscs'
6import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
7
8function searchVideo (url: string, search: string, sort = '-publishedAt') {
9 const path = '/api/v1/search/videos'
10
11 const query = { sort, search: search }
12 const req = request(url)
13 .get(path)
14 .query(query)
15 .set('Accept', 'application/json')
16
17 return req.expect(HttpStatusCode.OK_200)
18 .expect('Content-Type', /json/)
19}
20
21function searchVideoWithToken (url: string, search: string, token: string, query: { nsfw?: boolean } = {}) {
22 const path = '/api/v1/search/videos'
23 const req = request(url)
24 .get(path)
25 .set('Authorization', 'Bearer ' + token)
26 .query(immutableAssign(query, { sort: '-publishedAt', search }))
27 .set('Accept', 'application/json')
28
29 return req.expect(HttpStatusCode.OK_200)
30 .expect('Content-Type', /json/)
31}
32
33function searchVideoWithSort (url: string, search: string, sort: string) {
34 const path = '/api/v1/search/videos'
35
36 const query = { search, sort }
37
38 return request(url)
39 .get(path)
40 .query(query)
41 .set('Accept', 'application/json')
42 .expect(HttpStatusCode.OK_200)
43 .expect('Content-Type', /json/)
44}
45
46function advancedVideosSearch (url: string, options: VideosSearchQuery) {
47 const path = '/api/v1/search/videos'
48
49 return request(url)
50 .get(path)
51 .query(options)
52 .set('Accept', 'application/json')
53 .expect(HttpStatusCode.OK_200)
54 .expect('Content-Type', /json/)
55}
56
57// ---------------------------------------------------------------------------
58
59export {
60 searchVideo,
61 advancedVideosSearch,
62 searchVideoWithToken,
63 searchVideoWithSort
64}
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index 70be96cf6..8ccf790fc 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -15,6 +15,7 @@ import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../mi
15import { AbusesCommand } from '../moderation' 15import { AbusesCommand } from '../moderation'
16import { OverviewsCommand } from '../overviews' 16import { OverviewsCommand } from '../overviews'
17import { makeGetRequest } from '../requests/requests' 17import { makeGetRequest } from '../requests/requests'
18import { SearchCommand } from '../search'
18 19
19interface ServerInfo { 20interface ServerInfo {
20 app: ChildProcess 21 app: ChildProcess
@@ -75,6 +76,7 @@ interface ServerInfo {
75 logsCommand?: LogsCommand 76 logsCommand?: LogsCommand
76 abusesCommand?: AbusesCommand 77 abusesCommand?: AbusesCommand
77 overviewsCommand?: OverviewsCommand 78 overviewsCommand?: OverviewsCommand
79 searchCommand?: SearchCommand
78} 80}
79 81
80function parallelTests () { 82function parallelTests () {
@@ -287,6 +289,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
287 server.logsCommand = new LogsCommand(server) 289 server.logsCommand = new LogsCommand(server)
288 server.abusesCommand = new AbusesCommand(server) 290 server.abusesCommand = new AbusesCommand(server)
289 server.overviewsCommand = new OverviewsCommand(server) 291 server.overviewsCommand = new OverviewsCommand(server)
292 server.searchCommand = new SearchCommand(server)
290 293
291 res(server) 294 res(server)
292 }) 295 })
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts
index 469ea4d63..a45c0402a 100644
--- a/shared/extra-utils/videos/videos.ts
+++ b/shared/extra-utils/videos/videos.ts
@@ -10,7 +10,7 @@ import validator from 'validator'
10import { getLowercaseExtension } from '@server/helpers/core-utils' 10import { getLowercaseExtension } from '@server/helpers/core-utils'
11import { buildUUID } from '@server/helpers/uuid' 11import { buildUUID } from '@server/helpers/uuid'
12import { HttpStatusCode } from '@shared/core-utils' 12import { HttpStatusCode } from '@shared/core-utils'
13import { VideosCommonQuery } from '@shared/models' 13import { BooleanBothQuery, VideosCommonQuery } from '@shared/models'
14import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' 14import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
15import { VideoDetails, VideoPrivacy } from '../../models/videos' 15import { VideoDetails, VideoPrivacy } from '../../models/videos'
16import { 16import {
@@ -159,7 +159,7 @@ function getVideosList (url: string) {
159 .expect('Content-Type', /json/) 159 .expect('Content-Type', /json/)
160} 160}
161 161
162function getVideosListWithToken (url: string, token: string, query: { nsfw?: boolean } = {}) { 162function getVideosListWithToken (url: string, token: string, query: { nsfw?: BooleanBothQuery } = {}) {
163 const path = '/api/v1/videos' 163 const path = '/api/v1/videos'
164 164
165 return request(url) 165 return request(url)
@@ -219,7 +219,7 @@ function getAccountVideos (
219 count: number, 219 count: number,
220 sort?: string, 220 sort?: string,
221 query: { 221 query: {
222 nsfw?: boolean 222 nsfw?: BooleanBothQuery
223 search?: string 223 search?: string
224 } = {} 224 } = {}
225) { 225) {
@@ -245,7 +245,7 @@ function getVideoChannelVideos (
245 start: number, 245 start: number,
246 count: number, 246 count: number,
247 sort?: string, 247 sort?: string,
248 query: { nsfw?: boolean } = {} 248 query: { nsfw?: BooleanBothQuery } = {}
249) { 249) {
250 const path = '/api/v1/video-channels/' + videoChannelName + '/videos' 250 const path = '/api/v1/video-channels/' + videoChannelName + '/videos'
251 251