]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/tests/api/server/follow-constraints.ts
Merge branch 'release/4.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / follow-constraints.ts
... / ...
CommitLineData
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
5import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
6
7describe('Test follow constraints', function () {
8 let servers: PeerTubeServer[] = []
9 let video1UUID: string
10 let video2UUID: string
11 let userToken: string
12
13 before(async function () {
14 this.timeout(240000)
15
16 servers = await createMultipleServers(2)
17
18 // Get the access tokens
19 await setAccessTokensToServers(servers)
20
21 {
22 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
23 video1UUID = uuid
24 }
25 {
26 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
27 video2UUID = uuid
28 }
29
30 const user = {
31 username: 'user1',
32 password: 'super_password'
33 }
34 await servers[0].users.create({ username: user.username, password: user.password })
35 userToken = await servers[0].login.getAccessToken(user)
36
37 await doubleFollow(servers[0], servers[1])
38 })
39
40 describe('With a followed instance', function () {
41
42 describe('With an unlogged user', function () {
43
44 it('Should get the local video', async function () {
45 await servers[0].videos.get({ id: video1UUID })
46 })
47
48 it('Should get the remote video', async function () {
49 await servers[0].videos.get({ id: video2UUID })
50 })
51
52 it('Should list local account videos', async function () {
53 const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[0].port })
54
55 expect(total).to.equal(1)
56 expect(data).to.have.lengthOf(1)
57 })
58
59 it('Should list remote account videos', async function () {
60 const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[1].port })
61
62 expect(total).to.equal(1)
63 expect(data).to.have.lengthOf(1)
64 })
65
66 it('Should list local channel videos', async function () {
67 const handle = 'root_channel@localhost:' + servers[0].port
68 const { total, data } = await servers[0].videos.listByChannel({ handle })
69
70 expect(total).to.equal(1)
71 expect(data).to.have.lengthOf(1)
72 })
73
74 it('Should list remote channel videos', async function () {
75 const handle = 'root_channel@localhost:' + servers[1].port
76 const { total, data } = await servers[0].videos.listByChannel({ handle })
77
78 expect(total).to.equal(1)
79 expect(data).to.have.lengthOf(1)
80 })
81 })
82
83 describe('With a logged user', function () {
84 it('Should get the local video', async function () {
85 await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
86 })
87
88 it('Should get the remote video', async function () {
89 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
90 })
91
92 it('Should list local account videos', async function () {
93 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port })
94
95 expect(total).to.equal(1)
96 expect(data).to.have.lengthOf(1)
97 })
98
99 it('Should list remote account videos', async function () {
100 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port })
101
102 expect(total).to.equal(1)
103 expect(data).to.have.lengthOf(1)
104 })
105
106 it('Should list local channel videos', async function () {
107 const handle = 'root_channel@localhost:' + servers[0].port
108 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
109
110 expect(total).to.equal(1)
111 expect(data).to.have.lengthOf(1)
112 })
113
114 it('Should list remote channel videos', async function () {
115 const handle = 'root_channel@localhost:' + servers[1].port
116 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
117
118 expect(total).to.equal(1)
119 expect(data).to.have.lengthOf(1)
120 })
121 })
122 })
123
124 describe('With a non followed instance', function () {
125
126 before(async function () {
127 this.timeout(30000)
128
129 await servers[0].follows.unfollow({ target: servers[1] })
130 })
131
132 describe('With an unlogged user', function () {
133
134 it('Should get the local video', async function () {
135 await servers[0].videos.get({ id: video1UUID })
136 })
137
138 it('Should not get the remote video', async function () {
139 const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
140 const error = body as unknown as PeerTubeProblemDocument
141
142 const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
143 expect(error.type).to.equal(doc)
144 expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
145
146 expect(error.detail).to.equal('Cannot get this video regarding follow constraints')
147 expect(error.error).to.equal(error.detail)
148
149 expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403)
150
151 expect(error.originUrl).to.contains(servers[1].url)
152 })
153
154 it('Should list local account videos', async function () {
155 const { total, data } = await servers[0].videos.listByAccount({
156 token: null,
157 handle: 'root@localhost:' + servers[0].port
158 })
159
160 expect(total).to.equal(1)
161 expect(data).to.have.lengthOf(1)
162 })
163
164 it('Should not list remote account videos', async function () {
165 const { total, data } = await servers[0].videos.listByAccount({
166 token: null,
167 handle: 'root@localhost:' + servers[1].port
168 })
169
170 expect(total).to.equal(0)
171 expect(data).to.have.lengthOf(0)
172 })
173
174 it('Should list local channel videos', async function () {
175 const handle = 'root_channel@localhost:' + servers[0].port
176 const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
177
178 expect(total).to.equal(1)
179 expect(data).to.have.lengthOf(1)
180 })
181
182 it('Should not list remote channel videos', async function () {
183 const handle = 'root_channel@localhost:' + servers[1].port
184 const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
185
186 expect(total).to.equal(0)
187 expect(data).to.have.lengthOf(0)
188 })
189 })
190
191 describe('With a logged user', function () {
192 it('Should get the local video', async function () {
193 await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
194 })
195
196 it('Should get the remote video', async function () {
197 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
198 })
199
200 it('Should list local account videos', async function () {
201 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port })
202
203 expect(total).to.equal(1)
204 expect(data).to.have.lengthOf(1)
205 })
206
207 it('Should list remote account videos', async function () {
208 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port })
209
210 expect(total).to.equal(1)
211 expect(data).to.have.lengthOf(1)
212 })
213
214 it('Should list local channel videos', async function () {
215 const handle = 'root_channel@localhost:' + servers[0].port
216 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
217
218 expect(total).to.equal(1)
219 expect(data).to.have.lengthOf(1)
220 })
221
222 it('Should list remote channel videos', async function () {
223 const handle = 'root_channel@localhost:' + servers[1].port
224 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
225
226 expect(total).to.equal(1)
227 expect(data).to.have.lengthOf(1)
228 })
229 })
230 })
231
232 after(async function () {
233 await cleanupTests(servers)
234 })
235})