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