]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
8d427346 C |
2 | |
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
35adc403 | 5 | import { |
7243f84d | 6 | cleanupTests, |
35adc403 | 7 | doubleFollow, |
7243f84d | 8 | flushAndRunMultipleServers, |
35adc403 | 9 | getAccountVideos, |
10 | getVideo, | |
11 | getVideoChannelVideos, | |
12 | getVideoWithToken, | |
35adc403 | 13 | ServerInfo, |
14 | setAccessTokensToServers, | |
7243f84d | 15 | uploadVideo |
94565d52 C |
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' | |
f2eb23cd | 20 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
e030bfb5 | 21 | import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' |
8d427346 C |
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 () { | |
3ec535f7 | 32 | this.timeout(90000) |
8d427346 C |
33 | |
34 | servers = await flushAndRunMultipleServers(2) | |
35 | ||
36 | // Get the access tokens | |
37 | await setAccessTokensToServers(servers) | |
38 | ||
39 | { | |
a1587156 | 40 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) |
8d427346 C |
41 | video1UUID = res.body.video.uuid |
42 | } | |
43 | { | |
a1587156 | 44 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) |
8d427346 C |
45 | video2UUID = res.body.video.uuid |
46 | } | |
47 | ||
48 | const user = { | |
49 | username: 'user1', | |
50 | password: 'super_password' | |
51 | } | |
a1587156 | 52 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) |
8d427346 C |
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 () { | |
f2eb23cd | 63 | await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200) |
8d427346 C |
64 | }) |
65 | ||
66 | it('Should get the remote video', async function () { | |
f2eb23cd | 67 | await getVideo(servers[0].url, video2UUID, HttpStatusCode.OK_200) |
8d427346 C |
68 | }) |
69 | ||
70 | it('Should list local account videos', async function () { | |
7243f84d | 71 | const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5) |
8d427346 C |
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 () { | |
7243f84d | 78 | const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5) |
8d427346 C |
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 () { | |
7243f84d C |
85 | const videoChannelName = 'root_channel@localhost:' + servers[0].port |
86 | const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) | |
8d427346 C |
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 () { | |
7243f84d C |
93 | const videoChannelName = 'root_channel@localhost:' + servers[1].port |
94 | const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) | |
8d427346 C |
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 () { | |
f2eb23cd | 103 | await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200) |
8d427346 C |
104 | }) |
105 | ||
106 | it('Should get the remote video', async function () { | |
f2eb23cd | 107 | await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200) |
8d427346 C |
108 | }) |
109 | ||
110 | it('Should list local account videos', async function () { | |
7243f84d | 111 | const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5) |
8d427346 C |
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 () { | |
7243f84d | 118 | const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5) |
8d427346 C |
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 () { | |
7243f84d C |
125 | const videoChannelName = 'root_channel@localhost:' + servers[0].port |
126 | const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) | |
8d427346 C |
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 () { | |
7243f84d C |
133 | const videoChannelName = 'root_channel@localhost:' + servers[1].port |
134 | const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) | |
8d427346 C |
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 () { | |
f2eb23cd | 153 | await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200) |
8d427346 C |
154 | }) |
155 | ||
156 | it('Should not get the remote video', async function () { | |
e030bfb5 C |
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) | |
8d427346 C |
171 | }) |
172 | ||
173 | it('Should list local account videos', async function () { | |
7243f84d | 174 | const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5) |
8d427346 C |
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 () { | |
7243f84d | 181 | const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5) |
8d427346 C |
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 () { | |
7243f84d C |
188 | const videoChannelName = 'root_channel@localhost:' + servers[0].port |
189 | const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) | |
8d427346 C |
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 () { | |
7243f84d C |
196 | const videoChannelName = 'root_channel@localhost:' + servers[1].port |
197 | const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) | |
8d427346 C |
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 () { | |
f2eb23cd | 206 | await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200) |
8d427346 C |
207 | }) |
208 | ||
209 | it('Should get the remote video', async function () { | |
f2eb23cd | 210 | await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200) |
8d427346 C |
211 | }) |
212 | ||
213 | it('Should list local account videos', async function () { | |
7243f84d | 214 | const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5) |
8d427346 C |
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 () { | |
7243f84d | 221 | const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5) |
8d427346 C |
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 () { | |
7243f84d C |
228 | const videoChannelName = 'root_channel@localhost:' + servers[0].port |
229 | const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) | |
8d427346 C |
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 () { | |
7243f84d C |
236 | const videoChannelName = 'root_channel@localhost:' + servers[1].port |
237 | const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) | |
8d427346 C |
238 | |
239 | expect(res.body.total).to.equal(1) | |
240 | expect(res.body.data).to.have.lengthOf(1) | |
241 | }) | |
242 | }) | |
243 | }) | |
244 | ||
7c3b7976 C |
245 | after(async function () { |
246 | await cleanupTests(servers) | |
8d427346 C |
247 | }) |
248 | }) |