search-videos.ts 14.6 KB
Newer Older
Chocobozzz's avatar
Chocobozzz committed
1
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
Chocobozzz's avatar
Chocobozzz committed
2
3

import 'mocha'
4
import * as chai from 'chai'
Chocobozzz's avatar
Chocobozzz committed
5
import {
6
  cleanupTests,
7
8
  createSingleServer,
  PeerTubeServer,
Chocobozzz's avatar
Chocobozzz committed
9
  SearchCommand,
Chocobozzz's avatar
Chocobozzz committed
10
  setAccessTokensToServers,
11
12
  setDefaultVideoChannel,
  stopFfmpeg,
Chocobozzz's avatar
Chocobozzz committed
13
14
15
  wait
} from '@shared/extra-utils'
import { VideoPrivacy } from '@shared/models'
Chocobozzz's avatar
Chocobozzz committed
16
17
18

const expect = chai.expect

Chocobozzz's avatar
Chocobozzz committed
19
describe('Test videos search', function () {
20
  let server: PeerTubeServer = null
Chocobozzz's avatar
Chocobozzz committed
21
  let startDate: string
Chocobozzz's avatar
Chocobozzz committed
22
  let videoUUID: string
Chocobozzz's avatar
Chocobozzz committed
23

Chocobozzz's avatar
Chocobozzz committed
24
25
  let command: SearchCommand

Chocobozzz's avatar
Chocobozzz committed
26
  before(async function () {
27
    this.timeout(60000)
Chocobozzz's avatar
Chocobozzz committed
28

29
    server = await createSingleServer(1)
Chocobozzz's avatar
Chocobozzz committed
30
31

    await setAccessTokensToServers([ server ])
32
    await setDefaultVideoChannel([ server ])
Chocobozzz's avatar
Chocobozzz committed
33
34
35
36
37
38
39
40
41
42

    {
      const attributes1 = {
        name: '1111 2222 3333',
        fixture: '60fps_720p_small.mp4', // 2 seconds
        category: 1,
        licence: 1,
        nsfw: false,
        language: 'fr'
      }
Chocobozzz's avatar
Chocobozzz committed
43
      await server.videos.upload({ attributes: attributes1 })
Chocobozzz's avatar
Chocobozzz committed
44

Chocobozzz's avatar
Chocobozzz committed
45
      const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }
Chocobozzz's avatar
Chocobozzz committed
46
      await server.videos.upload({ attributes: attributes2 })
Chocobozzz's avatar
Chocobozzz committed
47

48
      {
Chocobozzz's avatar
Chocobozzz committed
49
        const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined }
Chocobozzz's avatar
Chocobozzz committed
50
        const { id, uuid } = await server.videos.upload({ attributes: attributes3 })
Chocobozzz's avatar
Chocobozzz committed
51
        videoUUID = uuid
52

Chocobozzz's avatar
Chocobozzz committed
53
        await server.captions.add({
54
          language: 'en',
Chocobozzz's avatar
Chocobozzz committed
55
          videoId: id,
56
57
58
59
          fixture: 'subtitle-good2.vtt',
          mimeType: 'application/octet-stream'
        })

Chocobozzz's avatar
Chocobozzz committed
60
        await server.captions.add({
61
          language: 'aa',
Chocobozzz's avatar
Chocobozzz committed
62
          videoId: id,
63
64
65
66
          fixture: 'subtitle-good2.vtt',
          mimeType: 'application/octet-stream'
        })
      }
Chocobozzz's avatar
Chocobozzz committed
67

Chocobozzz's avatar
Chocobozzz committed
68
      const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true }
Chocobozzz's avatar
Chocobozzz committed
69
      await server.videos.upload({ attributes: attributes4 })
Chocobozzz's avatar
Chocobozzz committed
70
71
72
73
74

      await wait(1000)

      startDate = new Date().toISOString()

Chocobozzz's avatar
Chocobozzz committed
75
      const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined }
Chocobozzz's avatar
Chocobozzz committed
76
      await server.videos.upload({ attributes: attributes5 })
Chocobozzz's avatar
Chocobozzz committed
77

Chocobozzz's avatar
Chocobozzz committed
78
      const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }
