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'
20 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
21 import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
23 const expect = chai.expect
25 describe('Test follow constraints', function () {
26 let servers: ServerInfo[] = []
27 let video1UUID: string
28 let video2UUID: string
29 let userAccessToken: string
31 before(async function () {
34 servers = await flushAndRunMultipleServers(2)
36 // Get the access tokens
37 await setAccessTokensToServers(servers)
40 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' })
41 video1UUID = res.body.video.uuid
44 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' })
45 video2UUID = res.body.video.uuid
50 password: 'super_password'
52 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
53 userAccessToken = await userLogin(servers[0], user)
55 await doubleFollow(servers[0], servers[1])
58 describe('With a followed instance', function () {
60 describe('With an unlogged user', function () {
62 it('Should get the local video', async function () {
63 await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200)
66 it('Should get the remote video', async function () {
67 await getVideo(servers[0].url, video2UUID, HttpStatusCode.OK_200)
70 it('Should list local account videos', async function () {
71 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5)
73 expect(res.body.total).to.equal(1)
74 expect(res.body.data).to.have.lengthOf(1)
77 it('Should list remote account videos', async function () {
78 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5)
80 expect(res.body.total).to.equal(1)
81 expect(res.body.data).to.have.lengthOf(1)
84 it('Should list local channel videos', async function () {
85 const videoChannelName = 'root_channel@localhost:' + servers[0].port
86 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
88 expect(res.body.total).to.equal(1)
89 expect(res.body.data).to.have.lengthOf(1)
92 it('Should list remote channel videos', async function () {
93 const videoChannelName = 'root_channel@localhost:' + servers[1].port
94 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
96 expect(res.body.total).to.equal(1)
97 expect(res.body.data).to.have.lengthOf(1)
101 describe('With a logged user', function () {
102 it('Should get the local video', async function () {
103 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200)
106 it('Should get the remote video', async function () {
107 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200)
110 it('Should list local account videos', async function () {
111 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
113 expect(res.body.total).to.equal(1)
114 expect(res.body.data).to.have.lengthOf(1)
117 it('Should list remote account videos', async function () {
118 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
120 expect(res.body.total).to.equal(1)
121 expect(res.body.data).to.have.lengthOf(1)
124 it('Should list local channel videos', async function () {
125 const videoChannelName = 'root_channel@localhost:' + servers[0].port
126 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
128 expect(res.body.total).to.equal(1)
129 expect(res.body.data).to.have.lengthOf(1)
132 it('Should list remote channel videos', async function () {
133 const videoChannelName = 'root_channel@localhost:' + servers[1].port
134 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
136 expect(res.body.total).to.equal(1)
137 expect(res.body.data).to.have.lengthOf(1)
142 describe('With a non followed instance', function () {
144 before(async function () {
147 await unfollow(servers[0].url, servers[0].accessToken, servers[1])
150 describe('With an unlogged user', function () {
152 it('Should get the local video', async function () {
153 await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200)
156 it('Should not get the remote video', async function () {
157 const res = await getVideo(servers[0].url, video2UUID, HttpStatusCode.FORBIDDEN_403)
159 const error = res.body as PeerTubeProblemDocument
161 const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
162 expect(error.type).to.equal(doc)
163 expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
165 expect(error.detail).to.equal('Cannot get this video regarding follow constraints')
166 expect(error.error).to.equal(error.detail)
168 expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403)
170 expect(error.originUrl).to.contains(servers[1].url)
173 it('Should list local account videos', async function () {
174 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 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 account videos', async function () {
181 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5)
183 expect(res.body.total).to.equal(0)
184 expect(res.body.data).to.have.lengthOf(0)
187 it('Should list local channel videos', async function () {
188 const videoChannelName = 'root_channel@localhost:' + servers[0].port
189 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
191 expect(res.body.total).to.equal(1)
192 expect(res.body.data).to.have.lengthOf(1)
195 it('Should not list remote channel videos', async function () {
196 const videoChannelName = 'root_channel@localhost:' + servers[1].port
197 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
199 expect(res.body.total).to.equal(0)
200 expect(res.body.data).to.have.lengthOf(0)
204 describe('With a logged user', function () {
205 it('Should get the local video', async function () {
206 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200)
209 it('Should get the remote video', async function () {
210 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200)
213 it('Should list local account videos', async function () {
214 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
216 expect(res.body.total).to.equal(1)
217 expect(res.body.data).to.have.lengthOf(1)
220 it('Should list remote account videos', async function () {
221 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
223 expect(res.body.total).to.equal(1)
224 expect(res.body.data).to.have.lengthOf(1)
227 it('Should list local channel videos', async function () {
228 const videoChannelName = 'root_channel@localhost:' + servers[0].port
229 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
231 expect(res.body.total).to.equal(1)
232 expect(res.body.data).to.have.lengthOf(1)
235 it('Should list remote channel videos', async function () {
236 const videoChannelName = 'root_channel@localhost:' + servers[1].port
237 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
239 expect(res.body.total).to.equal(1)
240 expect(res.body.data).to.have.lengthOf(1)
245 after(async function () {
246 await cleanupTests(servers)