1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
8 flushAndRunMultipleServers,
11 getVideoChannelVideos,
14 setAccessTokensToServers,
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:' + servers[0].port, 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:' + servers[1].port, 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 videoChannelName = 'root_channel@localhost:' + servers[0].port
84 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
86 expect(res.body.total).to.equal(1)
87 expect(res.body.data).to.have.lengthOf(1)
90 it('Should list remote channel videos', async function () {
91 const videoChannelName = 'root_channel@localhost:' + servers[1].port
92 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
94 expect(res.body.total).to.equal(1)
95 expect(res.body.data).to.have.lengthOf(1)
99 describe('With a logged user', function () {
100 it('Should get the local video', async function () {
101 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, 200)
104 it('Should get the remote video', async function () {
105 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, 200)
108 it('Should list local account videos', async function () {
109 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
111 expect(res.body.total).to.equal(1)
112 expect(res.body.data).to.have.lengthOf(1)
115 it('Should list remote account videos', async function () {
116 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
118 expect(res.body.total).to.equal(1)
119 expect(res.body.data).to.have.lengthOf(1)
122 it('Should list local channel videos', async function () {
123 const videoChannelName = 'root_channel@localhost:' + servers[0].port
124 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
126 expect(res.body.total).to.equal(1)
127 expect(res.body.data).to.have.lengthOf(1)
130 it('Should list remote channel videos', async function () {
131 const videoChannelName = 'root_channel@localhost:' + servers[1].port
132 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
134 expect(res.body.total).to.equal(1)
135 expect(res.body.data).to.have.lengthOf(1)
140 describe('With a non followed instance', function () {
142 before(async function () {
145 await unfollow(servers[0].url, servers[0].accessToken, servers[1])
148 describe('With an unlogged user', function () {
150 it('Should get the local video', async function () {
151 await getVideo(servers[0].url, video1UUID, 200)
154 it('Should not get the remote video', async function () {
155 await getVideo(servers[0].url, video2UUID, 403)
158 it('Should list local account videos', async function () {
159 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 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 account videos', async function () {
166 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5)
168 expect(res.body.total).to.equal(0)
169 expect(res.body.data).to.have.lengthOf(0)
172 it('Should list local channel videos', async function () {
173 const videoChannelName = 'root_channel@localhost:' + servers[0].port
174 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
176 expect(res.body.total).to.equal(1)
177 expect(res.body.data).to.have.lengthOf(1)
180 it('Should not list remote channel videos', async function () {
181 const videoChannelName = 'root_channel@localhost:' + servers[1].port
182 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
184 expect(res.body.total).to.equal(0)
185 expect(res.body.data).to.have.lengthOf(0)
189 describe('With a logged user', function () {
190 it('Should get the local video', async function () {
191 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, 200)
194 it('Should get the remote video', async function () {
195 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, 200)
198 it('Should list local account videos', async function () {
199 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
201 expect(res.body.total).to.equal(1)
202 expect(res.body.data).to.have.lengthOf(1)
205 it('Should list remote account videos', async function () {
206 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
208 expect(res.body.total).to.equal(1)
209 expect(res.body.data).to.have.lengthOf(1)
212 it('Should list local channel videos', async function () {
213 const videoChannelName = 'root_channel@localhost:' + servers[0].port
214 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
216 expect(res.body.total).to.equal(1)
217 expect(res.body.data).to.have.lengthOf(1)
220 it('Should list remote channel videos', async function () {
221 const videoChannelName = 'root_channel@localhost:' + servers[1].port
222 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
224 expect(res.body.total).to.equal(1)
225 expect(res.body.data).to.have.lengthOf(1)
230 after(async function () {
231 await cleanupTests(servers)