Chocobozzz's avatar
Chocobozzz committed
79
      await server.videos.upload({ attributes: attributes6 })
Chocobozzz's avatar
Chocobozzz committed
80

Chocobozzz's avatar
Chocobozzz committed
81
      const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' }
Chocobozzz's avatar
Chocobozzz committed
82
      await server.videos.upload({ attributes: attributes7 })
Chocobozzz's avatar
Chocobozzz committed
83

Chocobozzz's avatar
Chocobozzz committed
84
      const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 }
Chocobozzz's avatar
Chocobozzz committed
85
      await server.videos.upload({ attributes: attributes8 })
Chocobozzz's avatar
Chocobozzz committed
86
87
88
89
90
91
92
93
94
95
    }

    {
      const attributes = {
        name: '3333 4444 5555',
        fixture: 'video_short.mp4',
        category: 2,
        licence: 2,
        language: 'en'
      }
Chocobozzz's avatar
Chocobozzz committed
96
      await server.videos.upload({ attributes: attributes })
Chocobozzz's avatar
Chocobozzz committed
97

Chocobozzz's avatar
Chocobozzz committed
98
      await server.videos.upload({ attributes: { ...attributes, name: attributes.name + ' duplicate' } })
Chocobozzz's avatar
Chocobozzz committed
99
100
101
102
103
104
105
106
107
108
    }

    {
      const attributes = {
        name: '6666 7777 8888',
        fixture: 'video_short.mp4',
        category: 3,
        licence: 3,
        language: 'pl'
      }
Chocobozzz's avatar
Chocobozzz committed
109
      await server.videos.upload({ attributes: attributes })
Chocobozzz's avatar
Chocobozzz committed
110
111
112
113
114
115
116
117
    }

    {
      const attributes1 = {
        name: '9999',
        tags: [ 'aaaa', 'bbbb', 'cccc' ],
        category: 1
      }
Chocobozzz's avatar
Chocobozzz committed
118
119
      await server.videos.upload({ attributes: attributes1 })
      await server.videos.upload({ attributes: { ...attributes1, category: 2 } })
Chocobozzz's avatar
Chocobozzz committed
120

Chocobozzz's avatar
Chocobozzz committed
121
122
      await server.videos.upload({ attributes: { ...attributes1, tags: [ 'cccc', 'dddd' ] } })
      await server.videos.upload({ attributes: { ...attributes1, tags: [ 'eeee', 'ffff' ] } })
Chocobozzz's avatar
Chocobozzz committed
123
    }
124
125
126
127
128
129

    {
      const attributes1 = {
        name: 'aaaa 2',
        category: 1
      }
Chocobozzz's avatar
Chocobozzz committed
130
131
      await server.videos.upload({ attributes: attributes1 })
      await server.videos.upload({ attributes: { ...attributes1, category: 2 } })
132
    }
Chocobozzz's avatar
Chocobozzz committed
133

Chocobozzz's avatar
Chocobozzz committed
134
    command = server.search
Chocobozzz's avatar
Chocobozzz committed
135
136
137
  })

  it('Should make a simple search and not have results', async function () {
Chocobozzz's avatar
Chocobozzz committed
138
    const body = await command.searchVideos({ search: 'abc' })
Chocobozzz's avatar
Chocobozzz committed
139

Chocobozzz's avatar
Chocobozzz committed
140
141
    expect(body.total).to.equal(0)
    expect(body.data).to.have.lengthOf(0)
Chocobozzz's avatar
Chocobozzz committed
142
143
144
  })

  it('Should make a simple search and have results', async function () {
Chocobozzz's avatar
Chocobozzz committed
145
    const body = await command.searchVideos({ search: '4444 5555 duplicate' })
Chocobozzz's avatar
Chocobozzz committed
146

Chocobozzz's avatar
Chocobozzz committed
147
    expect(body.total).to.equal(2)
Chocobozzz's avatar
Chocobozzz committed
148

Chocobozzz's avatar
Chocobozzz committed
149
    const videos = body.data
Chocobozzz's avatar
Chocobozzz committed
150
151
152
153
154
155
156
    expect(videos).to.have.lengthOf(2)

    // bestmatch
    expect(videos[0].name).to.equal('3333 4444 5555 duplicate')
    expect(videos[1].name).to.equal('3333 4444 5555')
  })

