1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
10 setAccessTokensToServers,
12 } from '@shared/server-commands'
14 describe('Test follow constraints', function () {
15 let servers: PeerTubeServer[] = []
16 let video1UUID: string
17 let video2UUID: string
20 before(async function () {
23 servers = await createMultipleServers(2)
25 // Get the access tokens
26 await setAccessTokensToServers(servers)
29 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
33 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
39 password: 'super_password'
41 await servers[0].users.create({ username: user.username, password: user.password })
42 userToken = await servers[0].login.getAccessToken(user)
44 await doubleFollow(servers[0], servers[1])
47 describe('With a followed instance', function () {
49 describe('With an unlogged user', function () {
51 it('Should get the local video', async function () {
52 await servers[0].videos.get({ id: video1UUID })
55 it('Should get the remote video', async function () {
56 await servers[0].videos.get({ id: video2UUID })
59 it('Should list local account videos', async function () {
60 const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@' + servers[0].host })
62 expect(total).to.equal(1)
63 expect(data).to.have.lengthOf(1)
66 it('Should list remote account videos', async function () {
67 const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@' + servers[1].host })
69 expect(total).to.equal(1)
70 expect(data).to.have.lengthOf(1)
73 it('Should list local channel videos', async function () {
74 const handle = 'root_channel@' + servers[0].host
75 const { total, data } = await servers[0].videos.listByChannel({ handle })
77 expect(total).to.equal(1)
78 expect(data).to.have.lengthOf(1)
81 it('Should list remote channel videos', async function () {
82 const handle = 'root_channel@' + servers[1].host
83 const { total, data } = await servers[0].videos.listByChannel({ handle })
85 expect(total).to.equal(1)
86 expect(data).to.have.lengthOf(1)
90 describe('With a logged user', function () {
91 it('Should get the local video', async function () {
92 await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
95 it('Should get the remote video', async function () {
96 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
99 it('Should list local account videos', async function () {
100 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@' + servers[0].host })
102 expect(total).to.equal(1)
103 expect(data).to.have.lengthOf(1)
106 it('Should list remote account videos', async function () {
107 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@' + servers[1].host })
109 expect(total).to.equal(1)
110 expect(data).to.have.lengthOf(1)
113 it('Should list local channel videos', async function () {
114 const handle = 'root_channel@' + servers[0].host
115 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
117 expect(total).to.equal(1)
118 expect(data).to.have.lengthOf(1)
121 it('Should list remote channel videos', async function () {
122 const handle = 'root_channel@' + servers[1].host
123 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
125 expect(total).to.equal(1)
126 expect(data).to.have.lengthOf(1)
131 describe('With a non followed instance', function () {
133 before(async function () {
136 await servers[0].follows.unfollow({ target: servers[1] })
139 describe('With an unlogged user', function () {
141 it('Should get the local video', async function () {
142 await servers[0].videos.get({ id: video1UUID })
145 it('Should not get the remote video', async function () {
146 const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
147 const error = body as unknown as PeerTubeProblemDocument
149 const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
150 expect(error.type).to.equal(doc)
151 expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
153 expect(error.detail).to.equal('Cannot get this video regarding follow constraints')
154 expect(error.error).to.equal(error.detail)
156 expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403)
158 expect(error.originUrl).to.contains(servers[1].url)
161 it('Should list local account videos', async function () {
162 const { total, data } = await servers[0].videos.listByAccount({
164 handle: 'root@' + servers[0].host
167 expect(total).to.equal(1)
168 expect(data).to.have.lengthOf(1)
171 it('Should not list remote account videos', async function () {
172 const { total, data } = await servers[0].videos.listByAccount({
174 handle: 'root@' + servers[1].host
177 expect(total).to.equal(0)
178 expect(data).to.have.lengthOf(0)
181 it('Should list local channel videos', async function () {
182 const handle = 'root_channel@' + servers[0].host
183 const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
185 expect(total).to.equal(1)
186 expect(data).to.have.lengthOf(1)
189 it('Should not list remote channel videos', async function () {
190 const handle = 'root_channel@' + servers[1].host
191 const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
193 expect(total).to.equal(0)
194 expect(data).to.have.lengthOf(0)
198 describe('With a logged user', function () {
200 it('Should get the local video', async function () {
201 await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
204 it('Should get the remote video', async function () {
205 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
208 it('Should list local account videos', async function () {
209 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@' + servers[0].host })
211 expect(total).to.equal(1)
212 expect(data).to.have.lengthOf(1)
215 it('Should list remote account videos', async function () {
216 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@' + servers[1].host })
218 expect(total).to.equal(1)
219 expect(data).to.have.lengthOf(1)
222 it('Should list local channel videos', async function () {
223 const handle = 'root_channel@' + servers[0].host
224 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
226 expect(total).to.equal(1)
227 expect(data).to.have.lengthOf(1)
230 it('Should list remote channel videos', async function () {
231 const handle = 'root_channel@' + servers[1].host
232 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
234 expect(total).to.equal(1)
235 expect(data).to.have.lengthOf(1)
240 describe('When following a remote account', function () {
242 before(async function () {
245 await servers[0].follows.follow({ handles: [ 'root@' + servers[1].host ] })
246 await waitJobs(servers)
249 it('Should get the remote video with an unlogged user', async function () {
250 await servers[0].videos.get({ id: video2UUID })
253 it('Should get the remote video with a logged in user', async function () {
254 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
258 describe('When unfollowing a remote account', function () {
260 before(async function () {
263 await servers[0].follows.unfollow({ target: 'root@' + servers[1].host })
264 await waitJobs(servers)
267 it('Should not get the remote video with an unlogged user', async function () {
268 const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
270 const error = body as unknown as PeerTubeProblemDocument
271 expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
274 it('Should get the remote video with a logged in user', async function () {
275 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
279 describe('When following a remote channel', function () {
281 before(async function () {
284 await servers[0].follows.follow({ handles: [ 'root_channel@' + servers[1].host ] })
285 await waitJobs(servers)
288 it('Should get the remote video with an unlogged user', async function () {
289 await servers[0].videos.get({ id: video2UUID })
292 it('Should get the remote video with a logged in user', async function () {
293 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
297 describe('When unfollowing a remote channel', function () {
299 before(async function () {
302 await servers[0].follows.unfollow({ target: 'root_channel@' + servers[1].host })
303 await waitJobs(servers)
306 it('Should not get the remote video with an unlogged user', async function () {
307 const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
309 const error = body as unknown as PeerTubeProblemDocument
310 expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
313 it('Should get the remote video with a logged in user', async function () {
314 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
318 after(async function () {
319 await cleanupTests(servers)