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