157
  it('Should make a search on tags too, and have results', async function () {
Chocobozzz's avatar
Chocobozzz committed
158
    const search = {
159
160
161
      search: 'aaaa',
      categoryOneOf: [ 1 ]
    }
Chocobozzz's avatar
Chocobozzz committed
162
    const body = await command.advancedVideoSearch({ search })
163

Chocobozzz's avatar
Chocobozzz committed
164
    expect(body.total).to.equal(2)
165

Chocobozzz's avatar
Chocobozzz committed
166
    const videos = body.data
167
168
169
170
171
172
173
174
    expect(videos).to.have.lengthOf(2)

    // bestmatch
    expect(videos[0].name).to.equal('aaaa 2')
    expect(videos[1].name).to.equal('9999')
  })

  it('Should filter on tags without a search', async function () {
Chocobozzz's avatar
Chocobozzz committed
175
    const search = {
176
177
      tagsAllOf: [ 'bbbb' ]
    }
Chocobozzz's avatar
Chocobozzz committed
178
    const body = await command.advancedVideoSearch({ search })
179

Chocobozzz's avatar
Chocobozzz committed
180
    expect(body.total).to.equal(2)
181

Chocobozzz's avatar
Chocobozzz committed
182
    const videos = body.data
183
184
185
186
187
188
189
    expect(videos).to.have.lengthOf(2)

    expect(videos[0].name).to.equal('9999')
    expect(videos[1].name).to.equal('9999')
  })

  it('Should filter on category without a search', async function () {
Chocobozzz's avatar
Chocobozzz committed
190
    const search = {
191
192
      categoryOneOf: [ 3 ]
    }
Chocobozzz's avatar
Chocobozzz committed
193
    const body = await command.advancedVideoSearch({ search: search })
194

Chocobozzz's avatar
Chocobozzz committed
195
    expect(body.total).to.equal(1)
196

Chocobozzz's avatar
Chocobozzz committed
197
    const videos = body.data
198
199
200
201
202
    expect(videos).to.have.lengthOf(1)

    expect(videos[0].name).to.equal('6666 7777 8888')
  })

Chocobozzz's avatar
Chocobozzz committed
203
204
205
206
  it('Should search by tags (one of)', async function () {
    const query = {
      search: '9999',
      categoryOneOf: [ 1 ],
Chocobozzz's avatar
Chocobozzz committed
207
      tagsOneOf: [ 'aAaa', 'ffff' ]
Chocobozzz's avatar
Chocobozzz committed
208
209
    }

Chocobozzz's avatar
Chocobozzz committed
210
211
212
213
214
215
216
217
218
    {
      const body = await command.advancedVideoSearch({ search: query })
      expect(body.total).to.equal(2)
    }

    {
      const body = await command.advancedVideoSearch({ search: { ...query, tagsOneOf: [ 'blabla' ] } })
      expect(body.total).to.equal(0)
    }
Chocobozzz's avatar
Chocobozzz committed
219
220
221
222
223
224
  })

  it('Should search by tags (all of)', async function () {
    const query = {
      search: '9999',
      categoryOneOf: [ 1 ],
Chocobozzz's avatar
Chocobozzz committed
225
      tagsAllOf: [ 'CCcc' ]
Chocobozzz's avatar
Chocobozzz committed
226
227
    }

Chocobozzz's avatar
Chocobozzz committed
228
229
230
231
    {
      const body = await command.advancedVideoSearch({ search: query })
      expect(body.total).to.equal(2)
    }
Chocobozzz's avatar
Chocobozzz committed
232

Chocobozzz's avatar
Chocobozzz committed
233
234
235
236
237
238
239
240
241
    {
      const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'blAbla' ] } })
      expect(body.total).to.equal(0)
    }

    {
      const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'bbbb', 'CCCC' ] } })
      expect(body.total).to.equal(1)
    }
