]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-privacy.ts
Try parallel check params tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-privacy.ts
CommitLineData
11474c3c
C
1/* tslint:disable:no-unused-expression */
2
11474c3c 3import * as chai from 'chai'
975e6e0e 4import 'mocha'
c5d31dba 5import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
11474c3c 6import {
7c3b7976 7 cleanupTests,
975e6e0e 8 flushAndRunMultipleServers,
11474c3c 9 getVideosList,
975e6e0e
C
10 killallServers,
11 ServerInfo,
11474c3c 12 setAccessTokensToServers,
3cd0734f 13 uploadVideo
94565d52
C
14} from '../../../../shared/extra-utils/index'
15import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
16import { userLogin } from '../../../../shared/extra-utils/users/login'
17import { createUser } from '../../../../shared/extra-utils/users/users'
18import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos'
19import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
975e6e0e
C
20
21const expect = chai.expect
11474c3c
C
22
23describe('Test video privacy', function () {
24 let servers: ServerInfo[] = []
c49db162
C
25 let privateVideoId: number
26 let privateVideoUUID: string
27 let unlistedVideoUUID: string
28 let now: number
11474c3c
C
29
30 before(async function () {
572f8d3d 31 this.timeout(50000)
11474c3c
C
32
33 // Run servers
34 servers = await flushAndRunMultipleServers(2)
35
36 // Get the access tokens
37 await setAccessTokensToServers(servers)
38
975e6e0e
C
39 // Server 1 and server 2 follow each other
40 await doubleFollow(servers[0], servers[1])
11474c3c
C
41 })
42
975e6e0e 43 it('Should upload a private video on server 1', async function () {
572f8d3d 44 this.timeout(10000)
11474c3c
C
45
46 const attributes = {
47 privacy: VideoPrivacy.PRIVATE
48 }
49 await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
50
3cd0734f 51 await waitJobs(servers)
11474c3c
C
52 })
53
975e6e0e 54 it('Should not have this private video on server 2', async function () {
11474c3c
C
55 const res = await getVideosList(servers[1].url)
56
57 expect(res.body.total).to.equal(0)
58 expect(res.body.data).to.have.lengthOf(0)
59 })
60
61 it('Should list my (private) videos', async function () {
62 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 1)
63
64 expect(res.body.total).to.equal(1)
65 expect(res.body.data).to.have.lengthOf(1)
66
67 privateVideoId = res.body.data[0].id
68 privateVideoUUID = res.body.data[0].uuid
69 })
70
71 it('Should not be able to watch this video with non authenticated user', async function () {
72 await getVideo(servers[0].url, privateVideoUUID, 401)
73 })
74
75 it('Should not be able to watch this private video with another user', async function () {
77a87fec
C
76 this.timeout(10000)
77
11474c3c
C
78 const user = {
79 username: 'hello',
80 password: 'super password'
81 }
1eddc9a7 82 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
11474c3c 83
eec63bbc 84 const token = await userLogin(servers[0], user)
11474c3c
C
85 await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403)
86 })
87
88 it('Should be able to watch this video with the correct user', async function () {
89 await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID)
90 })
91
9a27cdc2 92 it('Should upload an unlisted video on server 2', async function () {
572f8d3d 93 this.timeout(30000)
11474c3c
C
94
95 const attributes = {
96 name: 'unlisted video',
97 privacy: VideoPrivacy.UNLISTED
98 }
99 await uploadVideo(servers[1].url, servers[1].accessToken, attributes)
100
572f8d3d 101 // Server 2 has transcoding enabled
3cd0734f 102 await waitJobs(servers)
11474c3c
C
103 })
104
975e6e0e 105 it('Should not have this unlisted video listed on server 1 and 2', async function () {
11474c3c
C
106 for (const server of servers) {
107 const res = await getVideosList(server.url)
108
109 expect(res.body.total).to.equal(0)
110 expect(res.body.data).to.have.lengthOf(0)
111 }
112 })
113
114 it('Should list my (unlisted) videos', async function () {
115 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1)
116
117 expect(res.body.total).to.equal(1)
118 expect(res.body.data).to.have.lengthOf(1)
119
120 unlistedVideoUUID = res.body.data[0].uuid
121 })
122
123 it('Should be able to get this unlisted video', async function () {
124 for (const server of servers) {
125 const res = await getVideo(server.url, unlistedVideoUUID)
126
127 expect(res.body.name).to.equal('unlisted video')
128 }
129 })
130
975e6e0e 131 it('Should update the private video to public on server 1', async function () {
572f8d3d 132 this.timeout(10000)
11474c3c
C
133
134 const attribute = {
135 name: 'super video public',
136 privacy: VideoPrivacy.PUBLIC
137 }
138
c49db162 139 now = Date.now()
11474c3c
C
140 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute)
141
3cd0734f 142 await waitJobs(servers)
11474c3c
C
143 })
144
9a27cdc2 145 it('Should have this new public video listed on server 1 and 2', async function () {
11474c3c
C
146 for (const server of servers) {
147 const res = await getVideosList(server.url)
148
149 expect(res.body.total).to.equal(1)
150 expect(res.body.data).to.have.lengthOf(1)
151 expect(res.body.data[0].name).to.equal('super video public')
c49db162 152 expect(new Date(res.body.data[0].publishedAt).getTime()).to.be.at.least(now)
11474c3c
C
153 }
154 })
155
7c3b7976
C
156 after(async function () {
157 await cleanupTests(servers)
11474c3c
C
158 })
159})