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