]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
8d427346 | 2 | |
8d427346 | 3 | import 'mocha' |
c3d29f69 C |
4 | import * as chai from 'chai' |
5 | import { HttpStatusCode } from '@shared/core-utils' | |
6 | import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' | |
35adc403 | 7 | import { |
7243f84d | 8 | cleanupTests, |
c3d29f69 | 9 | createUser, |
35adc403 | 10 | doubleFollow, |
7243f84d | 11 | flushAndRunMultipleServers, |
35adc403 | 12 | getAccountVideos, |
13 | getVideo, | |
14 | getVideoChannelVideos, | |
15 | getVideoWithToken, | |
35adc403 | 16 | ServerInfo, |
17 | setAccessTokensToServers, | |
c3d29f69 C |
18 | uploadVideo, |
19 | userLogin | |
94565d52 | 20 | } from '../../../../shared/extra-utils' |
8d427346 C |
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 () { | |
3ec535f7 | 31 | this.timeout(90000) |
8d427346 C |
32 | |
33 | servers = await flushAndRunMultipleServers(2) | |
34 | ||
35 | // Get the access tokens | |
36 | await setAccessTokensToServers(servers) | |
37 | ||
38 | { | |
a1587156 | 39 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) |
8d427346 C |
40 | video1UUID = res.body.video.uuid |
41 | } | |
42 | { | |
a1587156 | 43 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) |
8d427346 C |
44 | video2UUID = res.body.video.uuid |
45 | } | |
46 | ||
47 | const user = { | |
48 | username: 'user1', | |
49 | password: 'super_password' | |
50 | } | |
a1587156 | 51 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) |
8d427346 C |
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 () { | |
f2eb23cd | 62 | await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200) |
8d427346 C |
63 | }) |
64 | ||
65 | it('Should get the remote video', async function () { | |
f2eb23cd | 66 | await getVideo(servers[0].url, video2UUID, HttpStatusCode.OK_200) |
8d427346 C |
67 | }) |
68 | ||
69 | it('Should list local account videos', async function () { | |
7243f84d | 70 | const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5) |
8d427346 C |
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 () { | |
7243f84d | 77 | const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5) |
8d427346 C |
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 () { | |
7243f84d C |
84 | const videoChannelName = 'root_channel@localhost:' + servers[0].port |
85 | const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) | |
8d427346 C |
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 () { | |
7243f84d C |
92 | const videoChannelName = 'root_channel@localhost:' + servers[1].port |
93 | const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) | |
8d427346 C |
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 () { | |
f2eb23cd | 102 | await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200) |
8d427346 C |
103 | }) |
104 | ||
105 | it('Should get the remote video', async function () { | |
f2eb23cd | 106 | await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200) |
8d427346 C |
107 | }) |
108 | ||
109 | it('Should list local account videos', async function () { | |
7243f84d | 110 | const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5) |
8d427346 C |
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 () { | |
7243f84d | 117 | const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5) |
8d427346 C |
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 () { | |
7243f84d C |
124 | const videoChannelName = 'root_channel@localhost:' + servers[0].port |
125 | const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) | |
8d427346 C |
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 () { | |
7243f84d C |
132 | const videoChannelName = 'root_channel@localhost:' + servers[1].port |
133 | const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) | |
8d427346 C |
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 | ||
c3d29f69 | 146 | await servers[0].followsCommand.unfollow({ target: servers[1] }) |
8d427346 C |
147 | }) |
148 | ||
149 | describe('With an unlogged user', function () { | |
150 | ||
151 | it('Should get the local video', async function () { | |
f2eb23cd | 152 | await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200) |
8d427346 C |
153 | }) |
154 | ||
155 | it('Should not get the remote video', async function () { | |
e030bfb5 C |
156 | const res = await getVideo(servers[0].url, video2UUID, HttpStatusCode.FORBIDDEN_403) |
157 | ||
158 | const error = res.body as PeerTubeProblemDocument | |
159 | ||
160 | const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints' | |
161 | expect(error.type).to.equal(doc) | |
162 | expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS) | |
163 | ||
164 | expect(error.detail).to.equal('Cannot get this video regarding follow constraints') | |
165 | expect(error.error).to.equal(error.detail) | |
166 | ||
167 | expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403) | |
168 | ||
169 | expect(error.originUrl).to.contains(servers[1].url) | |
8d427346 C |
170 | }) |
171 | ||
172 | it('Should list local account videos', async function () { | |
7243f84d | 173 | const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5) |
8d427346 C |
174 | |
175 | expect(res.body.total).to.equal(1) | |
176 | expect(res.body.data).to.have.lengthOf(1) | |
177 | }) | |
178 | ||
179 | it('Should not list remote account videos', async function () { | |
7243f84d | 180 | const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5) |
8d427346 C |
181 | |
182 | expect(res.body.total).to.equal(0) | |
183 | expect(res.body.data).to.have.lengthOf(0) | |
184 | }) | |
185 | ||
186 | it('Should list local channel videos', async function () { | |
7243f84d C |
187 | const videoChannelName = 'root_channel@localhost:' + servers[0].port |
188 | const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) | |
8d427346 C |
189 | |
190 | expect(res.body.total).to.equal(1) | |
191 | expect(res.body.data).to.have.lengthOf(1) | |
192 | }) | |
193 | ||
194 | it('Should not list remote channel videos', async function () { | |
7243f84d C |
195 | const videoChannelName = 'root_channel@localhost:' + servers[1].port |
196 | const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) | |
8d427346 C |
197 | |
198 | expect(res.body.total).to.equal(0) | |
199 | expect(res.body.data).to.have.lengthOf(0) | |
200 | }) | |
201 | }) | |
202 | ||
203 | describe('With a logged user', function () { | |
204 | it('Should get the local video', async function () { | |
f2eb23cd | 205 | await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200) |
8d427346 C |
206 | }) |
207 | ||
208 | it('Should get the remote video', async function () { | |
f2eb23cd | 209 | await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200) |
8d427346 C |
210 | }) |
211 | ||
212 | it('Should list local account videos', async function () { | |
7243f84d | 213 | const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5) |
8d427346 C |
214 | |
215 | expect(res.body.total).to.equal(1) | |
216 | expect(res.body.data).to.have.lengthOf(1) | |
217 | }) | |
218 | ||
219 | it('Should list remote account videos', async function () { | |
7243f84d | 220 | const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5) |
8d427346 C |
221 | |
222 | expect(res.body.total).to.equal(1) | |
223 | expect(res.body.data).to.have.lengthOf(1) | |
224 | }) | |
225 | ||
226 | it('Should list local channel videos', async function () { | |
7243f84d C |
227 | const videoChannelName = 'root_channel@localhost:' + servers[0].port |
228 | const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) | |
8d427346 C |
229 | |
230 | expect(res.body.total).to.equal(1) | |
231 | expect(res.body.data).to.have.lengthOf(1) | |
232 | }) | |
233 | ||
234 | it('Should list remote channel videos', async function () { | |
7243f84d C |
235 | const videoChannelName = 'root_channel@localhost:' + servers[1].port |
236 | const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) | |
8d427346 C |
237 | |
238 | expect(res.body.total).to.equal(1) | |
239 | expect(res.body.data).to.have.lengthOf(1) | |
240 | }) | |
241 | }) | |
242 | }) | |
243 | ||
7c3b7976 C |
244 | after(async function () { |
245 | await cleanupTests(servers) | |
8d427346 C |
246 | }) |
247 | }) |