diff options
Diffstat (limited to 'server/tests/api/search/search-index.ts')
-rw-r--r-- | server/tests/api/search/search-index.ts | 422 |
1 files changed, 273 insertions, 149 deletions
diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index 00f79232a..4c8b1f608 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts | |||
@@ -2,36 +2,34 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { advancedVideoChannelSearch, searchVideoChannel } from '@shared/extra-utils/search/video-channels' | 5 | import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils' |
6 | import { Video, VideoChannel, VideoPlaylist, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' | ||
7 | import { | 6 | import { |
8 | advancedVideoPlaylistSearch, | 7 | BooleanBothQuery, |
9 | advancedVideosSearch, | 8 | VideoChannelsSearchQuery, |
10 | cleanupTests, | 9 | VideoPlaylistPrivacy, |
11 | flushAndRunServer, | 10 | VideoPlaylistsSearchQuery, |
12 | immutableAssign, | 11 | VideoPlaylistType, |
13 | searchVideo, | 12 | VideosSearchQuery |
14 | searchVideoPlaylists, | 13 | } from '@shared/models' |
15 | ServerInfo, | ||
16 | setAccessTokensToServers, | ||
17 | updateCustomSubConfig, | ||
18 | uploadVideo | ||
19 | } from '../../../../shared/extra-utils' | ||
20 | 14 | ||
21 | const expect = chai.expect | 15 | const expect = chai.expect |
22 | 16 | ||
23 | describe('Test videos search', function () { | 17 | describe('Test videos search', function () { |
24 | let server: ServerInfo = null | ||
25 | const localVideoName = 'local video' + new Date().toISOString() | 18 | const localVideoName = 'local video' + new Date().toISOString() |
26 | 19 | ||
20 | let server: PeerTubeServer = null | ||
21 | let command: SearchCommand | ||
22 | |||
27 | before(async function () { | 23 | before(async function () { |
28 | this.timeout(30000) | 24 | this.timeout(30000) |
29 | 25 | ||
30 | server = await flushAndRunServer(1) | 26 | server = await createSingleServer(1) |
31 | 27 | ||
32 | await setAccessTokensToServers([ server ]) | 28 | await setAccessTokensToServers([ server ]) |
33 | 29 | ||
34 | await uploadVideo(server.url, server.accessToken, { name: localVideoName }) | 30 | await server.videos.upload({ attributes: { name: localVideoName } }) |
31 | |||
32 | command = server.search | ||
35 | }) | 33 | }) |
36 | 34 | ||
37 | describe('Default search', async function () { | 35 | describe('Default search', async function () { |
@@ -39,163 +37,213 @@ describe('Test videos search', function () { | |||
39 | it('Should make a local videos search by default', async function () { | 37 | it('Should make a local videos search by default', async function () { |
40 | this.timeout(10000) | 38 | this.timeout(10000) |
41 | 39 | ||
42 | await updateCustomSubConfig(server.url, server.accessToken, { | 40 | await server.config.updateCustomSubConfig({ |
43 | search: { | 41 | newConfig: { |
44 | searchIndex: { | 42 | search: { |
45 | enabled: true, | 43 | searchIndex: { |
46 | isDefaultSearch: false, | 44 | enabled: true, |
47 | disableLocalSearch: false | 45 | isDefaultSearch: false, |
46 | disableLocalSearch: false | ||
47 | } | ||
48 | } | 48 | } |
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 () { |
67 | await updateCustomSubConfig(server.url, server.accessToken, { | 67 | await server.config.updateCustomSubConfig({ |
68 | search: { | 68 | newConfig: { |
69 | searchIndex: { | 69 | search: { |
70 | enabled: true, | 70 | searchIndex: { |
71 | isDefaultSearch: true, | 71 | enabled: true, |
72 | disableLocalSearch: false | 72 | isDefaultSearch: true, |
73 | disableLocalSearch: false | ||
74 | } | ||
73 | } | 75 | } |
74 | } | 76 | } |
75 | }) | 77 | }) |
76 | 78 | ||
77 | const res = await searchVideo(server.url, 'local video') | 79 | const body = await command.searchVideos({ search: 'local video' }) |
78 | expect(res.body.total).to.be.greaterThan(2) | 80 | expect(body.total).to.be.greaterThan(2) |
79 | }) | 81 | }) |
80 | 82 | ||
81 | it('Should make an index channels search by default', async function () { | 83 | it('Should make an index channels search by default', async function () { |
82 | const res = await searchVideoChannel(server.url, 'root') | 84 | const body = await command.searchChannels({ search: 'root' }) |
83 | expect(res.body.total).to.be.greaterThan(2) | 85 | expect(body.total).to.be.greaterThan(2) |
84 | }) | 86 | }) |
85 | 87 | ||
86 | it('Should make an index videos search if local search is disabled', async function () { | 88 | it('Should make an index videos search if local search is disabled', async function () { |
87 | await updateCustomSubConfig(server.url, server.accessToken, { | 89 | await server.config.updateCustomSubConfig({ |
88 | search: { | 90 | newConfig: { |
89 | searchIndex: { | 91 | search: { |
90 | enabled: true, | 92 | searchIndex: { |
91 | isDefaultSearch: false, | 93 | enabled: true, |
92 | disableLocalSearch: true | 94 | isDefaultSearch: false, |
95 | disableLocalSearch: true | ||
96 | } | ||
93 | } | 97 | } |
94 | } | 98 | } |
95 | }) | 99 | }) |
96 | 100 | ||
97 | const res = await searchVideo(server.url, 'local video') | 101 | const body = await command.searchVideos({ search: 'local video' }) |
98 | expect(res.body.total).to.be.greaterThan(2) | 102 | expect(body.total).to.be.greaterThan(2) |
99 | }) | 103 | }) |
100 | 104 | ||
101 | it('Should make an index channels search if local search is disabled', async function () { | 105 | it('Should make an index channels search if local search is disabled', async function () { |
102 | const res = await searchVideoChannel(server.url, 'root') | 106 | const body = await command.searchChannels({ search: 'root' }) |
103 | expect(res.body.total).to.be.greaterThan(2) | 107 | expect(body.total).to.be.greaterThan(2) |
104 | }) | 108 | }) |
105 | }) | 109 | }) |
106 | 110 | ||
107 | describe('Videos search', async function () { | 111 | describe('Videos search', async function () { |
108 | 112 | ||
113 | async function check (search: VideosSearchQuery, exists = true) { | ||
114 | const body = await command.advancedVideoSearch({ search }) | ||
115 | |||
116 | if (exists === false) { | ||
117 | expect(body.total).to.equal(0) | ||
118 | expect(body.data).to.have.lengthOf(0) | ||
119 | return | ||
120 | } | ||
121 | |||
122 | expect(body.total).to.equal(1) | ||
123 | expect(body.data).to.have.lengthOf(1) | ||
124 | |||
125 | const video = body.data[0] | ||
126 | |||
127 | expect(video.name).to.equal('What is PeerTube?') | ||
128 | expect(video.category.label).to.equal('Science & Technology') | ||
129 | expect(video.licence.label).to.equal('Attribution - Share Alike') | ||
130 | expect(video.privacy.label).to.equal('Public') | ||
131 | expect(video.duration).to.equal(113) | ||
132 | expect(video.thumbnailUrl.startsWith('https://framatube.org/static/thumbnails')).to.be.true | ||
133 | |||
134 | expect(video.account.host).to.equal('framatube.org') | ||
135 | expect(video.account.name).to.equal('framasoft') | ||
136 | expect(video.account.url).to.equal('https://framatube.org/accounts/framasoft') | ||
137 | expect(video.account.avatar).to.exist | ||
138 | |||
139 | expect(video.channel.host).to.equal('framatube.org') | ||
140 | expect(video.channel.name).to.equal('bf54d359-cfad-4935-9d45-9d6be93f63e8') | ||
141 | expect(video.channel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') | ||
142 | expect(video.channel.avatar).to.exist | ||
143 | } | ||
144 | |||
145 | const baseSearch: VideosSearchQuery = { | ||
146 | search: 'what is peertube', | ||
147 | start: 0, | ||
148 | count: 2, | ||
149 | categoryOneOf: [ 15 ], | ||
150 | licenceOneOf: [ 2 ], | ||
151 | tagsAllOf: [ 'framasoft', 'peertube' ], | ||
152 | startDate: '2018-10-01T10:50:46.396Z', | ||
153 | endDate: '2018-10-01T10:55:46.396Z' | ||
154 | } | ||
155 | |||
109 | it('Should make a simple search and not have results', async function () { | 156 | it('Should make a simple search and not have results', async function () { |
110 | const res = await searchVideo(server.url, 'djidane'.repeat(50)) | 157 | const body = await command.searchVideos({ search: 'djidane'.repeat(50) }) |
111 | 158 | ||
112 | expect(res.body.total).to.equal(0) | 159 | expect(body.total).to.equal(0) |
113 | expect(res.body.data).to.have.lengthOf(0) | 160 | expect(body.data).to.have.lengthOf(0) |
114 | }) | 161 | }) |
115 | 162 | ||
116 | it('Should make a simple search and have results', async function () { | 163 | it('Should make a simple search and have results', async function () { |
117 | const res = await searchVideo(server.url, 'What is PeerTube') | 164 | const body = await command.searchVideos({ search: 'What is PeerTube' }) |
118 | 165 | ||
119 | expect(res.body.total).to.be.greaterThan(1) | 166 | expect(body.total).to.be.greaterThan(1) |
120 | }) | 167 | }) |
121 | 168 | ||
122 | it('Should make a complex search', async function () { | 169 | it('Should make a simple search', async function () { |
123 | 170 | await check(baseSearch) | |
124 | async function check (search: VideosSearchQuery, exists = true) { | 171 | }) |
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 | 172 | ||
145 | expect(video.account.host).to.equal('framatube.org') | 173 | it('Should search by start date', async function () { |
146 | expect(video.account.name).to.equal('framasoft') | 174 | const search = { ...baseSearch, startDate: '2018-10-01T10:54:46.396Z' } |
147 | expect(video.account.url).to.equal('https://framatube.org/accounts/framasoft') | 175 | await check(search, false) |
148 | expect(video.account.avatar).to.exist | 176 | }) |
149 | 177 | ||
150 | expect(video.channel.host).to.equal('framatube.org') | 178 | it('Should search by tags', async function () { |
151 | expect(video.channel.name).to.equal('bf54d359-cfad-4935-9d45-9d6be93f63e8') | 179 | const search = { ...baseSearch, tagsAllOf: [ 'toto', 'framasoft' ] } |
152 | expect(video.channel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') | 180 | await check(search, false) |
153 | expect(video.channel.avatar).to.exist | 181 | }) |
154 | } | ||
155 | 182 | ||
156 | const baseSearch: VideosSearchQuery = { | 183 | it('Should search by duration', async function () { |
157 | search: 'what is peertube', | 184 | const search = { ...baseSearch, durationMin: 2000 } |
158 | start: 0, | 185 | await check(search, false) |
159 | count: 2, | 186 | }) |
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 | 187 | ||
188 | it('Should search by nsfw attribute', async function () { | ||
167 | { | 189 | { |
168 | await check(baseSearch) | 190 | const search = { ...baseSearch, nsfw: 'true' as BooleanBothQuery } |
191 | await check(search, false) | ||
169 | } | 192 | } |
170 | 193 | ||
171 | { | 194 | { |
172 | const search = immutableAssign(baseSearch, { startDate: '2018-10-01T10:54:46.396Z' }) | 195 | const search = { ...baseSearch, nsfw: 'false' as BooleanBothQuery } |
173 | await check(search, false) | 196 | await check(search, true) |
174 | } | 197 | } |
175 | 198 | ||
176 | { | 199 | { |
177 | const search = immutableAssign(baseSearch, { tagsAllOf: [ 'toto', 'framasoft' ] }) | 200 | const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery } |
178 | await check(search, false) | 201 | await check(search, true) |
179 | } | 202 | } |
203 | }) | ||
180 | 204 | ||
205 | it('Should search by host', async function () { | ||
181 | { | 206 | { |
182 | const search = immutableAssign(baseSearch, { durationMin: 2000 }) | 207 | const search = { ...baseSearch, host: 'example.com' } |
183 | await check(search, false) | 208 | await check(search, false) |
184 | } | 209 | } |
185 | 210 | ||
186 | { | 211 | { |
187 | const search = immutableAssign(baseSearch, { nsfw: 'true' }) | 212 | const search = { ...baseSearch, host: 'framatube.org' } |
188 | await check(search, false) | 213 | await check(search, true) |
189 | } | 214 | } |
215 | }) | ||
216 | |||
217 | it('Should search by uuids', async function () { | ||
218 | const goodUUID = '9c9de5e8-0a1e-484a-b099-e80766180a6d' | ||
219 | const goodShortUUID = 'kkGMgK9ZtnKfYAgnEtQxbv' | ||
220 | const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0' | ||
221 | const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej' | ||
190 | 222 | ||
191 | { | 223 | { |
192 | const search = immutableAssign(baseSearch, { nsfw: 'false' }) | 224 | const uuidsMatrix = [ |
193 | await check(search, true) | 225 | [ goodUUID ], |
226 | [ goodUUID, badShortUUID ], | ||
227 | [ badShortUUID, goodShortUUID ], | ||
228 | [ goodUUID, goodShortUUID ] | ||
229 | ] | ||
230 | |||
231 | for (const uuids of uuidsMatrix) { | ||
232 | const search = { ...baseSearch, uuids } | ||
233 | await check(search, true) | ||
234 | } | ||
194 | } | 235 | } |
195 | 236 | ||
196 | { | 237 | { |
197 | const search = immutableAssign(baseSearch, { nsfw: 'both' }) | 238 | const uuidsMatrix = [ |
198 | await check(search, true) | 239 | [ badUUID ], |
240 | [ badShortUUID ] | ||
241 | ] | ||
242 | |||
243 | for (const uuids of uuidsMatrix) { | ||
244 | const search = { ...baseSearch, uuids } | ||
245 | await check(search, false) | ||
246 | } | ||
199 | } | 247 | } |
200 | }) | 248 | }) |
201 | 249 | ||
@@ -206,37 +254,44 @@ describe('Test videos search', function () { | |||
206 | count: 5 | 254 | count: 5 |
207 | } | 255 | } |
208 | 256 | ||
209 | const res = await advancedVideosSearch(server.url, search) | 257 | const body = await command.advancedVideoSearch({ search }) |
210 | 258 | ||
211 | expect(res.body.total).to.be.greaterThan(5) | 259 | expect(body.total).to.be.greaterThan(5) |
212 | expect(res.body.data).to.have.lengthOf(5) | 260 | expect(body.data).to.have.lengthOf(5) |
213 | }) | 261 | }) |
214 | 262 | ||
215 | it('Should use the nsfw instance policy as default', async function () { | 263 | it('Should use the nsfw instance policy as default', async function () { |
216 | let nsfwUUID: string | 264 | let nsfwUUID: string |
217 | 265 | ||
218 | { | 266 | { |
219 | await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'display' } }) | 267 | await server.config.updateCustomSubConfig({ |
268 | newConfig: { | ||
269 | instance: { defaultNSFWPolicy: 'display' } | ||
270 | } | ||
271 | }) | ||
220 | 272 | ||
221 | const res = await searchVideo(server.url, 'NSFW search index', '-match') | 273 | const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' }) |
222 | const video = res.body.data[0] as Video | 274 | expect(body.data).to.have.length.greaterThan(0) |
223 | 275 | ||
224 | expect(res.body.data).to.have.length.greaterThan(0) | 276 | const video = body.data[0] |
225 | expect(video.nsfw).to.be.true | 277 | expect(video.nsfw).to.be.true |
226 | 278 | ||
227 | nsfwUUID = video.uuid | 279 | nsfwUUID = video.uuid |
228 | } | 280 | } |
229 | 281 | ||
230 | { | 282 | { |
231 | await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'do_not_list' } }) | 283 | await server.config.updateCustomSubConfig({ |
284 | newConfig: { | ||
285 | instance: { defaultNSFWPolicy: 'do_not_list' } | ||
286 | } | ||
287 | }) | ||
232 | 288 | ||
233 | const res = await searchVideo(server.url, 'NSFW search index', '-match') | 289 | const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' }) |
234 | 290 | ||
235 | try { | 291 | try { |
236 | expect(res.body.data).to.have.lengthOf(0) | 292 | expect(body.data).to.have.lengthOf(0) |
237 | } catch (err) { | 293 | } catch { |
238 | // | 294 | const video = body.data[0] |
239 | const video = res.body.data[0] as Video | ||
240 | 295 | ||
241 | expect(video.uuid).not.equal(nsfwUUID) | 296 | expect(video.uuid).not.equal(nsfwUUID) |
242 | } | 297 | } |
@@ -246,20 +301,19 @@ describe('Test videos search', function () { | |||
246 | 301 | ||
247 | describe('Channels search', async function () { | 302 | describe('Channels search', async function () { |
248 | 303 | ||
249 | it('Should make a simple search and not have results', async function () { | 304 | async function check (search: VideoChannelsSearchQuery, exists = true) { |
250 | const res = await searchVideoChannel(server.url, 'a'.repeat(500)) | 305 | const body = await command.advancedChannelSearch({ search }) |
251 | 306 | ||
252 | expect(res.body.total).to.equal(0) | 307 | if (exists === false) { |
253 | expect(res.body.data).to.have.lengthOf(0) | 308 | expect(body.total).to.equal(0) |
254 | }) | 309 | expect(body.data).to.have.lengthOf(0) |
255 | 310 | return | |
256 | it('Should make a search and have results', async function () { | 311 | } |
257 | const res = await advancedVideoChannelSearch(server.url, { search: 'Framasoft', sort: 'createdAt' }) | ||
258 | 312 | ||
259 | expect(res.body.total).to.be.greaterThan(0) | 313 | expect(body.total).to.be.greaterThan(0) |
260 | expect(res.body.data).to.have.length.greaterThan(0) | 314 | expect(body.data).to.have.length.greaterThan(0) |
261 | 315 | ||
262 | const videoChannel: VideoChannel = res.body.data[0] | 316 | const videoChannel = body.data[0] |
263 | expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') | 317 | expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') |
264 | expect(videoChannel.host).to.equal('framatube.org') | 318 | expect(videoChannel.host).to.equal('framatube.org') |
265 | expect(videoChannel.avatar).to.exist | 319 | expect(videoChannel.avatar).to.exist |
@@ -269,32 +323,53 @@ describe('Test videos search', function () { | |||
269 | expect(videoChannel.ownerAccount.name).to.equal('framasoft') | 323 | expect(videoChannel.ownerAccount.name).to.equal('framasoft') |
270 | expect(videoChannel.ownerAccount.host).to.equal('framatube.org') | 324 | expect(videoChannel.ownerAccount.host).to.equal('framatube.org') |
271 | expect(videoChannel.ownerAccount.avatar).to.exist | 325 | expect(videoChannel.ownerAccount.avatar).to.exist |
326 | } | ||
327 | |||
328 | it('Should make a simple search and not have results', async function () { | ||
329 | const body = await command.searchChannels({ search: 'a'.repeat(500) }) | ||
330 | |||
331 | expect(body.total).to.equal(0) | ||
332 | expect(body.data).to.have.lengthOf(0) | ||
333 | }) | ||
334 | |||
335 | it('Should make a search and have results', async function () { | ||
336 | await check({ search: 'Framasoft', sort: 'createdAt' }, true) | ||
337 | }) | ||
338 | |||
339 | it('Should make host search and have appropriate results', async function () { | ||
340 | await check({ search: 'Framasoft', host: 'example.com' }, false) | ||
341 | await check({ search: 'Framasoft', host: 'framatube.org' }, true) | ||
342 | }) | ||
343 | |||
344 | it('Should make handles search and have appropriate results', async function () { | ||
345 | await check({ handles: [ 'bf54d359-cfad-4935-9d45-9d6be93f63e8@framatube.org' ] }, true) | ||
346 | await check({ handles: [ 'jeanine', 'bf54d359-cfad-4935-9d45-9d6be93f63e8@framatube.org' ] }, true) | ||
347 | await check({ handles: [ 'jeanine', 'chocobozzz_channel2@peertube2.cpy.re' ] }, false) | ||
272 | }) | 348 | }) |
273 | 349 | ||
274 | it('Should have a correct pagination', async function () { | 350 | it('Should have a correct pagination', async function () { |
275 | const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 }) | 351 | const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } }) |
276 | 352 | ||
277 | expect(res.body.total).to.be.greaterThan(2) | 353 | expect(body.total).to.be.greaterThan(2) |
278 | expect(res.body.data).to.have.lengthOf(2) | 354 | expect(body.data).to.have.lengthOf(2) |
279 | }) | 355 | }) |
280 | }) | 356 | }) |
281 | 357 | ||
282 | describe('Playlists search', async function () { | 358 | describe('Playlists search', async function () { |
283 | 359 | ||
284 | it('Should make a simple search and not have results', async function () { | 360 | async function check (search: VideoPlaylistsSearchQuery, exists = true) { |
285 | const res = await searchVideoPlaylists(server.url, 'a'.repeat(500)) | 361 | const body = await command.advancedPlaylistSearch({ search }) |
286 | 362 | ||
287 | expect(res.body.total).to.equal(0) | 363 | if (exists === false) { |
288 | expect(res.body.data).to.have.lengthOf(0) | 364 | expect(body.total).to.equal(0) |
289 | }) | 365 | expect(body.data).to.have.lengthOf(0) |
290 | 366 | return | |
291 | it('Should make a search and have results', async function () { | 367 | } |
292 | const res = await advancedVideoPlaylistSearch(server.url, { search: 'E2E playlist', sort: '-match' }) | ||
293 | 368 | ||
294 | expect(res.body.total).to.be.greaterThan(0) | 369 | expect(body.total).to.be.greaterThan(0) |
295 | expect(res.body.data).to.have.length.greaterThan(0) | 370 | expect(body.data).to.have.length.greaterThan(0) |
296 | 371 | ||
297 | const videoPlaylist: VideoPlaylist = res.body.data[0] | 372 | const videoPlaylist = body.data[0] |
298 | 373 | ||
299 | expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') | 374 | expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') |
300 | expect(videoPlaylist.thumbnailUrl).to.exist | 375 | expect(videoPlaylist.thumbnailUrl).to.exist |
@@ -319,13 +394,62 @@ describe('Test videos search', function () { | |||
319 | expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel') | 394 | expect(videoPlaylist.videoChannel.name).to.equal('chocobozzz_channel') |
320 | expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re') | 395 | expect(videoPlaylist.videoChannel.host).to.equal('peertube2.cpy.re') |
321 | expect(videoPlaylist.videoChannel.avatar).to.exist | 396 | expect(videoPlaylist.videoChannel.avatar).to.exist |
397 | } | ||
398 | |||
399 | it('Should make a simple search and not have results', async function () { | ||
400 | const body = await command.searchPlaylists({ search: 'a'.repeat(500) }) | ||
401 | |||
402 | expect(body.total).to.equal(0) | ||
403 | expect(body.data).to.have.lengthOf(0) | ||
404 | }) | ||
405 | |||
406 | it('Should make a search and have results', async function () { | ||
407 | await check({ search: 'E2E playlist', sort: '-match' }, true) | ||
408 | }) | ||
409 | |||
410 | it('Should make host search and have appropriate results', async function () { | ||
411 | await check({ search: 'E2E playlist', host: 'example.com' }, false) | ||
412 | await check({ search: 'E2E playlist', host: 'peertube2.cpy.re', sort: '-match' }, true) | ||
413 | }) | ||
414 | |||
415 | it('Should make a search by uuids and have appropriate results', async function () { | ||
416 | const goodUUID = '73804a40-da9a-40c2-b1eb-2c6d9eec8f0a' | ||
417 | const goodShortUUID = 'fgei1ws1oa6FCaJ2qZPG29' | ||
418 | const badUUID = 'c29c5b77-4a04-493d-96a9-2e9267e308f0' | ||
419 | const badShortUUID = 'rP5RgUeX9XwTSrspCdkDej' | ||
420 | |||
421 | { | ||
422 | const uuidsMatrix = [ | ||
423 | [ goodUUID ], | ||
424 | [ goodUUID, badShortUUID ], | ||
425 | [ badShortUUID, goodShortUUID ], | ||
426 | [ goodUUID, goodShortUUID ] | ||
427 | ] | ||
428 | |||
429 | for (const uuids of uuidsMatrix) { | ||
430 | const search = { search: 'E2E playlist', sort: '-match', uuids } | ||
431 | await check(search, true) | ||
432 | } | ||
433 | } | ||
434 | |||
435 | { | ||
436 | const uuidsMatrix = [ | ||
437 | [ badUUID ], | ||
438 | [ badShortUUID ] | ||
439 | ] | ||
440 | |||
441 | for (const uuids of uuidsMatrix) { | ||
442 | const search = { search: 'E2E playlist', sort: '-match', uuids } | ||
443 | await check(search, false) | ||
444 | } | ||
445 | } | ||
322 | }) | 446 | }) |
323 | 447 | ||
324 | it('Should have a correct pagination', async function () { | 448 | it('Should have a correct pagination', async function () { |
325 | const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 }) | 449 | const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } }) |
326 | 450 | ||
327 | expect(res.body.total).to.be.greaterThan(2) | 451 | expect(body.total).to.be.greaterThan(2) |
328 | expect(res.body.data).to.have.lengthOf(2) | 452 | expect(body.data).to.have.lengthOf(2) |
329 | }) | 453 | }) |
330 | }) | 454 | }) |
331 | 455 | ||