1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
11 flushAndRunMultipleServers,
14 setAccessTokensToServers,
15 uploadVideo, cleanupTests
16 } from '../../../../shared/extra-utils'
17 import { unfollow } from '../../../../shared/extra-utils/server/follows'
18 import { userLogin } from '../../../../shared/extra-utils/users/login'
19 import { createUser } from '../../../../shared/extra-utils/users/users'
21 const expect = chai.expect
23 describe('Test follow constraints', function () {
24 let servers: ServerInfo[] = []
25 let video1UUID: string
26 let video2UUID: string
27 let userAccessToken: string
29 before(async function () {
32 servers = await flushAndRunMultipleServers(2)
34 // Get the access tokens
35 await setAccessTokensToServers(servers)
38 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video server 1' })
39 video1UUID = res.body.video.uuid
42 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video server 2' })
43 video2UUID = res.body.video.uuid
48 password: 'super_password'
50 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
51 userAccessToken = await userLogin(servers[0], user)
53 await doubleFollow(servers[0], servers[1])
56 describe('With a followed instance', function () {
58 describe('With an unlogged user', function () {
60 it('Should get the local video', async function () {
61 await getVideo(servers[0].url, video1UUID, 200)
64 it('Should get the remote video', async function () {
65 await getVideo(servers[0].url, video2UUID, 200)
68 it('Should list local account videos', async function () {
69 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:9001', 0, 5)
71 expect(res.body.total).to.equal(1)
72 expect(res.body.data).to.have.lengthOf(1)
75 it('Should list remote account videos', async function () {
76 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:9002', 0, 5)
78 expect(res.body.total).to.equal(1)
79 expect(res.body.data).to.have.lengthOf(1)
82 it('Should list local channel videos', async function () {
83 const res = await getVideoChannelVideos(servers[0].url, undefined, 'root_channel@localhost:9001', 0, 5)
85 expect(res.body.total).to.equal(1)
86 expect(res.body.data).to.have.lengthOf(1)
89 it('Should list remote channel videos', async function () {
90 const res = await getVideoChannelVideos(servers[0].url, undefined, 'root_channel@localhost:9002', 0, 5)
92 expect(res.body.total).to.equal(1)
93 expect(res.body.data).to.have.lengthOf(1)
97 describe('With a logged user', function () {
98 it('Should get the local video', async function () {
99 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, 200)
102 it('Should get the remote video', async function () {
103 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, 200)
106 it('Should list local account videos', async function () {
107 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:9001', 0, 5)
109 expect(res.body.total).to.equal(1)
110 expect(res.body.data).to.have.lengthOf(1)
113 it('Should list remote account videos', async function () {
114 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:9002', 0, 5)
116 expect(res.body.total).to.equal(1)
117 expect(res.body.data).to.have.lengthOf(1)
120 it('Should list local channel videos', async function () {
121 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, 'root_channel@localhost:9001', 0, 5)
123 expect(res.body.total).to.equal(1)
124 expect(res.body.data).to.have.lengthOf(1)
127 it('Should list remote channel videos', async function () {
128 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, 'root_channel@localhost:9002', 0, 5)
130 expect(res.body.total).to.equal(1)
131 expect(res.body.data).to.have.lengthOf(1)
136 describe('With a non followed instance', function () {
138 before(async function () {
141 await unfollow(servers[0].url, servers[0].accessToken, servers[1])
144 describe('With an unlogged user', function () {
146 it('Should get the local video', async function () {
147 await getVideo(servers[0].url, video1UUID, 200)
150 it('Should not get the remote video', async function () {
151 await getVideo(servers[0].url, video2UUID, 403)
154 it('Should list local account videos', async function () {
155 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:9001', 0, 5)
157 expect(res.body.total).to.equal(1)
158 expect(res.body.data).to.have.lengthOf(1)
161 it('Should not list remote account videos', async function () {
162 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:9002', 0, 5)
164 expect(res.body.total).to.equal(0)
165 expect(res.body.data).to.have.lengthOf(0)
168 it('Should list local channel videos', async function () {
169 const res = await getVideoChannelVideos(servers[0].url, undefined, 'root_channel@localhost:9001', 0, 5)
171 expect(res.body.total).to.equal(1)
172 expect(res.body.data).to.have.lengthOf(1)
175 it('Should not list remote channel videos', async function () {
176 const res = await getVideoChannelVideos(servers[0].url, undefined, 'root_channel@localhost:9002', 0, 5)
178 expect(res.body.total).to.equal(0)
179 expect(res.body.data).to.have.lengthOf(0)
183 describe('With a logged user', function () {
184 it('Should get the local video', async function () {
185 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, 200)
188 it('Should get the remote video', async function () {
189 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, 200)
192 it('Should list local account videos', async function () {
193 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:9001', 0, 5)
195 expect(res.body.total).to.equal(1)
196 expect(res.body.data).to.have.lengthOf(1)
199 it('Should list remote account videos', async function () {
200 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:9002', 0, 5)
202 expect(res.body.total).to.equal(1)
203 expect(res.body.data).to.have.lengthOf(1)
206 it('Should list local channel videos', async function () {
207 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, 'root_channel@localhost:9001', 0, 5)
209 expect(res.body.total).to.equal(1)
210 expect(res.body.data).to.have.lengthOf(1)
213 it('Should list remote channel videos', async function () {
214 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, 'root_channel@localhost:9002', 0, 5)
216 expect(res.body.total).to.equal(1)
217 expect(res.body.data).to.have.lengthOf(1)
222 after(async function () {
223 await cleanupTests(servers)