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