]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-privacy.ts
Video channel API routes refractor
[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 {
975e6e0e 7 flushAndRunMultipleServers,
11474c3c 8 flushTests,
11474c3c 9 getVideosList,
975e6e0e
C
10 killallServers,
11 ServerInfo,
11474c3c 12 setAccessTokensToServers,
975e6e0e
C
13 uploadVideo,
14 wait
c5d31dba
C
15} from '../../utils/index'
16import { doubleFollow } from '../../utils/server/follows'
eec63bbc 17import { userLogin } from '../../utils/users/login'
c5d31dba
C
18import { createUser } from '../../utils/users/users'
19import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../utils/videos/videos'
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
572f8d3d 51 await wait(5000)
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 () {
76 const user = {
77 username: 'hello',
78 password: 'super password'
79 }
80 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
81
eec63bbc 82 const token = await userLogin(servers[0], user)
11474c3c
C
83 await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403)
84 })
85
86 it('Should be able to watch this video with the correct user', async function () {
87 await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID)
88 })
89
9a27cdc2 90 it('Should upload an unlisted video on server 2', async function () {
572f8d3d 91 this.timeout(30000)
11474c3c
C
92
93 const attributes = {
94 name: 'unlisted video',
95 privacy: VideoPrivacy.UNLISTED
96 }
97 await uploadVideo(servers[1].url, servers[1].accessToken, attributes)
98
572f8d3d
C
99 // Server 2 has transcoding enabled
100 await wait(10000)
11474c3c
C
101 })
102
975e6e0e 103 it('Should not have this unlisted video listed on server 1 and 2', async function () {
11474c3c
C
104 for (const server of servers) {
105 const res = await getVideosList(server.url)
106
107 expect(res.body.total).to.equal(0)
108 expect(res.body.data).to.have.lengthOf(0)
109 }
110 })
111
112 it('Should list my (unlisted) videos', async function () {
113 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1)
114
115 expect(res.body.total).to.equal(1)
116 expect(res.body.data).to.have.lengthOf(1)
117
118 unlistedVideoUUID = res.body.data[0].uuid
119 })
120
121 it('Should be able to get this unlisted video', async function () {
122 for (const server of servers) {
123 const res = await getVideo(server.url, unlistedVideoUUID)
124
125 expect(res.body.name).to.equal('unlisted video')
126 }
127 })
128
975e6e0e 129 it('Should update the private video to public on server 1', async function () {
572f8d3d 130 this.timeout(10000)
11474c3c
C
131
132 const attribute = {
133 name: 'super video public',
134 privacy: VideoPrivacy.PUBLIC
135 }
136
c49db162 137 now = Date.now()
11474c3c
C
138 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute)
139
572f8d3d 140 await wait(5000)
11474c3c
C
141 })
142
9a27cdc2 143 it('Should have this new public video listed on server 1 and 2', async function () {
11474c3c
C
144 for (const server of servers) {
145 const res = await getVideosList(server.url)
146
147 expect(res.body.total).to.equal(1)
148 expect(res.body.data).to.have.lengthOf(1)
149 expect(res.body.data[0].name).to.equal('super video public')
c49db162 150 expect(new Date(res.body.data[0].publishedAt).getTime()).to.be.at.least(now)
11474c3c
C
151 }
152 })
153
154 after(async function () {
155 killallServers(servers)
156
157 // Keep the logs if the test failed
158 if (this['ok']) {
159 await flushTests()
160 }
161 })
162})