1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
7 flushAndRunMultipleServers,
11 setAccessTokensToServers,
13 } from '../../utils/index'
14 import { doubleFollow } from '../../utils/server/follows'
15 import { userLogin } from '../../utils/users/login'
16 import { createUser } from '../../utils/users/users'
17 import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../utils/videos/videos'
18 import { waitJobs } from '../../utils/server/jobs'
20 const expect = chai.expect
22 describe('Test video privacy', function () {
23 let servers: ServerInfo[] = []
24 let privateVideoId: number
25 let privateVideoUUID: string
26 let unlistedVideoUUID: string
29 before(async function () {
33 servers = await flushAndRunMultipleServers(2)
35 // Get the access tokens
36 await setAccessTokensToServers(servers)
38 // Server 1 and server 2 follow each other
39 await doubleFollow(servers[0], servers[1])
42 it('Should upload a private video on server 1', async function () {
46 privacy: VideoPrivacy.PRIVATE
48 await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
50 await waitJobs(servers)
53 it('Should not have this private video on server 2', async function () {
54 const res = await getVideosList(servers[1].url)
56 expect(res.body.total).to.equal(0)
57 expect(res.body.data).to.have.lengthOf(0)
60 it('Should list my (private) videos', async function () {
61 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 1)
63 expect(res.body.total).to.equal(1)
64 expect(res.body.data).to.have.lengthOf(1)
66 privateVideoId = res.body.data[0].id
67 privateVideoUUID = res.body.data[0].uuid
70 it('Should not be able to watch this video with non authenticated user', async function () {
71 await getVideo(servers[0].url, privateVideoUUID, 401)
74 it('Should not be able to watch this private video with another user', async function () {
79 password: 'super password'
81 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
83 const token = await userLogin(servers[0], user)
84 await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403)
87 it('Should be able to watch this video with the correct user', async function () {
88 await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID)
91 it('Should upload an unlisted video on server 2', async function () {
95 name: 'unlisted video',
96 privacy: VideoPrivacy.UNLISTED
98 await uploadVideo(servers[1].url, servers[1].accessToken, attributes)
100 // Server 2 has transcoding enabled
101 await waitJobs(servers)
104 it('Should not have this unlisted video listed on server 1 and 2', async function () {
105 for (const server of servers) {
106 const res = await getVideosList(server.url)
108 expect(res.body.total).to.equal(0)
109 expect(res.body.data).to.have.lengthOf(0)
113 it('Should list my (unlisted) videos', async function () {
114 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1)
116 expect(res.body.total).to.equal(1)
117 expect(res.body.data).to.have.lengthOf(1)
119 unlistedVideoUUID = res.body.data[0].uuid
122 it('Should be able to get this unlisted video', async function () {
123 for (const server of servers) {
124 const res = await getVideo(server.url, unlistedVideoUUID)
126 expect(res.body.name).to.equal('unlisted video')
130 it('Should update the private video to public on server 1', async function () {
134 name: 'super video public',
135 privacy: VideoPrivacy.PUBLIC
139 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute)
141 await waitJobs(servers)
144 it('Should have this new public video listed on server 1 and 2', async function () {
145 for (const server of servers) {
146 const res = await getVideosList(server.url)
148 expect(res.body.total).to.equal(1)
149 expect(res.body.data).to.have.lengthOf(1)
150 expect(res.body.data[0].name).to.equal('super video public')
151 expect(new Date(res.body.data[0].publishedAt).getTime()).to.be.at.least(now)
155 after(async function () {
156 killallServers(servers)