diff options
Diffstat (limited to 'server/tests/api/search/search-videos.ts')
-rw-r--r-- | server/tests/api/search/search-videos.ts | 393 |
1 files changed, 230 insertions, 163 deletions
diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 5b8907961..bd1e4d266 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts | |||
@@ -2,40 +2,42 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { VideoPrivacy } from '@shared/models' | ||
6 | import { | 5 | import { |
7 | advancedVideosSearch, | ||
8 | cleanupTests, | 6 | cleanupTests, |
9 | createLive, | 7 | createSingleServer, |
10 | flushAndRunServer, | 8 | doubleFollow, |
11 | immutableAssign, | 9 | PeerTubeServer, |
12 | searchVideo, | 10 | SearchCommand, |
13 | sendRTMPStreamInVideo, | ||
14 | ServerInfo, | ||
15 | setAccessTokensToServers, | 11 | setAccessTokensToServers, |
16 | setDefaultVideoChannel, | 12 | setDefaultVideoChannel, |
17 | stopFfmpeg, | 13 | stopFfmpeg, |
18 | updateCustomSubConfig, | 14 | wait |
19 | uploadVideo, | 15 | } from '@shared/extra-utils' |
20 | wait, | 16 | import { VideoPrivacy } from '@shared/models' |
21 | waitUntilLivePublished | ||
22 | } from '../../../../shared/extra-utils' | ||
23 | import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions' | ||
24 | 17 | ||
25 | const expect = chai.expect | 18 | const expect = chai.expect |
26 | 19 | ||
27 | describe('Test videos search', function () { | 20 | describe('Test videos search', function () { |
28 | let server: ServerInfo = null | 21 | let server: PeerTubeServer |
22 | let remoteServer: PeerTubeServer | ||
29 | let startDate: string | 23 | let startDate: string |
30 | let videoUUID: string | 24 | let videoUUID: string |
25 | let videoShortUUID: string | ||
26 | |||
27 | let command: SearchCommand | ||
31 | 28 | ||
32 | before(async function () { | 29 | before(async function () { |
33 | this.timeout(60000) | 30 | this.timeout(120000) |
34 | 31 | ||
35 | server = await flushAndRunServer(1) | 32 | const servers = await Promise.all([ |
33 | createSingleServer(1), | ||
34 | createSingleServer(2) | ||
35 | ]) | ||
36 | server = servers[0] | ||
37 | remoteServer = servers[1] | ||
36 | 38 | ||
37 | await setAccessTokensToServers([ server ]) | 39 | await setAccessTokensToServers([ server, remoteServer ]) |
38 | await setDefaultVideoChannel([ server ]) | 40 | await setDefaultVideoChannel([ server, remoteServer ]) |
39 | 41 | ||
40 | { | 42 | { |
41 | const attributes1 = { | 43 | const attributes1 = { |
@@ -46,57 +48,50 @@ describe('Test videos search', function () { | |||
46 | nsfw: false, | 48 | nsfw: false, |
47 | language: 'fr' | 49 | language: 'fr' |
48 | } | 50 | } |
49 | await uploadVideo(server.url, server.accessToken, attributes1) | 51 | await server.videos.upload({ attributes: attributes1 }) |
50 | 52 | ||
51 | const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }) | 53 | const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' } |
52 | await uploadVideo(server.url, server.accessToken, attributes2) | 54 | await server.videos.upload({ attributes: attributes2 }) |
53 | 55 | ||
54 | { | 56 | { |
55 | const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: undefined }) | 57 | const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined } |
56 | const res = await uploadVideo(server.url, server.accessToken, attributes3) | 58 | const { id, uuid, shortUUID } = await server.videos.upload({ attributes: attributes3 }) |
57 | const videoId = res.body.video.id | 59 | videoUUID = uuid |
58 | videoUUID = res.body.video.uuid | 60 | videoShortUUID = shortUUID |
59 | 61 | ||
60 | await createVideoCaption({ | 62 | await server.captions.add({ |
61 | url: server.url, | ||
62 | accessToken: server.accessToken, | ||
63 | language: 'en', | 63 | language: 'en', |
64 | videoId, | 64 | videoId: id, |
65 | fixture: 'subtitle-good2.vtt', | 65 | fixture: 'subtitle-good2.vtt', |
66 | mimeType: 'application/octet-stream' | 66 | mimeType: 'application/octet-stream' |
67 | }) | 67 | }) |
68 | 68 | ||
69 | await createVideoCaption({ | 69 | await server.captions.add({ |
70 | url: server.url, | ||
71 | accessToken: server.accessToken, | ||
72 | language: 'aa', | 70 | language: 'aa', |
73 | videoId, | 71 | videoId: id, |
74 | fixture: 'subtitle-good2.vtt', | 72 | fixture: 'subtitle-good2.vtt', |
75 | mimeType: 'application/octet-stream' | 73 | mimeType: 'application/octet-stream' |
76 | }) | 74 | }) |
77 | } | 75 | } |
78 | 76 | ||
79 | const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true }) | 77 | const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true } |
80 | await uploadVideo(server.url, server.accessToken, attributes4) | 78 | await server.videos.upload({ attributes: attributes4 }) |
81 | 79 | ||
82 | await wait(1000) | 80 | await wait(1000) |
83 | 81 | ||
84 | startDate = new Date().toISOString() | 82 | startDate = new Date().toISOString() |
85 | 83 | ||
86 | const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2, language: undefined }) | 84 | const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined } |
87 | await uploadVideo(server.url, server.accessToken, attributes5) | 85 | await server.videos.upload({ attributes: attributes5 }) |
88 | 86 | ||
89 | const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }) | 87 | const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] } |
90 | await uploadVideo(server.url, server.accessToken, attributes6) | 88 | await server.videos.upload({ attributes: attributes6 }) |
91 | 89 | ||
92 | const attributes7 = immutableAssign(attributes1, { | 90 | const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' } |
93 | name: attributes1.name + ' - 7', | 91 | await server.videos.upload({ attributes: attributes7 }) |
94 | originallyPublishedAt: '2019-02-12T09:58:08.286Z' | ||
95 | }) | ||
96 | await uploadVideo(server.url, server.accessToken, attributes7) | ||
97 | 92 | ||
98 | const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 }) | 93 | const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 } |
99 | await uploadVideo(server.url, server.accessToken, attributes8) | 94 | await server.videos.upload({ attributes: attributes8 }) |
100 | } | 95 | } |
101 | 96 | ||
102 | { | 97 | { |
@@ -107,9 +102,9 @@ describe('Test videos search', function () { | |||
107 | licence: 2, | 102 | licence: 2, |
108 | language: 'en' | 103 | language: 'en' |
109 | } | 104 | } |
110 | await uploadVideo(server.url, server.accessToken, attributes) | 105 | await server.videos.upload({ attributes: attributes }) |
111 | 106 | ||
112 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' })) | 107 | await server.videos.upload({ attributes: { ...attributes, name: attributes.name + ' duplicate' } }) |
113 | } | 108 | } |
114 | 109 | ||
115 | { | 110 | { |
@@ -120,7 +115,7 @@ describe('Test videos search', function () { | |||
120 | licence: 3, | 115 | licence: 3, |
121 | language: 'pl' | 116 | language: 'pl' |
122 | } | 117 | } |
123 | await uploadVideo(server.url, server.accessToken, attributes) | 118 | await server.videos.upload({ attributes: attributes }) |
124 | } | 119 | } |
125 | 120 | ||
126 | { | 121 | { |
@@ -129,11 +124,11 @@ describe('Test videos search', function () { | |||
129 | tags: [ 'aaaa', 'bbbb', 'cccc' ], | 124 | tags: [ 'aaaa', 'bbbb', 'cccc' ], |
130 | category: 1 | 125 | category: 1 |
131 | } | 126 | } |
132 | await uploadVideo(server.url, server.accessToken, attributes1) | 127 | await server.videos.upload({ attributes: attributes1 }) |
133 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) | 128 | await server.videos.upload({ attributes: { ...attributes1, category: 2 } }) |
134 | 129 | ||
135 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] })) | 130 | await server.videos.upload({ attributes: { ...attributes1, tags: [ 'cccc', 'dddd' ] } }) |
136 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] })) | 131 | await server.videos.upload({ attributes: { ...attributes1, tags: [ 'eeee', 'ffff' ] } }) |
137 | } | 132 | } |
138 | 133 | ||
139 | { | 134 | { |
@@ -141,24 +136,33 @@ describe('Test videos search', function () { | |||
141 | name: 'aaaa 2', | 136 | name: 'aaaa 2', |
142 | category: 1 | 137 | category: 1 |
143 | } | 138 | } |
144 | await uploadVideo(server.url, server.accessToken, attributes1) | 139 | await server.videos.upload({ attributes: attributes1 }) |
145 | await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) | 140 | await server.videos.upload({ attributes: { ...attributes1, category: 2 } }) |
141 | } | ||
142 | |||
143 | { | ||
144 | await remoteServer.videos.upload({ attributes: { name: 'remote video 1' } }) | ||
145 | await remoteServer.videos.upload({ attributes: { name: 'remote video 2' } }) | ||
146 | } | 146 | } |
147 | |||
148 | await doubleFollow(server, remoteServer) | ||
149 | |||
150 | command = server.search | ||
147 | }) | 151 | }) |
148 | 152 | ||
149 | it('Should make a simple search and not have results', async function () { | 153 | it('Should make a simple search and not have results', async function () { |
150 | const res = await searchVideo(server.url, 'abc') | 154 | const body = await command.searchVideos({ search: 'abc' }) |
151 | 155 | ||
152 | expect(res.body.total).to.equal(0) | 156 | expect(body.total).to.equal(0) |
153 | expect(res.body.data).to.have.lengthOf(0) | 157 | expect(body.data).to.have.lengthOf(0) |
154 | }) | 158 | }) |
155 | 159 | ||
156 | it('Should make a simple search and have results', async function () { | 160 | it('Should make a simple search and have results', async function () { |
157 | const res = await searchVideo(server.url, '4444 5555 duplicate') | 161 | const body = await command.searchVideos({ search: '4444 5555 duplicate' }) |
158 | 162 | ||
159 | expect(res.body.total).to.equal(2) | 163 | expect(body.total).to.equal(2) |
160 | 164 | ||
161 | const videos = res.body.data | 165 | const videos = body.data |
162 | expect(videos).to.have.lengthOf(2) | 166 | expect(videos).to.have.lengthOf(2) |
163 | 167 | ||
164 | // bestmatch | 168 | // bestmatch |
@@ -167,15 +171,15 @@ describe('Test videos search', function () { | |||
167 | }) | 171 | }) |
168 | 172 | ||
169 | it('Should make a search on tags too, and have results', async function () { | 173 | it('Should make a search on tags too, and have results', async function () { |
170 | const query = { | 174 | const search = { |
171 | search: 'aaaa', | 175 | search: 'aaaa', |
172 | categoryOneOf: [ 1 ] | 176 | categoryOneOf: [ 1 ] |
173 | } | 177 | } |
174 | const res = await advancedVideosSearch(server.url, query) | 178 | const body = await command.advancedVideoSearch({ search }) |
175 | 179 | ||
176 | expect(res.body.total).to.equal(2) | 180 | expect(body.total).to.equal(2) |
177 | 181 | ||
178 | const videos = res.body.data | 182 | const videos = body.data |
179 | expect(videos).to.have.lengthOf(2) | 183 | expect(videos).to.have.lengthOf(2) |
180 | 184 | ||
181 | // bestmatch | 185 | // bestmatch |
@@ -184,14 +188,14 @@ describe('Test videos search', function () { | |||
184 | }) | 188 | }) |
185 | 189 | ||
186 | it('Should filter on tags without a search', async function () { | 190 | it('Should filter on tags without a search', async function () { |
187 | const query = { | 191 | const search = { |
188 | tagsAllOf: [ 'bbbb' ] | 192 | tagsAllOf: [ 'bbbb' ] |
189 | } | 193 | } |
190 | const res = await advancedVideosSearch(server.url, query) | 194 | const body = await command.advancedVideoSearch({ search }) |
191 | 195 | ||
192 | expect(res.body.total).to.equal(2) | 196 | expect(body.total).to.equal(2) |
193 | 197 | ||
194 | const videos = res.body.data | 198 | const videos = body.data |
195 | expect(videos).to.have.lengthOf(2) | 199 | expect(videos).to.have.lengthOf(2) |
196 | 200 | ||
197 | expect(videos[0].name).to.equal('9999') | 201 | expect(videos[0].name).to.equal('9999') |
@@ -199,14 +203,14 @@ describe('Test videos search', function () { | |||
199 | }) | 203 | }) |
200 | 204 | ||
201 | it('Should filter on category without a search', async function () { | 205 | it('Should filter on category without a search', async function () { |
202 | const query = { | 206 | const search = { |
203 | categoryOneOf: [ 3 ] | 207 | categoryOneOf: [ 3 ] |
204 | } | 208 | } |
205 | const res = await advancedVideosSearch(server.url, query) | 209 | const body = await command.advancedVideoSearch({ search: search }) |
206 | 210 | ||
207 | expect(res.body.total).to.equal(1) | 211 | expect(body.total).to.equal(1) |
208 | 212 | ||
209 | const videos = res.body.data | 213 | const videos = body.data |
210 | expect(videos).to.have.lengthOf(1) | 214 | expect(videos).to.have.lengthOf(1) |
211 | 215 | ||
212 | expect(videos[0].name).to.equal('6666 7777 8888') | 216 | expect(videos[0].name).to.equal('6666 7777 8888') |
@@ -218,11 +222,16 @@ describe('Test videos search', function () { | |||
218 | categoryOneOf: [ 1 ], | 222 | categoryOneOf: [ 1 ], |
219 | tagsOneOf: [ 'aAaa', 'ffff' ] | 223 | tagsOneOf: [ 'aAaa', 'ffff' ] |
220 | } | 224 | } |
221 | const res1 = await advancedVideosSearch(server.url, query) | ||
222 | expect(res1.body.total).to.equal(2) | ||
223 | 225 | ||
224 | const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] })) | 226 | { |
225 | expect(res2.body.total).to.equal(0) | 227 | const body = await command.advancedVideoSearch({ search: query }) |
228 | expect(body.total).to.equal(2) | ||
229 | } | ||
230 | |||
231 | { | ||
232 | const body = await command.advancedVideoSearch({ search: { ...query, tagsOneOf: [ 'blabla' ] } }) | ||
233 | expect(body.total).to.equal(0) | ||
234 | } | ||
226 | }) | 235 | }) |
227 | 236 | ||
228 | it('Should search by tags (all of)', async function () { | 237 | it('Should search by tags (all of)', async function () { |
@@ -231,14 +240,21 @@ describe('Test videos search', function () { | |||
231 | categoryOneOf: [ 1 ], | 240 | categoryOneOf: [ 1 ], |
232 | tagsAllOf: [ 'CCcc' ] | 241 | tagsAllOf: [ 'CCcc' ] |
233 | } | 242 | } |
234 | const res1 = await advancedVideosSearch(server.url, query) | ||
235 | expect(res1.body.total).to.equal(2) | ||
236 | 243 | ||
237 | const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blAbla' ] })) | 244 | { |
238 | expect(res2.body.total).to.equal(0) | 245 | const body = await command.advancedVideoSearch({ search: query }) |
246 | expect(body.total).to.equal(2) | ||
247 | } | ||
248 | |||
249 | { | ||
250 | const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'blAbla' ] } }) | ||
251 | expect(body.total).to.equal(0) | ||
252 | } | ||
239 | 253 | ||
240 | const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'CCCC' ] })) | 254 | { |
241 | expect(res3.body.total).to.equal(1) | 255 | const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'bbbb', 'CCCC' ] } }) |
256 | expect(body.total).to.equal(1) | ||
257 | } | ||
242 | }) | 258 | }) |
243 | 259 | ||
244 | it('Should search by category', async function () { | 260 | it('Should search by category', async function () { |
@@ -246,12 +262,17 @@ describe('Test videos search', function () { | |||
246 | search: '6666', | 262 | search: '6666', |
247 | categoryOneOf: [ 3 ] | 263 | categoryOneOf: [ 3 ] |
248 | } | 264 | } |
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 | 265 | ||
253 | const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] })) | 266 | { |
254 | expect(res2.body.total).to.equal(0) | 267 | const body = await command.advancedVideoSearch({ search: query }) |
268 | expect(body.total).to.equal(1) | ||
269 | expect(body.data[0].name).to.equal('6666 7777 8888') | ||
270 | } | ||
271 | |||
272 | { | ||
273 | const body = await command.advancedVideoSearch({ search: { ...query, categoryOneOf: [ 2 ] } }) | ||
274 | expect(body.total).to.equal(0) | ||
275 | } | ||
255 | }) | 276 | }) |
256 | 277 | ||
257 | it('Should search by licence', async function () { | 278 | it('Should search by licence', async function () { |
@@ -259,13 +280,18 @@ describe('Test videos search', function () { | |||
259 | search: '4444 5555', | 280 | search: '4444 5555', |
260 | licenceOneOf: [ 2 ] | 281 | licenceOneOf: [ 2 ] |
261 | } | 282 | } |
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 | 283 | ||
267 | const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] })) | 284 | { |
268 | expect(res2.body.total).to.equal(0) | 285 | const body = await command.advancedVideoSearch({ search: query }) |
286 | expect(body.total).to.equal(2) | ||
287 | expect(body.data[0].name).to.equal('3333 4444 5555') | ||
288 | expect(body.data[1].name).to.equal('3333 4444 5555 duplicate') | ||
289 | } | ||
290 | |||
291 | { | ||
292 | const body = await command.advancedVideoSearch({ search: { ...query, licenceOneOf: [ 3 ] } }) | ||
293 | expect(body.total).to.equal(0) | ||
294 | } | ||
269 | }) | 295 | }) |
270 | 296 | ||
271 | it('Should search by languages', async function () { | 297 | it('Should search by languages', async function () { |
@@ -275,23 +301,23 @@ describe('Test videos search', function () { | |||
275 | } | 301 | } |
276 | 302 | ||
277 | { | 303 | { |
278 | const res = await advancedVideosSearch(server.url, query) | 304 | const body = await command.advancedVideoSearch({ search: query }) |
279 | expect(res.body.total).to.equal(2) | 305 | expect(body.total).to.equal(2) |
280 | expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') | 306 | expect(body.data[0].name).to.equal('1111 2222 3333 - 3') |
281 | expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4') | 307 | expect(body.data[1].name).to.equal('1111 2222 3333 - 4') |
282 | } | 308 | } |
283 | 309 | ||
284 | { | 310 | { |
285 | const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'pl', 'en', '_unknown' ] })) | 311 | const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'pl', 'en', '_unknown' ] } }) |
286 | expect(res.body.total).to.equal(3) | 312 | expect(body.total).to.equal(3) |
287 | expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') | 313 | expect(body.data[0].name).to.equal('1111 2222 3333 - 3') |
288 | expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4') | 314 | expect(body.data[1].name).to.equal('1111 2222 3333 - 4') |
289 | expect(res.body.data[2].name).to.equal('1111 2222 3333 - 5') | 315 | expect(body.data[2].name).to.equal('1111 2222 3333 - 5') |
290 | } | 316 | } |
291 | 317 | ||
292 | { | 318 | { |
293 | const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] })) | 319 | const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'eo' ] } }) |
294 | expect(res.body.total).to.equal(0) | 320 | expect(body.total).to.equal(0) |
295 | } | 321 | } |
296 | }) | 322 | }) |
297 | 323 | ||
@@ -301,10 +327,10 @@ describe('Test videos search', function () { | |||
301 | startDate | 327 | startDate |
302 | } | 328 | } |
303 | 329 | ||
304 | const res = await advancedVideosSearch(server.url, query) | 330 | const body = await command.advancedVideoSearch({ search: query }) |
305 | expect(res.body.total).to.equal(4) | 331 | expect(body.total).to.equal(4) |
306 | 332 | ||
307 | const videos = res.body.data | 333 | const videos = body.data |
308 | expect(videos[0].name).to.equal('1111 2222 3333 - 5') | 334 | expect(videos[0].name).to.equal('1111 2222 3333 - 5') |
309 | expect(videos[1].name).to.equal('1111 2222 3333 - 6') | 335 | expect(videos[1].name).to.equal('1111 2222 3333 - 6') |
310 | expect(videos[2].name).to.equal('1111 2222 3333 - 7') | 336 | expect(videos[2].name).to.equal('1111 2222 3333 - 7') |
@@ -320,10 +346,10 @@ describe('Test videos search', function () { | |||
320 | licenceOneOf: [ 1, 4 ] | 346 | licenceOneOf: [ 1, 4 ] |
321 | } | 347 | } |
322 | 348 | ||
323 | const res = await advancedVideosSearch(server.url, query) | 349 | const body = await command.advancedVideoSearch({ search: query }) |
324 | expect(res.body.total).to.equal(4) | 350 | expect(body.total).to.equal(4) |
325 | 351 | ||
326 | const videos = res.body.data | 352 | const videos = body.data |
327 | expect(videos[0].name).to.equal('1111 2222 3333') | 353 | expect(videos[0].name).to.equal('1111 2222 3333') |
328 | expect(videos[1].name).to.equal('1111 2222 3333 - 6') | 354 | expect(videos[1].name).to.equal('1111 2222 3333 - 6') |
329 | expect(videos[2].name).to.equal('1111 2222 3333 - 7') | 355 | expect(videos[2].name).to.equal('1111 2222 3333 - 7') |
@@ -340,10 +366,10 @@ describe('Test videos search', function () { | |||
340 | sort: '-name' | 366 | sort: '-name' |
341 | } | 367 | } |
342 | 368 | ||
343 | const res = await advancedVideosSearch(server.url, query) | 369 | const body = await command.advancedVideoSearch({ search: query }) |
344 | expect(res.body.total).to.equal(4) | 370 | expect(body.total).to.equal(4) |
345 | 371 | ||
346 | const videos = res.body.data | 372 | const videos = body.data |
347 | expect(videos[0].name).to.equal('1111 2222 3333 - 8') | 373 | expect(videos[0].name).to.equal('1111 2222 3333 - 8') |
348 | expect(videos[1].name).to.equal('1111 2222 3333 - 7') | 374 | expect(videos[1].name).to.equal('1111 2222 3333 - 7') |
349 | expect(videos[2].name).to.equal('1111 2222 3333 - 6') | 375 | expect(videos[2].name).to.equal('1111 2222 3333 - 6') |
@@ -362,10 +388,10 @@ describe('Test videos search', function () { | |||
362 | count: 1 | 388 | count: 1 |
363 | } | 389 | } |
364 | 390 | ||
365 | const res = await advancedVideosSearch(server.url, query) | 391 | const body = await command.advancedVideoSearch({ search: query }) |
366 | expect(res.body.total).to.equal(4) | 392 | expect(body.total).to.equal(4) |
367 | 393 | ||
368 | const videos = res.body.data | 394 | const videos = body.data |
369 | expect(videos[0].name).to.equal('1111 2222 3333 - 8') | 395 | expect(videos[0].name).to.equal('1111 2222 3333 - 8') |
370 | }) | 396 | }) |
371 | 397 | ||
@@ -381,10 +407,10 @@ describe('Test videos search', function () { | |||
381 | count: 1 | 407 | count: 1 |
382 | } | 408 | } |
383 | 409 | ||
384 | const res = await advancedVideosSearch(server.url, query) | 410 | const body = await command.advancedVideoSearch({ search: query }) |
385 | expect(res.body.total).to.equal(4) | 411 | expect(body.total).to.equal(4) |
386 | 412 | ||
387 | const videos = res.body.data | 413 | const videos = body.data |
388 | expect(videos[0].name).to.equal('1111 2222 3333') | 414 | expect(videos[0].name).to.equal('1111 2222 3333') |
389 | }) | 415 | }) |
390 | 416 | ||
@@ -398,99 +424,140 @@ describe('Test videos search', function () { | |||
398 | } | 424 | } |
399 | 425 | ||
400 | { | 426 | { |
401 | const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }) | 427 | const query = { ...baseQuery, originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' } |
402 | const res = await advancedVideosSearch(server.url, query) | 428 | const body = await command.advancedVideoSearch({ search: query }) |
403 | 429 | ||
404 | expect(res.body.total).to.equal(1) | 430 | expect(body.total).to.equal(1) |
405 | expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') | 431 | expect(body.data[0].name).to.equal('1111 2222 3333 - 7') |
406 | } | 432 | } |
407 | 433 | ||
408 | { | 434 | { |
409 | const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }) | 435 | const query = { ...baseQuery, originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' } |
410 | const res = await advancedVideosSearch(server.url, query) | 436 | const body = await command.advancedVideoSearch({ search: query }) |
411 | 437 | ||
412 | expect(res.body.total).to.equal(1) | 438 | expect(body.total).to.equal(1) |
413 | expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') | 439 | expect(body.data[0].name).to.equal('1111 2222 3333 - 7') |
414 | } | 440 | } |
415 | 441 | ||
416 | { | 442 | { |
417 | const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }) | 443 | const query = { ...baseQuery, originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' } |
418 | const res = await advancedVideosSearch(server.url, query) | 444 | const body = await command.advancedVideoSearch({ search: query }) |
419 | 445 | ||
420 | expect(res.body.total).to.equal(0) | 446 | expect(body.total).to.equal(0) |
421 | } | 447 | } |
422 | 448 | ||
423 | { | 449 | { |
424 | const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }) | 450 | const query = { ...baseQuery, originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' } |
425 | const res = await advancedVideosSearch(server.url, query) | 451 | const body = await command.advancedVideoSearch({ search: query }) |
426 | 452 | ||
427 | expect(res.body.total).to.equal(0) | 453 | expect(body.total).to.equal(0) |
428 | } | 454 | } |
429 | 455 | ||
430 | { | 456 | { |
431 | const query = immutableAssign(baseQuery, { | 457 | const query = { |
458 | ...baseQuery, | ||
432 | originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', | 459 | originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', |
433 | originallyPublishedEndDate: '2019-01-10T09:58:08.286Z' | 460 | originallyPublishedEndDate: '2019-01-10T09:58:08.286Z' |
434 | }) | 461 | } |
435 | const res = await advancedVideosSearch(server.url, query) | 462 | const body = await command.advancedVideoSearch({ search: query }) |
436 | 463 | ||
437 | expect(res.body.total).to.equal(0) | 464 | expect(body.total).to.equal(0) |
438 | } | 465 | } |
439 | 466 | ||
440 | { | 467 | { |
441 | const query = immutableAssign(baseQuery, { | 468 | const query = { |
469 | ...baseQuery, | ||
442 | originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', | 470 | originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', |
443 | originallyPublishedEndDate: '2019-04-11T09:58:08.286Z' | 471 | originallyPublishedEndDate: '2019-04-11T09:58:08.286Z' |
444 | }) | 472 | } |
445 | const res = await advancedVideosSearch(server.url, query) | 473 | const body = await command.advancedVideoSearch({ search: query }) |
446 | 474 | ||
447 | expect(res.body.total).to.equal(1) | 475 | expect(body.total).to.equal(1) |
448 | expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') | 476 | expect(body.data[0].name).to.equal('1111 2222 3333 - 7') |
449 | } | 477 | } |
450 | }) | 478 | }) |
451 | 479 | ||
452 | it('Should search by UUID', async function () { | 480 | it('Should search by UUID', async function () { |
453 | const search = videoUUID | 481 | const search = videoUUID |
454 | const res = await advancedVideosSearch(server.url, { search }) | 482 | const body = await command.advancedVideoSearch({ search: { search } }) |
483 | |||
484 | expect(body.total).to.equal(1) | ||
485 | expect(body.data[0].name).to.equal('1111 2222 3333 - 3') | ||
486 | }) | ||
487 | |||
488 | it('Should filter by UUIDs', async function () { | ||
489 | for (const uuid of [ videoUUID, videoShortUUID ]) { | ||
490 | const body = await command.advancedVideoSearch({ search: { uuids: [ uuid ] } }) | ||
491 | |||
492 | expect(body.total).to.equal(1) | ||
493 | expect(body.data[0].name).to.equal('1111 2222 3333 - 3') | ||
494 | } | ||
495 | |||
496 | { | ||
497 | const body = await command.advancedVideoSearch({ search: { uuids: [ 'dfd70b83-639f-4980-94af-304a56ab4b35' ] } }) | ||
498 | |||
499 | expect(body.total).to.equal(0) | ||
500 | expect(body.data).to.have.lengthOf(0) | ||
501 | } | ||
502 | }) | ||
503 | |||
504 | it('Should search by host', async function () { | ||
505 | { | ||
506 | const body = await command.advancedVideoSearch({ search: { search: '6666 7777 8888', host: server.host } }) | ||
507 | expect(body.total).to.equal(1) | ||
508 | expect(body.data[0].name).to.equal('6666 7777 8888') | ||
509 | } | ||
455 | 510 | ||
456 | expect(res.body.total).to.equal(1) | 511 | { |
457 | expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') | 512 | const body = await command.advancedVideoSearch({ search: { search: '1111', host: 'example.com' } }) |
513 | expect(body.total).to.equal(0) | ||
514 | expect(body.data).to.have.lengthOf(0) | ||
515 | } | ||
516 | |||
517 | { | ||
518 | const body = await command.advancedVideoSearch({ search: { search: 'remote', host: remoteServer.host } }) | ||
519 | expect(body.total).to.equal(2) | ||
520 | expect(body.data).to.have.lengthOf(2) | ||
521 | expect(body.data[0].name).to.equal('remote video 1') | ||
522 | expect(body.data[1].name).to.equal('remote video 2') | ||
523 | } | ||
458 | }) | 524 | }) |
459 | 525 | ||
460 | it('Should search by live', async function () { | 526 | it('Should search by live', async function () { |
461 | this.timeout(30000) | 527 | this.timeout(60000) |
462 | 528 | ||
463 | { | 529 | { |
464 | const options = { | 530 | const newConfig = { |
465 | search: { | 531 | search: { |
466 | searchIndex: { enabled: false } | 532 | searchIndex: { enabled: false } |
467 | }, | 533 | }, |
468 | live: { enabled: true } | 534 | live: { enabled: true } |
469 | } | 535 | } |
470 | await updateCustomSubConfig(server.url, server.accessToken, options) | 536 | await server.config.updateCustomSubConfig({ newConfig }) |
471 | } | 537 | } |
472 | 538 | ||
473 | { | 539 | { |
474 | const res = await advancedVideosSearch(server.url, { isLive: true }) | 540 | const body = await command.advancedVideoSearch({ search: { isLive: true } }) |
475 | 541 | ||
476 | expect(res.body.total).to.equal(0) | 542 | expect(body.total).to.equal(0) |
477 | expect(res.body.data).to.have.lengthOf(0) | 543 | expect(body.data).to.have.lengthOf(0) |
478 | } | 544 | } |
479 | 545 | ||
480 | { | 546 | { |
481 | const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.videoChannel.id } | 547 | const liveCommand = server.live |
482 | const resLive = await createLive(server.url, server.accessToken, liveOptions) | 548 | |
483 | const liveVideoId = resLive.body.video.uuid | 549 | const liveAttributes = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.store.channel.id } |
550 | const live = await liveCommand.create({ fields: liveAttributes }) | ||
484 | 551 | ||
485 | const command = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId) | 552 | const ffmpegCommand = await liveCommand.sendRTMPStreamInVideo({ videoId: live.id }) |
486 | await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) | 553 | await liveCommand.waitUntilPublished({ videoId: live.id }) |
487 | 554 | ||
488 | const res = await advancedVideosSearch(server.url, { isLive: true }) | 555 | const body = await command.advancedVideoSearch({ search: { isLive: true } }) |
489 | 556 | ||
490 | expect(res.body.total).to.equal(1) | 557 | expect(body.total).to.equal(1) |
491 | expect(res.body.data[0].name).to.equal('live') | 558 | expect(body.data[0].name).to.equal('live') |
492 | 559 | ||
493 | await stopFfmpeg(command) | 560 | await stopFfmpeg(ffmpegCommand) |
494 | } | 561 | } |
495 | }) | 562 | }) |
496 | 563 | ||