Chocobozzz's avatar
Chocobozzz committed
242
243
244
245
246
247
248
249
  })

  it('Should search by category', async function () {
    const query = {
      search: '6666',
      categoryOneOf: [ 3 ]
    }

Chocobozzz's avatar
Chocobozzz committed
250
251
252
253
254
255
256
257
258
259
    {
      const body = await command.advancedVideoSearch({ search: query })
      expect(body.total).to.equal(1)
      expect(body.data[0].name).to.equal('6666 7777 8888')
    }

    {
      const body = await command.advancedVideoSearch({ search: { ...query, categoryOneOf: [ 2 ] } })
      expect(body.total).to.equal(0)
    }
Chocobozzz's avatar
Chocobozzz committed
260
261
262
263
264
265
266
267
  })

  it('Should search by licence', async function () {
    const query = {
      search: '4444 5555',
      licenceOneOf: [ 2 ]
    }

Chocobozzz's avatar
Chocobozzz committed
268
269
270
271
272
273
274
275
276
277
278
    {
      const body = await command.advancedVideoSearch({ search: query })
      expect(body.total).to.equal(2)
      expect(body.data[0].name).to.equal('3333 4444 5555')
      expect(body.data[1].name).to.equal('3333 4444 5555 duplicate')
    }

    {
      const body = await command.advancedVideoSearch({ search: { ...query, licenceOneOf: [ 3 ] } })
      expect(body.total).to.equal(0)
    }
Chocobozzz's avatar
Chocobozzz committed
279
280
281
282
283
284
285
286
  })

  it('Should search by languages', async function () {
    const query = {
      search: '1111 2222 3333',
      languageOneOf: [ 'pl', 'en' ]
    }

287
    {
Chocobozzz's avatar
Chocobozzz committed
288
289
290
291
      const body = await command.advancedVideoSearch({ search: query })
      expect(body.total).to.equal(2)
      expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
      expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
292
293
294
    }

    {
Chocobozzz's avatar
Chocobozzz committed
295
296
297
298
299
      const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'pl', 'en', '_unknown' ] } })
      expect(body.total).to.equal(3)
      expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
      expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
      expect(body.data[2].name).to.equal('1111 2222 3333 - 5')
300
301
302
    }

    {
Chocobozzz's avatar
Chocobozzz committed
303
304
      const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'eo' ] } })
      expect(body.total).to.equal(0)
305
    }
