aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/video-blacklist.ts
blob: e789611d0778e889bbc5cd150dc035c75e9fb881 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* tslint:disable:no-unused-expression */

import 'mocha'
import * as chai from 'chai'
const expect = chai.expect

import {
  ServerInfo,
  flushTests,
  uploadVideo,
  makeFriends,
  getVideosList,
  wait,
  setAccessTokensToServers,
  flushAndRunMultipleServers,
  addVideoToBlacklist,
  searchVideo,
  killallServers
} from '../utils'

describe('Test video blacklists', function () {
  let servers: ServerInfo[] = []

  before(async function () {
    this.timeout(120000)

    // Run servers
    servers = await flushAndRunMultipleServers(2)

    // Get the access tokens
    await setAccessTokensToServers(servers)

    // Pod 1 makes friend with pod 2
    await makeFriends(servers[0].url, servers[0].accessToken)

    // Upload a video on pod 2
    const videoAttributes = {
      name: 'my super name for pod 2',
      description: 'my super description for pod 2'
    }
    await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)

    // Wait videos propagation
    await wait(22000)

    const res = await getVideosList(servers[0].url)
    const videos = res.body.data

    expect(videos.length).to.equal(1)

    servers[0].remoteVideo = videos.find(video => video.name === 'my super name for pod 2')
  })

  it('Should blacklist a remote video on pod 1', async function () {
    await addVideoToBlacklist(servers[0].url, servers[0].accessToken, servers[0].remoteVideo.id)
  })

  it('Should not have the video blacklisted in videos list on pod 1', async function () {
    const res = await getVideosList(servers[0].url)

    expect(res.body.total).to.equal(0)
    expect(res.body.data).to.be.an('array')
    expect(res.body.data.length).to.equal(0)
  })

  it('Should not have the video blacklisted in videos search on pod 1', async function () {
    const res = await searchVideo(servers[0].url, 'name')

    expect(res.body.total).to.equal(0)
    expect(res.body.data).to.be.an('array')
    expect(res.body.data.length).to.equal(0)
  })

  it('Should have the blacklisted video in videos list on pod 2', async function () {
    const res = await getVideosList(servers[1].url)

    expect(res.body.total).to.equal(1)
    expect(res.body.data).to.be.an('array')
    expect(res.body.data.length).to.equal(1)
  })

  it('Should have the video blacklisted in videos search on pod 2', async function () {
    const res = await searchVideo(servers[1].url, 'name')

    expect(res.body.total).to.equal(1)
    expect(res.body.data).to.be.an('array')
    expect(res.body.data.length).to.equal(1)
  })

  after(async function () {
    killallServers(servers)

    // Keep the logs if the test failed
    if (this['ok']) {
      await flushTests()
    }
  })
})