aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages/tests/src/api/videos/video-description.ts
blob: eb41cd71cc1dccf8a013396755c7bdffdf80bddf (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
99
100
101
102
103
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import { expect } from 'chai'
import {
  cleanupTests,
  createMultipleServers,
  doubleFollow,
  PeerTubeServer,
  setAccessTokensToServers,
  waitJobs
} from '@peertube/peertube-server-commands'

describe('Test video description', function () {
  let servers: PeerTubeServer[] = []
  let videoUUID = ''
  let videoId: number

  const longDescription = 'my super description for server 1'.repeat(50)

  // 30 characters * 6 -> 240 characters
  const truncatedDescription = 'my super description for server 1'.repeat(7) + 'my super descrip...'

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

    // Run servers
    servers = await createMultipleServers(2)

    // Get the access tokens
    await setAccessTokensToServers(servers)

    // Server 1 and server 2 follow each other
    await doubleFollow(servers[0], servers[1])
  })

  it('Should upload video with long description', async function () {
    this.timeout(30000)

    const attributes = {
      description: longDescription
    }
    await servers[0].videos.upload({ attributes })

    await waitJobs(servers)

    const { data } = await servers[0].videos.list()

    videoId = data[0].id
    videoUUID = data[0].uuid
  })

  it('Should have a truncated description on each server when listing videos', async function () {
    for (const server of servers) {
      const { data } = await server.videos.list()
      const video = data.find(v => v.uuid === videoUUID)

      expect(video.description).to.equal(truncatedDescription)
      expect(video.truncatedDescription).to.equal(truncatedDescription)
    }
  })

  it('Should not have a truncated description on each server when getting videos', async function () {
    for (const server of servers) {
      const video = await server.videos.get({ id: videoUUID })

      expect(video.description).to.equal(longDescription)
      expect(video.truncatedDescription).to.equal(truncatedDescription)
    }
  })

  it('Should fetch long description on each server', async function () {
    for (const server of servers) {
      const video = await server.videos.get({ id: videoUUID })

      const { description } = await server.videos.getDescription({ descriptionPath: video.descriptionPath })
      expect(description).to.equal(longDescription)
    }
  })

  it('Should update with a short description', async function () {
    const attributes = {
      description: 'short description'
    }
    await servers[0].videos.update({ id: videoId, attributes })

    await waitJobs(servers)
  })

  it('Should have a small description on each server', async function () {
    for (const server of servers) {
      const video = await server.videos.get({ id: videoUUID })

      expect(video.description).to.equal('short description')

      const { description } = await server.videos.getDescription({ descriptionPath: video.descriptionPath })
      expect(description).to.equal('short description')
    }
  })

  after(async function () {
    await cleanupTests(servers)
  })
})