Chocobozzz's avatar
Chocobozzz committed
306
307
308
309
310
311
312
313
  })

  it('Should search by start date', async function () {
    const query = {
      search: '1111 2222 3333',
      startDate
    }

Chocobozzz's avatar
Chocobozzz committed
314
315
    const body = await command.advancedVideoSearch({ search: query })
    expect(body.total).to.equal(4)
Chocobozzz's avatar
Chocobozzz committed
316

Chocobozzz's avatar
Chocobozzz committed
317
    const videos = body.data
Chocobozzz's avatar
Chocobozzz committed
318
319
320
321
322
323
324
325
326
327
328
    expect(videos[0].name).to.equal('1111 2222 3333 - 5')
    expect(videos[1].name).to.equal('1111 2222 3333 - 6')
    expect(videos[2].name).to.equal('1111 2222 3333 - 7')
    expect(videos[3].name).to.equal('1111 2222 3333 - 8')
  })

  it('Should make an advanced search', async function () {
    const query = {
      search: '1111 2222 3333',
      languageOneOf: [ 'pl', 'fr' ],
      durationMax: 4,
Chocobozzz's avatar
Chocobozzz committed
329
      nsfw: 'false' as 'false',
Chocobozzz's avatar
Chocobozzz committed
330
331
332
      licenceOneOf: [ 1, 4 ]
    }

Chocobozzz's avatar
Chocobozzz committed
333
334
    const body = await command.advancedVideoSearch({ search: query })
    expect(body.total).to.equal(4)
Chocobozzz's avatar
Chocobozzz committed
335

Chocobozzz's avatar
Chocobozzz committed
336
    const videos = body.data
Chocobozzz's avatar
Chocobozzz committed
337
338
339
340
341
342
343
344
345
346
347
    expect(videos[0].name).to.equal('1111 2222 3333')
    expect(videos[1].name).to.equal('1111 2222 3333 - 6')
    expect(videos[2].name).to.equal('1111 2222 3333 - 7')
    expect(videos[3].name).to.equal('1111 2222 3333 - 8')
  })

  it('Should make an advanced search and sort results', async function () {
    const query = {
      search: '1111 2222 3333',
      languageOneOf: [ 'pl', 'fr' ],
      durationMax: 4,
Chocobozzz's avatar
Chocobozzz committed
348
      nsfw: 'false' as 'false',
Chocobozzz's avatar
Chocobozzz committed
349
350
351
352
      licenceOneOf: [ 1, 4 ],
      sort: '-name'
    }

Chocobozzz's avatar
Chocobozzz committed
353
354
    const body = await command.advancedVideoSearch({ search: query })
    expect(body.total).to.equal(4)
Chocobozzz's avatar
Chocobozzz committed
355

Chocobozzz's avatar
Chocobozzz committed
356
    const videos = body.data
Chocobozzz's avatar
Chocobozzz committed
357
358
359
360
361
362
363
364
365
366
367
    expect(videos[0].name).to.equal('1111 2222 3333 - 8')
    expect(videos[1].name).to.equal('1111 2222 3333 - 7')
    expect(videos[2].name).to.equal('1111 2222 3333 - 6')
    expect(videos[3].name).to.equal('1111 2222 3333')
  })

  it('Should make an advanced search and only show the first result', async function () {
    const query = {
      search: '1111 2222 3333',
      languageOneOf: [ 'pl', 'fr' ],
      durationMax: 4,
Chocobozzz's avatar
Chocobozzz committed
368
      nsfw: 'false' as 'false',
Chocobozzz's avatar
Chocobozzz committed
369
370
371
372
373
374
      licenceOneOf: [ 1, 4 ],
      sort: '-name',
      start: 0,
      count: 1
    }

Chocobozzz's avatar
Chocobozzz committed
375
376
    const body = await command.advancedVideoSearch({ search: query })
    expect(body.total).to.equal(4)
Chocobozzz's avatar
Chocobozzz committed
377

Chocobozzz's avatar
Chocobozzz committed
378
    const videos = body.data
Chocobozzz's avatar
Chocobozzz committed
379
380
381
382
383
384
385
386
    expect(videos[0].name).to.equal('1111 2222 3333 - 8')
  })

  it('Should make an advanced search and only show the last result', async function () {
    const query = {
      search: '1111 2222 3333',
      languageOneOf: [ 'pl', 'fr' ],
      durationMax: 4,
Chocobozzz's avatar
Chocobozzz committed
387
      nsfw: 'false' as 'false',
Chocobozzz's avatar
Chocobozzz committed
388
389
390
391
392
393
      licenceOneOf: [ 1, 4 ],
      sort: '-name',
      start: 3,
      count: 1
    }

Chocobozzz's avatar
Chocobozzz committed
394
395
    const body = await command.advancedVideoSearch({ search: query })
    expect(body.total).to.equal(4)
Chocobozzz's avatar
Chocobozzz committed
396

Chocobozzz's avatar
Chocobozzz committed
397
    const videos = body.data
Chocobozzz's avatar
Chocobozzz committed
398
399
400
    expect(videos[0].name).to.equal('1111 2222 3333')
  })

