]>
Commit | Line | Data |
---|---|---|
3521ab8f C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { | |
6 | cleanupTests, | |
7 | flushAndRunServer, | |
37a44fc9 | 8 | immutableAssign, |
af971e06 | 9 | SearchCommand, |
3521ab8f C |
10 | ServerInfo, |
11 | setAccessTokensToServers, | |
37a44fc9 | 12 | uploadVideo |
af971e06 C |
13 | } from '@shared/extra-utils' |
14 | import { VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' | |
3521ab8f C |
15 | |
16 | const expect = chai.expect | |
17 | ||
18 | describe('Test videos search', function () { | |
3521ab8f C |
19 | const localVideoName = 'local video' + new Date().toISOString() |
20 | ||
af971e06 C |
21 | let server: ServerInfo = null |
22 | let command: SearchCommand | |
23 | ||
3521ab8f C |
24 | before(async function () { |
25 | this.timeout(30000) | |
26 | ||
27 | server = await flushAndRunServer(1) | |
28 | ||
29 | await setAccessTokensToServers([ server ]) | |
30 | ||
31 | await uploadVideo(server.url, server.accessToken, { name: localVideoName }) | |
af971e06 C |
32 | |
33 | command = server.searchCommand | |
3521ab8f C |
34 | }) |
35 | ||
36 | describe('Default search', async function () { | |
37 | ||
38 | it('Should make a local videos search by default', async function () { | |
39 | this.timeout(10000) | |
40 | ||
65e6e260 C |
41 | await server.configCommand.updateCustomSubConfig({ |
42 | newConfig: { | |
43 | search: { | |
44 | searchIndex: { | |
45 | enabled: true, | |
46 | isDefaultSearch: false, | |
47 | disableLocalSearch: false | |
48 | } | |
3521ab8f C |
49 | } |
50 | } | |
51 | }) | |
52 | ||
af971e06 | 53 | const body = await command.searchVideos({ search: 'local video' }) |
3521ab8f | 54 | |
af971e06 C |
55 | expect(body.total).to.equal(1) |
56 | expect(body.data[0].name).to.equal(localVideoName) | |
3521ab8f C |
57 | }) |
58 | ||
59 | it('Should make a local channels search by default', async function () { | |
af971e06 | 60 | const body = await command.searchChannels({ search: 'root' }) |
3521ab8f | 61 | |
af971e06 C |
62 | expect(body.total).to.equal(1) |
63 | expect(body.data[0].name).to.equal('root_channel') | |
64 | expect(body.data[0].host).to.equal('localhost:' + server.port) | |
3521ab8f C |
65 | }) |
66 | ||
67 | it('Should make an index videos search by default', async function () { | |
65e6e260 C |
68 | await server.configCommand.updateCustomSubConfig({ |
69 | newConfig: { | |
70 | search: { | |
71 | searchIndex: { | |
72 | enabled: true, | |
73 | isDefaultSearch: true, | |
74 | disableLocalSearch: false | |
75 | } | |
3521ab8f C |
76 | } |
77 | } | |
78 | }) | |
79 | ||
af971e06 C |
80 | const body = await command.searchVideos({ search: 'local video' }) |
81 | expect(body.total).to.be.greaterThan(2) | |
3521ab8f C |
82 | }) |
83 | ||
84 | it('Should make an index channels search by default', async function () { | |
af971e06 C |
85 | const body = await command.searchChannels({ search: 'root' }) |
86 | expect(body.total).to.be.greaterThan(2) | |
3521ab8f C |
87 | }) |
88 | ||
89 | it('Should make an index videos search if local search is disabled', async function () { | |
65e6e260 C |
90 | await server.configCommand.updateCustomSubConfig({ |
91 | newConfig: { | |
92 | search: { | |
93 | searchIndex: { | |
94 | enabled: true, | |
95 | isDefaultSearch: false, | |
96 | disableLocalSearch: true | |
97 | } | |
3521ab8f C |
98 | } |
99 | } | |
100 | }) | |
101 | ||
af971e06 C |
102 | const body = await command.searchVideos({ search: 'local video' }) |
103 | expect(body.total).to.be.greaterThan(2) | |
3521ab8f C |
104 | }) |
105 | ||
106 | it('Should make an index channels search if local search is disabled', async function () { | |
af971e06 C |
107 | const body = await command.searchChannels({ search: 'root' }) |
108 | expect(body.total).to.be.greaterThan(2) | |
3521ab8f C |
109 | }) |
110 | }) | |
111 | ||
112 | describe('Videos search', async function () { | |
113 | ||
114 | it('Should make a simple search and not have results', async function () { | |
af971e06 | 115 | const body = await command.searchVideos({ search: 'djidane'.repeat(50) }) |
3521ab8f | 116 | |
af971e06 C |
117 | expect(body.total).to.equal(0) |
118 | expect(body.data).to.have.lengthOf(0) | |
3521ab8f C |
119 | }) |
120 | ||
121 | it('Should make a simple search and have results', async function () { | |
af971e06 | 122 | const body = await command.searchVideos({ search: 'What is PeerTube' }) |
3521ab8f | 123 | |
af971e06 | 124 | expect(body.total).to.be.greaterThan(1) |
3521ab8f C |
125 | }) |
126 | ||
127 | it('Should make a complex search', async function () { | |
128 | ||
129 | async function check (search: VideosSearchQuery, exists = true) { | |
af971e06 | 130 | const body = await command.advancedVideoSearch({ search }) |
3521ab8f C |
131 | |
132 | if (exists === false) { | |
af971e06 C |
133 | expect(body.total).to.equal(0) |
134 | expect(body.data).to.have.lengthOf(0) | |
3521ab8f C |
135 | return |
136 | } | |
137 | ||
af971e06 C |
138 | expect(body.total).to.equal(1) |
139 | expect(body.data).to.have.lengthOf(1) | |
3521ab8f | 140 | |
af971e06 | 141 | const video = body.data[0] |
3521ab8f C |
142 | |
143 | expect(video.name).to.equal('What is PeerTube?') | |
144 | expect(video.category.label).to.equal('Science & Technology') | |
145 | expect(video.licence.label).to.equal('Attribution - Share Alike') | |
146 | expect(video.privacy.label).to.equal('Public') | |
147 | expect(video.duration).to.equal(113) | |
148 | expect(video.thumbnailUrl.startsWith('https://framatube.org/static/thumbnails')).to.be.true | |
149 | ||
150 | expect(video.account.host).to.equal('framatube.org') | |
151 | expect(video.account.name).to.equal('framasoft') | |
152 | expect(video.account.url).to.equal('https://framatube.org/accounts/framasoft') | |
153 | expect(video.account.avatar).to.exist | |
154 | ||
155 | expect(video.channel.host).to.equal('framatube.org') | |
156 | expect(video.channel.name).to.equal('bf54d359-cfad-4935-9d45-9d6be93f63e8') | |
157 | expect(video.channel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') | |
158 | expect(video.channel.avatar).to.exist | |
159 | } | |
160 | ||
161 | const baseSearch: VideosSearchQuery = { | |
162 | search: 'what is peertube', | |
163 | start: 0, | |
164 | count: 2, | |
165 | categoryOneOf: [ 15 ], | |
166 | licenceOneOf: [ 2 ], | |
167 | tagsAllOf: [ 'framasoft', 'peertube' ], | |
168 | startDate: '2018-10-01T10:50:46.396Z', | |
169 | endDate: '2018-10-01T10:55:46.396Z' | |
170 | } | |
171 | ||
172 | { | |
173 | await check(baseSearch) | |
174 | } | |
175 | ||
176 | { | |
177 | const search = immutableAssign(baseSearch, { startDate: '2018-10-01T10:54:46.396Z' }) | |
178 | await check(search, false) | |
179 | } | |
180 | ||
181 | { | |
182 | const search = immutableAssign(baseSearch, { tagsAllOf: [ 'toto', 'framasoft' ] }) | |
183 | await check(search, false) | |
184 | } | |
185 | ||
186 | { | |
187 | const search = immutableAssign(baseSearch, { durationMin: 2000 }) | |
188 | await check(search, false) | |
189 | } | |
190 | ||
191 | { | |
192 | const search = immutableAssign(baseSearch, { nsfw: 'true' }) | |
193 | await check(search, false) | |
194 | } | |
195 | ||
196 | { | |
197 | const search = immutableAssign(baseSearch, { nsfw: 'false' }) | |
198 | await check(search, true) | |
199 | } | |
200 | ||
201 | { | |
202 | const search = immutableAssign(baseSearch, { nsfw: 'both' }) | |
203 | await check(search, true) | |
204 | } | |
205 | }) | |
206 | ||
207 | it('Should have a correct pagination', async function () { | |
208 | const search = { | |
209 | search: 'video', | |
210 | start: 0, | |
211 | count: 5 | |
212 | } | |
213 | ||
af971e06 | 214 | const body = await command.advancedVideoSearch({ search }) |
3521ab8f | 215 | |
af971e06 C |
216 | expect(body.total).to.be.greaterThan(5) |
217 | expect(body.data).to.have.lengthOf(5) | |
3521ab8f | 218 | }) |
1a40132c C |
219 | |
220 | it('Should use the nsfw instance policy as default', async function () { | |
221 | let nsfwUUID: string | |
222 | ||
223 | { | |
65e6e260 C |
224 | await server.configCommand.updateCustomSubConfig({ |
225 | newConfig: { | |
226 | instance: { defaultNSFWPolicy: 'display' } | |
227 | } | |
228 | }) | |
1a40132c | 229 | |
af971e06 C |
230 | const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' }) |
231 | expect(body.data).to.have.length.greaterThan(0) | |
1a40132c | 232 | |
af971e06 | 233 | const video = body.data[0] |
1a40132c C |
234 | expect(video.nsfw).to.be.true |
235 | ||
236 | nsfwUUID = video.uuid | |
237 | } | |
238 | ||
239 | { | |
65e6e260 C |
240 | await server.configCommand.updateCustomSubConfig({ |
241 | newConfig: { | |
242 | instance: { defaultNSFWPolicy: 'do_not_list' } | |
243 | } | |
244 | }) | |
1a40132c | 245 | |
af971e06 | 246 | const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' }) |
1a40132c C |
247 | |
248 | try { | |
af971e06 C |
249 | expect(body.data).to.have.lengthOf(0) |
250 | } catch { | |
251 | const video = body.data[0] | |
1a40132c C |
252 | |
253 | expect(video.uuid).not.equal(nsfwUUID) | |
254 | } | |
255 | } | |
256 | }) | |
3521ab8f C |
257 | }) |
258 | ||
259 | describe('Channels search', async function () { | |
260 | ||
261 | it('Should make a simple search and not have results', async function () { | |
af971e06 | 262 | const body = await command.searchChannels({ search: 'a'.repeat(500) }) |
3521ab8f | 263 | |
af971e06 C |
264 | expect(body.total).to.equal(0) |
265 | expect(body.data).to.have.lengthOf(0) | |
3521ab8f C |
266 | }) |
267 | ||
268 | it('Should make a search and have results', async function () { | |
af971e06 | 269 | const body = await command.advancedChannelSearch({ search: { search: 'Framasoft', sort: 'createdAt' } }) |
3521ab8f | 270 | |
af971e06 C |
271 | expect(body.total).to.be.greaterThan(0) |
272 | expect(body.data).to.have.length.greaterThan(0) | |
3521ab8f | 273 | |
af971e06 | 274 | const videoChannel = body.data[0] |
3521ab8f C |
275 | expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') |
276 | expect(videoChannel.host).to.equal('framatube.org') | |
277 | expect(videoChannel.avatar).to.exist | |
278 | expect(videoChannel.displayName).to.exist | |
279 | ||
280 | expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft') | |
281 | expect(videoChannel.ownerAccount.name).to.equal('framasoft') | |
282 | expect(videoChannel.ownerAccount.host).to.equal('framatube.org') | |
283 | expect(videoChannel.ownerAccount.avatar).to.exist | |
284 | }) | |
285 | ||
286 | it('Should have a correct pagination', async function () { | |
af971e06 | 287 | const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } }) |
3521ab8f | 288 | |
af971e06 C |
289 | expect(body.total).to.be.greaterThan(2) |
290 | expect(body.data).to.have.lengthOf(2) | |
3521ab8f C |
291 | }) |
292 | }) | |
293 | ||
37a44fc9 C |
294 | describe('Playlists search', async function () { |
295 | ||
296 | it('Should make a simple search and not have results', async function () { | |
af971e06 | 297 | const body = await command.searchPlaylists({ search: 'a'.repeat(500) }) |
37a44fc9 | 298 | |
af971e06 C |
299 | expect(body.total).to.equal(0) |
300 | expect(body.data).to.have.lengthOf(0) | |
37a44fc9 C |
301 | }) |
302 | ||
303 | it('Should make a search and have results', async function () { | |
af971e06 | 304 | const body = await command.advancedPlaylistSearch({ search: { search: 'E2E playlist', sort: '-match' } }) |
37a44fc9 | 305 | |
af971e06 C |
306 | expect(body.total).to.be.greaterThan(0) |
307 | expect(body.data).to.have.length.greaterThan(0) | |
37a44fc9 | 308 | |
af971e06 | 309 | const videoPlaylist = body.data[0] |
37a44fc9 C |
310 | |
311 | expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | |
312 | expect(videoPlaylist.thumbnailUrl).to.exist | |
313 | expect(videoPlaylist.embedUrl).to.equal('https://peertube2.cpy.re/video-playlists/embed/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | |
314 | ||
315 | expect(videoPlaylist.type.id).to.equal(VideoPlaylistType.REGULAR) | |
316 | expect(videoPlaylist.privacy.id).to.equal(VideoPlaylistPrivacy.PUBLIC) | |
317 | expect(videoPlaylist.videosLength).to.exist | |
318 | ||
319 | expect(videoPlaylist.createdAt).to.exist | |
320 | expect(videoPlaylist.updatedAt).to.exist | |
321 | ||
322 | expect(videoPlaylist.uuid).to.equal('73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | |
323 | expect(videoPlaylist.displayName).to.exist | |
324 | ||
325 | expect(videoPlaylist.ownerAccount.url).to.equal('https://peertube2.cpy.re/accounts/chocobozzz') | |
326 | expect(videoPlaylist.ownerAccount.name).to.equal('chocobozzz') | |
327 | expect(videoPlaylist.ownerAccount.host).to.equal('peertube2.cpy.re') | |
328 | expect(videoPlaylist.ownerAccount.avatar).to.exist | |
329 | ||
330 | expect(videoPlaylist.videoChannel.url).to.equal('https://peertube2.cpy.re/video-channels/chocobozzz_channel') | |
331 | expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel') | |
332 | expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re') | |
333 | expect(videoPlaylist.videoChannel.avatar).to.exist | |
334 | }) | |
335 | ||
336 | it('Should have a correct pagination', async function () { | |
af971e06 | 337 | const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } }) |
37a44fc9 | 338 | |
af971e06 C |
339 | expect(body.total).to.be.greaterThan(2) |
340 | expect(body.data).to.have.lengthOf(2) | |
37a44fc9 C |
341 | }) |
342 | }) | |
343 | ||
3521ab8f C |
344 | after(async function () { |
345 | await cleanupTests([ server ]) | |
346 | }) | |
347 | }) |