1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { doubleFollow, getAccountVideos, getVideo, getVideoChannelVideos, getVideoWithToken } from '../../utils'
6 import { flushAndRunMultipleServers, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils/index'
7 import { unfollow } from '../../utils/server/follows'
8 import { userLogin } from '../../utils/users/login'
9 import { createUser } from '../../utils/users/users'
11 const expect = chai.expect
13 describe('Test follow constraints', function () {
14 let servers: ServerInfo[] = []
15 let video1UUID: string
16 let video2UUID: string
17 let userAccessToken: string
19 before(async function () {
22 servers = await flushAndRunMultipleServers(2)
24 // Get the access tokens
25 await setAccessTokensToServers(servers)
28 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video server 1' })
29 video1UUID = res.body.video.uuid
32 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video server 2' })
33 video2UUID = res.body.video.uuid
38 password: 'super_password'
40 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
41 userAccessToken = await userLogin(servers[0], user)
43 await doubleFollow(servers[0], servers[1])
46 describe('With a followed instance', function () {
48 describe('With an unlogged user', function () {
50 it('Should get the local video', async function () {
51 await getVideo(servers[0].url, video1UUID, 200)
54 it('Should get the remote video', async function () {
55 await getVideo(servers[0].url, video2UUID, 200)
58 it('Should list local account videos', async function () {
59 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:9001', 0, 5)
61 expect(res.body.total).to.equal(1)
62 expect(res.body.data).to.have.lengthOf(1)
65 it('Should list remote account videos', async function () {
66 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:9002', 0, 5)
68 expect(res.body.total).to.equal(1)
69 expect(res.body.data).to.have.lengthOf(1)
72 it('Should list local channel videos', async function () {
73 const res = await getVideoChannelVideos(servers[0].url, undefined, 'root_channel@localhost:9001', 0, 5)
75 expect(res.body.total).to.equal(1)
76 expect(res.body.data).to.have.lengthOf(1)
79 it('Should list remote channel videos', async function () {
80 const res = await getVideoChannelVideos(servers[0].url, undefined, 'root_channel@localhost:9002', 0, 5)
82 expect(res.body.total).to.equal(1)
83 expect(res.body.data).to.have.lengthOf(1)
87 describe('With a logged user', function () {
88 it('Should get the local video', async function () {
89 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, 200)
92 it('Should get the remote video', async function () {
93 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, 200)
96 it('Should list local account videos', async function () {
97 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:9001', 0, 5)
99 expect(res.body.total).to.equal(1)
100 expect(res.body.data).to.have.lengthOf(1)
103 it('Should list remote account videos', async function () {
104 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:9002', 0, 5)
106 expect(res.body.total).to.equal(1)
107 expect(res.body.data).to.have.lengthOf(1)
110 it('Should list local channel videos', async function () {
111 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, 'root_channel@localhost:9001', 0, 5)
113 expect(res.body.total).to.equal(1)
114 expect(res.body.data).to.have.lengthOf(1)
117 it('Should list remote channel videos', async function () {
118 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, 'root_channel@localhost:9002', 0, 5)
120 expect(res.body.total).to.equal(1)
121 expect(res.body.data).to.have.lengthOf(1)
126 describe('With a non followed instance', function () {
128 before(async function () {
131 await unfollow(servers[0].url, servers[0].accessToken, servers[1])
134 describe('With an unlogged user', function () {
136 it('Should get the local video', async function () {
137 await getVideo(servers[0].url, video1UUID, 200)
140 it('Should not get the remote video', async function () {
141 await getVideo(servers[0].url, video2UUID, 403)
144 it('Should list local account videos', async function () {
145 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:9001', 0, 5)
147 expect(res.body.total).to.equal(1)
148 expect(res.body.data).to.have.lengthOf(1)
151 it('Should not list remote account videos', async function () {
152 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:9002', 0, 5)
154 expect(res.body.total).to.equal(0)
155 expect(res.body.data).to.have.lengthOf(0)
158 it('Should list local channel videos', async function () {
159 const res = await getVideoChannelVideos(servers[0].url, undefined, 'root_channel@localhost:9001', 0, 5)
161 expect(res.body.total).to.equal(1)
162 expect(res.body.data).to.have.lengthOf(1)
165 it('Should not list remote channel videos', async function () {
166 const res = await getVideoChannelVideos(servers[0].url, undefined, 'root_channel@localhost:9002', 0, 5)
168 expect(res.body.total).to.equal(0)
169 expect(res.body.data).to.have.lengthOf(0)
173 describe('With a logged user', function () {
174 it('Should get the local video', async function () {
175 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, 200)
178 it('Should get the remote video', async function () {
179 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, 200)
182 it('Should list local account videos', async function () {
183 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:9001', 0, 5)
185 expect(res.body.total).to.equal(1)
186 expect(res.body.data).to.have.lengthOf(1)
189 it('Should list remote account videos', async function () {
190 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:9002', 0, 5)
192 expect(res.body.total).to.equal(1)
193 expect(res.body.data).to.have.lengthOf(1)
196 it('Should list local channel videos', async function () {
197 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, 'root_channel@localhost:9001', 0, 5)
199 expect(res.body.total).to.equal(1)
200 expect(res.body.data).to.have.lengthOf(1)
203 it('Should list remote channel videos', async function () {
204 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, 'root_channel@localhost:9002', 0, 5)
206 expect(res.body.total).to.equal(1)
207 expect(res.body.data).to.have.lengthOf(1)
212 after(async function () {
213 killallServers(servers)