401
402
403
404
405
406
407
408
409
410
  it('Should search on originally published date', async function () {
    const baseQuery = {
      search: '1111 2222 3333',
      languageOneOf: [ 'pl', 'fr' ],
      durationMax: 4,
      nsfw: 'false' as 'false',
      licenceOneOf: [ 1, 4 ]
    }

    {
Chocobozzz's avatar
Chocobozzz committed
411
      const query = { ...baseQuery, originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }
Chocobozzz's avatar
Chocobozzz committed
412
      const body = await command.advancedVideoSearch({ search: query })
413

Chocobozzz's avatar
Chocobozzz committed
414
415
      expect(body.total).to.equal(1)
      expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
416
417
418
    }

    {
Chocobozzz's avatar
Chocobozzz committed
419
      const query = { ...baseQuery, originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }
Chocobozzz's avatar
Chocobozzz committed
420
      const body = await command.advancedVideoSearch({ search: query })
421

Chocobozzz's avatar
Chocobozzz committed
422
423
      expect(body.total).to.equal(1)
      expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
424
425
426
    }

    {
Chocobozzz's avatar
Chocobozzz committed
427
      const query = { ...baseQuery, originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }
Chocobozzz's avatar
Chocobozzz committed
428
      const body = await command.advancedVideoSearch({ search: query })
429

Chocobozzz's avatar
Chocobozzz committed
430
      expect(body.total).to.equal(0)
431
432
433
    }

    {
Chocobozzz's avatar
Chocobozzz committed
434
      const query = { ...baseQuery, originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }
Chocobozzz's avatar
Chocobozzz committed
435
      const body = await command.advancedVideoSearch({ search: query })
436

Chocobozzz's avatar
Chocobozzz committed
437
      expect(body.total).to.equal(0)
438
439
440
    }

    {
Chocobozzz's avatar
Chocobozzz committed
441
442
      const query = {
        ...baseQuery,
443
444
        originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
        originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
Chocobozzz's avatar
Chocobozzz committed
445
      }
Chocobozzz's avatar
Chocobozzz committed
446
      const body = await command.advancedVideoSearch({ search: query })
447

Chocobozzz's avatar
Chocobozzz committed
448
      expect(body.total).to.equal(0)
449
450
451
    }

    {
Chocobozzz's avatar
Chocobozzz committed
452
453
      const query = {
        ...baseQuery,
454
455
        originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
        originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
Chocobozzz's avatar
Chocobozzz committed
456
      }
Chocobozzz's avatar
Chocobozzz committed
457
      const body = await command.advancedVideoSearch({ search: query })
458

Chocobozzz's avatar
Chocobozzz committed
459
460
      expect(body.total).to.equal(1)
      expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
461
462
463
    }
  })

Chocobozzz's avatar
Chocobozzz committed
464
465
  it('Should search by UUID', async function () {
    const search = videoUUID
Chocobozzz's avatar
Chocobozzz committed
466
    const body = await command.advancedVideoSearch({ search: { search } })
Chocobozzz's avatar
Chocobozzz committed
467

Chocobozzz's avatar
Chocobozzz committed
468
469
    expect(body.total).to.equal(1)
    expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
Chocobozzz's avatar
Chocobozzz committed
470
471
  })

472
473
474
475
  it('Should search by live', async function () {
    this.timeout(30000)

    {
Chocobozzz's avatar
Chocobozzz committed
476
      const newConfig = {
477
478
479
480
481
        search: {
          searchIndex: { enabled: false }
        },
        live: { enabled: true }
      }
Chocobozzz's avatar
Chocobozzz committed
482
      await server.config.updateCustomSubConfig({ newConfig })
483
484
485
    }

    {
Chocobozzz's avatar
Chocobozzz committed
486
      const body = await command.advancedVideoSearch({ search: { isLive: true } })
487

Chocobozzz's avatar
Chocobozzz committed
488
489
      expect(body.total).to.equal(0)
      expect(body.data).to.have.lengthOf(0)
490
491
492
    }

    {
Chocobozzz's avatar
Chocobozzz committed
493
      const liveCommand = server.live
Chocobozzz's avatar
Chocobozzz committed
494

Chocobozzz's avatar
Chocobozzz committed
495
      const liveAttributes = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.store.channel.id }
Chocobozzz's avatar
Chocobozzz committed
496
      const live = await liveCommand.create({ fields: liveAttributes })
497

Chocobozzz's avatar
Chocobozzz committed
498
      const ffmpegCommand = await liveCommand.sendRTMPStreamInVideo({ videoId: live.id })
Chocobozzz's avatar
Chocobozzz committed
499
      await liveCommand.waitUntilPublished({ videoId: live.id })
500

Chocobozzz's avatar
Chocobozzz committed
501
      const body = await command.advancedVideoSearch({ search: { isLive: true } })
502

Chocobozzz's avatar
Chocobozzz committed
503
504
      expect(body.total).to.equal(1)
      expect(body.data[0].name).to.equal('live')
505

Chocobozzz's avatar
Chocobozzz committed
506
      await stopFfmpeg(ffmpegCommand)
507
508
509
    }
  })

Chocobozzz's avatar
Chocobozzz committed
510
511
  after(async function () {
    await cleanupTests([ server ])
Chocobozzz's avatar
Chocobozzz committed
512
513
  })
})