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