]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/follow-constraints.ts
Allow to specify transcoding and import jobs concurrency
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / follow-constraints.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6 cleanupTests,
7 doubleFollow,
8 flushAndRunMultipleServers,
9 getAccountVideos,
10 getVideo,
11 getVideoChannelVideos,
12 getVideoWithToken,
13 ServerInfo,
14 setAccessTokensToServers,
15 uploadVideo
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
22 const expect = chai.expect
23
24 describe('Test follow constraints', function () {
25 let servers: ServerInfo[] = []
26 let video1UUID: string
27 let video2UUID: string
28 let userAccessToken: string
29
30 before(async function () {
31 this.timeout(60000)
32
33 servers = await flushAndRunMultipleServers(2)
34
35 // Get the access tokens
36 await setAccessTokensToServers(servers)
37
38 {
39 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' })
40 video1UUID = res.body.video.uuid
41 }
42 {
43 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' })
44 video2UUID = res.body.video.uuid
45 }
46
47 const user = {
48 username: 'user1',
49 password: 'super_password'
50 }
51 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
52 userAccessToken = await userLogin(servers[0], user)
53
54 await doubleFollow(servers[0], servers[1])
55 })
56
57 describe('With a followed instance', function () {
58
59 describe('With an unlogged user', function () {
60
61 it('Should get the local video', async function () {
62 await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200)
63 })
64
65 it('Should get the remote video', async function () {
66 await getVideo(servers[0].url, video2UUID, HttpStatusCode.OK_200)
67 })
68
69 it('Should list local account videos', async function () {
70 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5)
71
72 expect(res.body.total).to.equal(1)
73 expect(res.body.data).to.have.lengthOf(1)
74 })
75
76 it('Should list remote account videos', async function () {
77 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5)
78
79 expect(res.body.total).to.equal(1)
80 expect(res.body.data).to.have.lengthOf(1)
81 })
82
83 it('Should list local channel videos', async function () {
84 const videoChannelName = 'root_channel@localhost:' + servers[0].port
85 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
86
87 expect(res.body.total).to.equal(1)
88 expect(res.body.data).to.have.lengthOf(1)
89 })
90
91 it('Should list remote channel videos', async function () {
92 const videoChannelName = 'root_channel@localhost:' + servers[1].port
93 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
94
95 expect(res.body.total).to.equal(1)
96 expect(res.body.data).to.have.lengthOf(1)
97 })
98 })
99
100 describe('With a logged user', function () {
101 it('Should get the local video', async function () {
102 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200)
103 })
104
105 it('Should get the remote video', async function () {
106 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200)
107 })
108
109 it('Should list local account videos', async function () {
110 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
111
112 expect(res.body.total).to.equal(1)
113 expect(res.body.data).to.have.lengthOf(1)
114 })
115
116 it('Should list remote account videos', async function () {
117 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
118
119 expect(res.body.total).to.equal(1)
120 expect(res.body.data).to.have.lengthOf(1)
121 })
122
123 it('Should list local channel videos', async function () {
124 const videoChannelName = 'root_channel@localhost:' + servers[0].port
125 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
126
127 expect(res.body.total).to.equal(1)
128 expect(res.body.data).to.have.lengthOf(1)
129 })
130
131 it('Should list remote channel videos', async function () {
132 const videoChannelName = 'root_channel@localhost:' + servers[1].port
133 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
134
135 expect(res.body.total).to.equal(1)
136 expect(res.body.data).to.have.lengthOf(1)
137 })
138 })
139 })
140
141 describe('With a non followed instance', function () {
142
143 before(async function () {
144 this.timeout(30000)
145
146 await unfollow(servers[0].url, servers[0].accessToken, servers[1])
147 })
148
149 describe('With an unlogged user', function () {
150
151 it('Should get the local video', async function () {
152 await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200)
153 })
154
155 it('Should not get the remote video', async function () {
156 await getVideo(servers[0].url, video2UUID, HttpStatusCode.FORBIDDEN_403)
157 })
158
159 it('Should list local account videos', async function () {
160 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5)
161
162 expect(res.body.total).to.equal(1)
163 expect(res.body.data).to.have.lengthOf(1)
164 })
165
166 it('Should not list remote account videos', async function () {
167 const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5)
168
169 expect(res.body.total).to.equal(0)
170 expect(res.body.data).to.have.lengthOf(0)
171 })
172
173 it('Should list local channel videos', async function () {
174 const videoChannelName = 'root_channel@localhost:' + servers[0].port
175 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
176
177 expect(res.body.total).to.equal(1)
178 expect(res.body.data).to.have.lengthOf(1)
179 })
180
181 it('Should not list remote channel videos', async function () {
182 const videoChannelName = 'root_channel@localhost:' + servers[1].port
183 const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
184
185 expect(res.body.total).to.equal(0)
186 expect(res.body.data).to.have.lengthOf(0)
187 })
188 })
189
190 describe('With a logged user', function () {
191 it('Should get the local video', async function () {
192 await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200)
193 })
194
195 it('Should get the remote video', async function () {
196 await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200)
197 })
198
199 it('Should list local account videos', async function () {
200 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
201
202 expect(res.body.total).to.equal(1)
203 expect(res.body.data).to.have.lengthOf(1)
204 })
205
206 it('Should list remote account videos', async function () {
207 const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
208
209 expect(res.body.total).to.equal(1)
210 expect(res.body.data).to.have.lengthOf(1)
211 })
212
213 it('Should list local channel videos', async function () {
214 const videoChannelName = 'root_channel@localhost:' + servers[0].port
215 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
216
217 expect(res.body.total).to.equal(1)
218 expect(res.body.data).to.have.lengthOf(1)
219 })
220
221 it('Should list remote channel videos', async function () {
222 const videoChannelName = 'root_channel@localhost:' + servers[1].port
223 const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
224
225 expect(res.body.total).to.equal(1)
226 expect(res.body.data).to.have.lengthOf(1)
227 })
228 })
229 })
230
231 after(async function () {
232 await cleanupTests(servers)
233 })
234 })