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'
10 flushAndRunMultipleServers,
13 getVideoChannelVideos,
16 setAccessTokensToServers,
18 } from '../../../../shared/extra-utils'
20 const expect = chai.expect
22 describe('Test follow constraints', function () {
23 let servers: ServerInfo[] = []
24 let video1UUID: string
25 let video2UUID: string
26 let userAccessToken: string
28 before(async function () {
31 servers = await flushAndRunMultipleServers(2)
33 // Get the access tokens
34 await setAccessTokensToServers(servers)
37 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' })
38 video1UUID = res.body.video.uuid
41 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' })
42 video2UUID = res.body.video.uuid
47 password: 'super_password'
49 await servers[0].usersCommand.create({ username: user.username, password: user.password })
50 userAccessToken = await servers[0].loginCommand.getAccessToken(user)
52 await doubleFollow(servers[0], servers[1])
55 describe('With a followed instance', function () {
57 describe('With an unlogged user', function () {
59 it('Should get the local video', async function () {
60 await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200)
63 it('Should get the remote video', async function () {
64 await getVideo(servers[0].url, video2UUID, HttpStatusCode.OK_200)
67 it('Should list local account videos', async function () {
68 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5)
70 expect(res.body.total).to.equal(1)
71 expect(res.body.data).to.have.lengthOf(1)
74 it('Should list remote account videos', async function () {
75 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5)
77 expect(res.body.total).to.equal(1)
78 expect(res.body.data).to.have.lengthOf(1)
81 it('Should list local channel videos', async function () {
82 const videoChannelName = 'root_channel@localhost:' + servers[0].port
83 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 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 videoChannelName = 'root_channel@localhost:' + servers[1].port
91 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
93 expect(res.body.total).to.equal(1)
94 expect(res.body.data).to.have.lengthOf(1)
98 describe('With a logged user', function () {
99 it('Should get the local video', async function () {
100 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200)
103 it('Should get the remote video', async function () {
104 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200)
107 it('Should list local account videos', async function () {
108 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
110 expect(res.body.total).to.equal(1)
111 expect(res.body.data).to.have.lengthOf(1)
114 it('Should list remote account videos', async function () {
115 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
117 expect(res.body.total).to.equal(1)
118 expect(res.body.data).to.have.lengthOf(1)
121 it('Should list local channel videos', async function () {
122 const videoChannelName = 'root_channel@localhost:' + servers[0].port
123 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
125 expect(res.body.total).to.equal(1)
126 expect(res.body.data).to.have.lengthOf(1)
129 it('Should list remote channel videos', async function () {
130 const videoChannelName = 'root_channel@localhost:' + servers[1].port
131 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
133 expect(res.body.total).to.equal(1)
134 expect(res.body.data).to.have.lengthOf(1)
139 describe('With a non followed instance', function () {
141 before(async function () {
144 await servers[0].followsCommand.unfollow({ target: servers[1] })
147 describe('With an unlogged user', function () {
149 it('Should get the local video', async function () {
150 await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200)
153 it('Should not get the remote video', async function () {
154 const res = await getVideo(servers[0].url, video2UUID, HttpStatusCode.FORBIDDEN_403)
156 const error = res.body as PeerTubeProblemDocument
158 const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
159 expect(error.type).to.equal(doc)
160 expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
162 expect(error.detail).to.equal('Cannot get this video regarding follow constraints')
163 expect(error.error).to.equal(error.detail)
165 expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403)
167 expect(error.originUrl).to.contains(servers[1].url)
170 it('Should list local account videos', async function () {
171 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5)
173 expect(res.body.total).to.equal(1)
174 expect(res.body.data).to.have.lengthOf(1)
177 it('Should not list remote account videos', async function () {
178 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5)
180 expect(res.body.total).to.equal(0)
181 expect(res.body.data).to.have.lengthOf(0)
184 it('Should list local channel videos', async function () {
185 const videoChannelName = 'root_channel@localhost:' + servers[0].port
186 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
188 expect(res.body.total).to.equal(1)
189 expect(res.body.data).to.have.lengthOf(1)
192 it('Should not list remote channel videos', async function () {
193 const videoChannelName = 'root_channel@localhost:' + servers[1].port
194 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
196 expect(res.body.total).to.equal(0)
197 expect(res.body.data).to.have.lengthOf(0)
201 describe('With a logged user', function () {
202 it('Should get the local video', async function () {
203 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200)
206 it('Should get the remote video', async function () {
207 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200)
210 it('Should list local account videos', async function () {
211 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
213 expect(res.body.total).to.equal(1)
214 expect(res.body.data).to.have.lengthOf(1)
217 it('Should list remote account videos', async function () {
218 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
220 expect(res.body.total).to.equal(1)
221 expect(res.body.data).to.have.lengthOf(1)
224 it('Should list local channel videos', async function () {
225 const videoChannelName = 'root_channel@localhost:' + servers[0].port
226 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
228 expect(res.body.total).to.equal(1)
229 expect(res.body.data).to.have.lengthOf(1)
232 it('Should list remote channel videos', async function () {
233 const videoChannelName = 'root_channel@localhost:' + servers[1].port
234 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
236 expect(res.body.total).to.equal(1)
237 expect(res.body.data).to.have.lengthOf(1)
242 after(async function () {
243 await cleanupTests(servers)