Move utils to /shared
[oweals/peertube.git] / server / tests / api / videos / video-description.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6   flushAndRunMultipleServers,
7   getVideo,
8   getVideoDescription,
9   getVideosList,
10   killallServers,
11   ServerInfo,
12   setAccessTokensToServers,
13   updateVideo,
14   uploadVideo
15 } from '../../../../shared/utils/index'
16 import { doubleFollow } from '../../../../shared/utils/server/follows'
17 import { waitJobs } from '../../../../shared/utils/server/jobs'
18
19 const expect = chai.expect
20
21 describe('Test video description', function () {
22   let servers: ServerInfo[] = []
23   let videoUUID = ''
24   let videoId: number
25   let longDescription = 'my super description for server 1'.repeat(50)
26
27   before(async function () {
28     this.timeout(40000)
29
30     // Run servers
31     servers = await flushAndRunMultipleServers(2)
32
33     // Get the access tokens
34     await setAccessTokensToServers(servers)
35
36     // Server 1 and server 2 follow each other
37     await doubleFollow(servers[0], servers[1])
38   })
39
40   it('Should upload video with long description', async function () {
41     this.timeout(10000)
42
43     const attributes = {
44       description: longDescription
45     }
46     await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
47
48     await waitJobs(servers)
49
50     const res = await getVideosList(servers[0].url)
51
52     videoId = res.body.data[0].id
53     videoUUID = res.body.data[0].uuid
54   })
55
56   it('Should have a truncated description on each server', async function () {
57     for (const server of servers) {
58       const res = await getVideo(server.url, videoUUID)
59       const video = res.body
60
61       // 30 characters * 6 -> 240 characters
62       const truncatedDescription = 'my super description for server 1'.repeat(7) +
63                                    'my super descrip...'
64
65       expect(video.description).to.equal(truncatedDescription)
66     }
67   })
68
69   it('Should fetch long description on each server', async function () {
70     for (const server of servers) {
71       const res = await getVideo(server.url, videoUUID)
72       const video = res.body
73
74       const res2 = await getVideoDescription(server.url, video.descriptionPath)
75       expect(res2.body.description).to.equal(longDescription)
76     }
77   })
78
79   it('Should update with a short description', async function () {
80     this.timeout(10000)
81
82     const attributes = {
83       description: 'short description'
84     }
85     await updateVideo(servers[0].url, servers[0].accessToken, videoId, attributes)
86
87     await waitJobs(servers)
88   })
89
90   it('Should have a small description on each server', async function () {
91     for (const server of servers) {
92       const res = await getVideo(server.url, videoUUID)
93       const video = res.body
94
95       expect(video.description).to.equal('short description')
96
97       const res2 = await getVideoDescription(server.url, video.descriptionPath)
98       expect(res2.body.description).to.equal('short description')
99     }
100   })
101
102   after(async function () {
103     killallServers(servers)
104   })
105 })