1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
6 import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
11 flushAndRunMultipleServers,
14 getVideoChannelVideos,
17 setAccessTokensToServers,
19 } from '../../../../shared/extra-utils'
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 servers[0].loginCommand.getAccessToken(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, HttpStatusCode.OK_200)
64 it('Should get the remote video', async function () {
65 await getVideo(servers[0].url, video2UUID, HttpStatusCode.OK_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, HttpStatusCode.OK_200)
104 it('Should get the remote video', async function () {
105 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_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 servers[0].followsCommand.unfollow({ target: 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, HttpStatusCode.OK_200)
154 it('Should not get the remote video', async function () {
155 const res = await getVideo(servers[0].url, video2UUID, HttpStatusCode.FORBIDDEN_403)
157 const error = res.body as PeerTubeProblemDocument
159 const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
160 expect(error.type).to.equal(doc)
161 expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
163 expect(error.detail).to.equal('Cannot get this video regarding follow constraints')
164 expect(error.error).to.equal(error.detail)
166 expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403)
168 expect(error.originUrl).to.contains(servers[1].url)
171 it('Should list local account videos', async function () {
172 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5)
174 expect(res.body.total).to.equal(1)
175 expect(res.body.data).to.have.lengthOf(1)
178 it('Should not list remote account videos', async function () {
179 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5)
181 expect(res.body.total).to.equal(0)
182 expect(res.body.data).to.have.lengthOf(0)
185 it('Should list local channel videos', async function () {
186 const videoChannelName = 'root_channel@localhost:' + servers[0].port
187 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
189 expect(res.body.total).to.equal(1)
190 expect(res.body.data).to.have.lengthOf(1)
193 it('Should not list remote channel videos', async function () {
194 const videoChannelName = 'root_channel@localhost:' + servers[1].port
195 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
197 expect(res.body.total).to.equal(0)
198 expect(res.body.data).to.have.lengthOf(0)
202 describe('With a logged user', function () {
203 it('Should get the local video', async function () {
204 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200)
207 it('Should get the remote video', async function () {
208 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200)
211 it('Should list local account videos', async function () {
212 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
214 expect(res.body.total).to.equal(1)
215 expect(res.body.data).to.have.lengthOf(1)
218 it('Should list remote account videos', async function () {
219 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
221 expect(res.body.total).to.equal(1)
222 expect(res.body.data).to.have.lengthOf(1)
225 it('Should list local channel videos', async function () {
226 const videoChannelName = 'root_channel@localhost:' + servers[0].port
227 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
229 expect(res.body.total).to.equal(1)
230 expect(res.body.data).to.have.lengthOf(1)
233 it('Should list remote channel videos', async function () {
234 const videoChannelName = 'root_channel@localhost:' + servers[1].port
235 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
237 expect(res.body.total).to.equal(1)
238 expect(res.body.data).to.have.lengthOf(1)
243 after(async function () {
244 await cleanupTests(servers)