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