]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/follow-constraints.ts
Add runner server tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / follow-constraints.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
8d427346 2
86347717 3import { expect } from 'chai'
4c7e60bc 4import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
11ae7e29
C
5import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 PeerTubeServer,
10 setAccessTokensToServers,
11 waitJobs
12} from '@shared/server-commands'
8d427346 13
8d427346 14describe('Test follow constraints', function () {
254d3579 15 let servers: PeerTubeServer[] = []
8d427346
C
16 let video1UUID: string
17 let video2UUID: string
d23dd9fb 18 let userToken: string
8d427346
C
19
20 before(async function () {
81d02aac 21 this.timeout(240000)
8d427346 22
254d3579 23 servers = await createMultipleServers(2)
8d427346
C
24
25 // Get the access tokens
26 await setAccessTokensToServers(servers)
27
28 {
89d241a7 29 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
d23dd9fb 30 video1UUID = uuid
8d427346
C
31 }
32 {
89d241a7 33 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
d23dd9fb 34 video2UUID = uuid
8d427346
C
35 }
36
37 const user = {
38 username: 'user1',
39 password: 'super_password'
40 }
89d241a7
C
41 await servers[0].users.create({ username: user.username, password: user.password })
42 userToken = await servers[0].login.getAccessToken(user)
8d427346
C
43
44 await doubleFollow(servers[0], servers[1])
45 })
46
47 describe('With a followed instance', function () {
48
49 describe('With an unlogged user', function () {
50
51 it('Should get the local video', async function () {
89d241a7 52 await servers[0].videos.get({ id: video1UUID })
8d427346
C
53 })
54
55 it('Should get the remote video', async function () {
89d241a7 56 await servers[0].videos.get({ id: video2UUID })
8d427346
C
57 })
58
59 it('Should list local account videos', async function () {
2732eeff 60 const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@' + servers[0].host })
8d427346 61
d23dd9fb
C
62 expect(total).to.equal(1)
63 expect(data).to.have.lengthOf(1)
8d427346
C
64 })
65
66 it('Should list remote account videos', async function () {
2732eeff 67 const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@' + servers[1].host })
8d427346 68
d23dd9fb
C
69 expect(total).to.equal(1)
70 expect(data).to.have.lengthOf(1)
8d427346
C
71 })
72
73 it('Should list local channel videos', async function () {
2732eeff 74 const handle = 'root_channel@' + servers[0].host
c0e8b12e 75 const { total, data } = await servers[0].videos.listByChannel({ handle })
8d427346 76
d23dd9fb
C
77 expect(total).to.equal(1)
78 expect(data).to.have.lengthOf(1)
8d427346
C
79 })
80
81 it('Should list remote channel videos', async function () {
2732eeff 82 const handle = 'root_channel@' + servers[1].host
c0e8b12e 83 const { total, data } = await servers[0].videos.listByChannel({ handle })
8d427346 84
d23dd9fb
C
85 expect(total).to.equal(1)
86 expect(data).to.have.lengthOf(1)
8d427346
C
87 })
88 })
89
90 describe('With a logged user', function () {
91 it('Should get the local video', async function () {
89d241a7 92 await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
8d427346
C
93 })
94
95 it('Should get the remote video', async function () {
89d241a7 96 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
8d427346
C
97 })
98
99 it('Should list local account videos', async function () {
2732eeff 100 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@' + servers[0].host })
8d427346 101
d23dd9fb
C
102 expect(total).to.equal(1)
103 expect(data).to.have.lengthOf(1)
8d427346
C
104 })
105
106 it('Should list remote account videos', async function () {
2732eeff 107 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@' + servers[1].host })
8d427346 108
d23dd9fb
C
109 expect(total).to.equal(1)
110 expect(data).to.have.lengthOf(1)
8d427346
C
111 })
112
113 it('Should list local channel videos', async function () {
2732eeff 114 const handle = 'root_channel@' + servers[0].host
c0e8b12e 115 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
8d427346 116
d23dd9fb
C
117 expect(total).to.equal(1)
118 expect(data).to.have.lengthOf(1)
8d427346
C
119 })
120
121 it('Should list remote channel videos', async function () {
2732eeff 122 const handle = 'root_channel@' + servers[1].host
c0e8b12e 123 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
8d427346 124
d23dd9fb
C
125 expect(total).to.equal(1)
126 expect(data).to.have.lengthOf(1)
8d427346
C
127 })
128 })
129 })
130
131 describe('With a non followed instance', function () {
132
133 before(async function () {
134 this.timeout(30000)
135
89d241a7 136 await servers[0].follows.unfollow({ target: servers[1] })
8d427346
C
137 })
138
139 describe('With an unlogged user', function () {
140
141 it('Should get the local video', async function () {
89d241a7 142 await servers[0].videos.get({ id: video1UUID })
8d427346
C
143 })
144
145 it('Should not get the remote video', async function () {
89d241a7 146 const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
d23dd9fb 147 const error = body as unknown as PeerTubeProblemDocument
e030bfb5 148
d102de1b 149 const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
e030bfb5
C
150 expect(error.type).to.equal(doc)
151 expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
152
153 expect(error.detail).to.equal('Cannot get this video regarding follow constraints')
154 expect(error.error).to.equal(error.detail)
155
156 expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403)
157
158 expect(error.originUrl).to.contains(servers[1].url)
8d427346
C
159 })
160
161 it('Should list local account videos', async function () {
89d241a7 162 const { total, data } = await servers[0].videos.listByAccount({
4c7e60bc 163 token: null,
2732eeff 164 handle: 'root@' + servers[0].host
d23dd9fb 165 })
8d427346 166
d23dd9fb
C
167 expect(total).to.equal(1)
168 expect(data).to.have.lengthOf(1)
8d427346
C
169 })
170
171 it('Should not list remote account videos', async function () {
89d241a7 172 const { total, data } = await servers[0].videos.listByAccount({
4c7e60bc 173 token: null,
2732eeff 174 handle: 'root@' + servers[1].host
d23dd9fb 175 })
8d427346 176
d23dd9fb
C
177 expect(total).to.equal(0)
178 expect(data).to.have.lengthOf(0)
8d427346
C
179 })
180
181 it('Should list local channel videos', async function () {
2732eeff 182 const handle = 'root_channel@' + servers[0].host
4c7e60bc 183 const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
8d427346 184
d23dd9fb
C
185 expect(total).to.equal(1)
186 expect(data).to.have.lengthOf(1)
8d427346
C
187 })
188
189 it('Should not list remote channel videos', async function () {
2732eeff 190 const handle = 'root_channel@' + servers[1].host
4c7e60bc 191 const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
8d427346 192
d23dd9fb
C
193 expect(total).to.equal(0)
194 expect(data).to.have.lengthOf(0)
8d427346
C
195 })
196 })
197
198 describe('With a logged user', function () {
11ae7e29 199
8d427346 200 it('Should get the local video', async function () {
89d241a7 201 await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
8d427346
C
202 })
203
204 it('Should get the remote video', async function () {
89d241a7 205 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
8d427346
C
206 })
207
208 it('Should list local account videos', async function () {
2732eeff 209 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@' + servers[0].host })
8d427346 210
d23dd9fb
C
211 expect(total).to.equal(1)
212 expect(data).to.have.lengthOf(1)
8d427346
C
213 })
214
215 it('Should list remote account videos', async function () {
2732eeff 216 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@' + servers[1].host })
8d427346 217
d23dd9fb
C
218 expect(total).to.equal(1)
219 expect(data).to.have.lengthOf(1)
8d427346
C
220 })
221
222 it('Should list local channel videos', async function () {
2732eeff 223 const handle = 'root_channel@' + servers[0].host
c0e8b12e 224 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
8d427346 225
d23dd9fb
C
226 expect(total).to.equal(1)
227 expect(data).to.have.lengthOf(1)
8d427346
C
228 })
229
230 it('Should list remote channel videos', async function () {
2732eeff 231 const handle = 'root_channel@' + servers[1].host
c0e8b12e 232 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
8d427346 233
d23dd9fb
C
234 expect(total).to.equal(1)
235 expect(data).to.have.lengthOf(1)
8d427346
C
236 })
237 })
238 })
239
11ae7e29
C
240 describe('When following a remote account', function () {
241
242 before(async function () {
243 this.timeout(60000)
244
245 await servers[0].follows.follow({ handles: [ 'root@' + servers[1].host ] })
246 await waitJobs(servers)
247 })
248
249 it('Should get the remote video with an unlogged user', async function () {
250 await servers[0].videos.get({ id: video2UUID })
251 })
252
253 it('Should get the remote video with a logged in user', async function () {
254 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
255 })
256 })
257
258 describe('When unfollowing a remote account', function () {
259
260 before(async function () {
261 this.timeout(60000)
262
263 await servers[0].follows.unfollow({ target: 'root@' + servers[1].host })
264 await waitJobs(servers)
265 })
266
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 })
269
270 const error = body as unknown as PeerTubeProblemDocument
271 expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
272 })
273
274 it('Should get the remote video with a logged in user', async function () {
275 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
276 })
277 })
278
279 describe('When following a remote channel', function () {
280
281 before(async function () {
282 this.timeout(60000)
283
284 await servers[0].follows.follow({ handles: [ 'root_channel@' + servers[1].host ] })
285 await waitJobs(servers)
286 })
287
288 it('Should get the remote video with an unlogged user', async function () {
289 await servers[0].videos.get({ id: video2UUID })
290 })
291
292 it('Should get the remote video with a logged in user', async function () {
293 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
294 })
295 })
296
297 describe('When unfollowing a remote channel', function () {
298
299 before(async function () {
300 this.timeout(60000)
301
302 await servers[0].follows.unfollow({ target: 'root_channel@' + servers[1].host })
303 await waitJobs(servers)
304 })
305
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 })
308
309 const error = body as unknown as PeerTubeProblemDocument
310 expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
311 })
312
313 it('Should get the remote video with a logged in user', async function () {
314 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
315 })
316 })
317
7c3b7976
C
318 after(async function () {
319 await cleanupTests(servers)
8d427346
C
320 })
321})