]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
8d427346 | 2 | |
8d427346 | 3 | import 'mocha' |
c3d29f69 | 4 | import * as chai from 'chai' |
bf54587a | 5 | import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' |
4c7e60bc | 6 | import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' |
8d427346 C |
7 | |
8 | const expect = chai.expect | |
9 | ||
10 | describe('Test follow constraints', function () { | |
254d3579 | 11 | let servers: PeerTubeServer[] = [] |
8d427346 C |
12 | let video1UUID: string |
13 | let video2UUID: string | |
d23dd9fb | 14 | let userToken: string |
8d427346 C |
15 | |
16 | before(async function () { | |
81d02aac | 17 | this.timeout(240000) |
8d427346 | 18 | |
254d3579 | 19 | servers = await createMultipleServers(2) |
8d427346 C |
20 | |
21 | // Get the access tokens | |
22 | await setAccessTokensToServers(servers) | |
23 | ||
24 | { | |
89d241a7 | 25 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } }) |
d23dd9fb | 26 | video1UUID = uuid |
8d427346 C |
27 | } |
28 | { | |
89d241a7 | 29 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } }) |
d23dd9fb | 30 | video2UUID = uuid |
8d427346 C |
31 | } |
32 | ||
33 | const user = { | |
34 | username: 'user1', | |
35 | password: 'super_password' | |
36 | } | |
89d241a7 C |
37 | await servers[0].users.create({ username: user.username, password: user.password }) |
38 | userToken = await servers[0].login.getAccessToken(user) | |
8d427346 C |
39 | |
40 | await doubleFollow(servers[0], servers[1]) | |
41 | }) | |
42 | ||
43 | describe('With a followed instance', function () { | |
44 | ||
45 | describe('With an unlogged user', function () { | |
46 | ||
47 | it('Should get the local video', async function () { | |
89d241a7 | 48 | await servers[0].videos.get({ id: video1UUID }) |
8d427346 C |
49 | }) |
50 | ||
51 | it('Should get the remote video', async function () { | |
89d241a7 | 52 | await servers[0].videos.get({ id: video2UUID }) |
8d427346 C |
53 | }) |
54 | ||
55 | it('Should list local account videos', async function () { | |
c0e8b12e | 56 | const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[0].port }) |
8d427346 | 57 | |
d23dd9fb C |
58 | expect(total).to.equal(1) |
59 | expect(data).to.have.lengthOf(1) | |
8d427346 C |
60 | }) |
61 | ||
62 | it('Should list remote account videos', async function () { | |
c0e8b12e | 63 | const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[1].port }) |
8d427346 | 64 | |
d23dd9fb C |
65 | expect(total).to.equal(1) |
66 | expect(data).to.have.lengthOf(1) | |
8d427346 C |
67 | }) |
68 | ||
69 | it('Should list local channel videos', async function () { | |
c0e8b12e C |
70 | const handle = 'root_channel@localhost:' + servers[0].port |
71 | const { total, data } = await servers[0].videos.listByChannel({ handle }) | |
8d427346 | 72 | |
d23dd9fb C |
73 | expect(total).to.equal(1) |
74 | expect(data).to.have.lengthOf(1) | |
8d427346 C |
75 | }) |
76 | ||
77 | it('Should list remote channel videos', async function () { | |
c0e8b12e C |
78 | const handle = 'root_channel@localhost:' + servers[1].port |
79 | const { total, data } = await servers[0].videos.listByChannel({ handle }) | |
8d427346 | 80 | |
d23dd9fb C |
81 | expect(total).to.equal(1) |
82 | expect(data).to.have.lengthOf(1) | |
8d427346 C |
83 | }) |
84 | }) | |
85 | ||
86 | describe('With a logged user', function () { | |
87 | it('Should get the local video', async function () { | |
89d241a7 | 88 | await servers[0].videos.getWithToken({ token: userToken, id: video1UUID }) |
8d427346 C |
89 | }) |
90 | ||
91 | it('Should get the remote video', async function () { | |
89d241a7 | 92 | await servers[0].videos.getWithToken({ token: userToken, id: video2UUID }) |
8d427346 C |
93 | }) |
94 | ||
95 | it('Should list local account videos', async function () { | |
c0e8b12e | 96 | const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port }) |
8d427346 | 97 | |
d23dd9fb C |
98 | expect(total).to.equal(1) |
99 | expect(data).to.have.lengthOf(1) | |
8d427346 C |
100 | }) |
101 | ||
102 | it('Should list remote account videos', async function () { | |
c0e8b12e | 103 | const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port }) |
8d427346 | 104 | |
d23dd9fb C |
105 | expect(total).to.equal(1) |
106 | expect(data).to.have.lengthOf(1) | |
8d427346 C |
107 | }) |
108 | ||
109 | it('Should list local channel videos', async function () { | |
c0e8b12e C |
110 | const handle = 'root_channel@localhost:' + servers[0].port |
111 | const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle }) | |
8d427346 | 112 | |
d23dd9fb C |
113 | expect(total).to.equal(1) |
114 | expect(data).to.have.lengthOf(1) | |
8d427346 C |
115 | }) |
116 | ||
117 | it('Should list remote channel videos', async function () { | |
c0e8b12e C |
118 | const handle = 'root_channel@localhost:' + servers[1].port |
119 | const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle }) | |
8d427346 | 120 | |
d23dd9fb C |
121 | expect(total).to.equal(1) |
122 | expect(data).to.have.lengthOf(1) | |
8d427346 C |
123 | }) |
124 | }) | |
125 | }) | |
126 | ||
127 | describe('With a non followed instance', function () { | |
128 | ||
129 | before(async function () { | |
130 | this.timeout(30000) | |
131 | ||
89d241a7 | 132 | await servers[0].follows.unfollow({ target: servers[1] }) |
8d427346 C |
133 | }) |
134 | ||
135 | describe('With an unlogged user', function () { | |
136 | ||
137 | it('Should get the local video', async function () { | |
89d241a7 | 138 | await servers[0].videos.get({ id: video1UUID }) |
8d427346 C |
139 | }) |
140 | ||
141 | it('Should not get the remote video', async function () { | |
89d241a7 | 142 | const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
d23dd9fb | 143 | const error = body as unknown as PeerTubeProblemDocument |
e030bfb5 C |
144 | |
145 | const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints' | |
146 | expect(error.type).to.equal(doc) | |
147 | expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS) | |
148 | ||
149 | expect(error.detail).to.equal('Cannot get this video regarding follow constraints') | |
150 | expect(error.error).to.equal(error.detail) | |
151 | ||
152 | expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403) | |
153 | ||
154 | expect(error.originUrl).to.contains(servers[1].url) | |
8d427346 C |
155 | }) |
156 | ||
157 | it('Should list local account videos', async function () { | |
89d241a7 | 158 | const { total, data } = await servers[0].videos.listByAccount({ |
4c7e60bc | 159 | token: null, |
c0e8b12e | 160 | handle: 'root@localhost:' + servers[0].port |
d23dd9fb | 161 | }) |
8d427346 | 162 | |
d23dd9fb C |
163 | expect(total).to.equal(1) |
164 | expect(data).to.have.lengthOf(1) | |
8d427346 C |
165 | }) |
166 | ||
167 | it('Should not list remote account videos', async function () { | |
89d241a7 | 168 | const { total, data } = await servers[0].videos.listByAccount({ |
4c7e60bc | 169 | token: null, |
c0e8b12e | 170 | handle: 'root@localhost:' + servers[1].port |
d23dd9fb | 171 | }) |
8d427346 | 172 | |
d23dd9fb C |
173 | expect(total).to.equal(0) |
174 | expect(data).to.have.lengthOf(0) | |
8d427346 C |
175 | }) |
176 | ||
177 | it('Should list local channel videos', async function () { | |
c0e8b12e | 178 | const handle = 'root_channel@localhost:' + servers[0].port |
4c7e60bc | 179 | const { total, data } = await servers[0].videos.listByChannel({ token: null, handle }) |
8d427346 | 180 | |
d23dd9fb C |
181 | expect(total).to.equal(1) |
182 | expect(data).to.have.lengthOf(1) | |
8d427346 C |
183 | }) |
184 | ||
185 | it('Should not list remote channel videos', async function () { | |
c0e8b12e | 186 | const handle = 'root_channel@localhost:' + servers[1].port |
4c7e60bc | 187 | const { total, data } = await servers[0].videos.listByChannel({ token: null, handle }) |
8d427346 | 188 | |
d23dd9fb C |
189 | expect(total).to.equal(0) |
190 | expect(data).to.have.lengthOf(0) | |
8d427346 C |
191 | }) |
192 | }) | |
193 | ||
194 | describe('With a logged user', function () { | |
195 | it('Should get the local video', async function () { | |
89d241a7 | 196 | await servers[0].videos.getWithToken({ token: userToken, id: video1UUID }) |
8d427346 C |
197 | }) |
198 | ||
199 | it('Should get the remote video', async function () { | |
89d241a7 | 200 | await servers[0].videos.getWithToken({ token: userToken, id: video2UUID }) |
8d427346 C |
201 | }) |
202 | ||
203 | it('Should list local account videos', async function () { | |
c0e8b12e | 204 | const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port }) |
8d427346 | 205 | |
d23dd9fb C |
206 | expect(total).to.equal(1) |
207 | expect(data).to.have.lengthOf(1) | |
8d427346 C |
208 | }) |
209 | ||
210 | it('Should list remote account videos', async function () { | |
c0e8b12e | 211 | const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port }) |
8d427346 | 212 | |
d23dd9fb C |
213 | expect(total).to.equal(1) |
214 | expect(data).to.have.lengthOf(1) | |
8d427346 C |
215 | }) |
216 | ||
217 | it('Should list local channel videos', async function () { | |
c0e8b12e C |
218 | const handle = 'root_channel@localhost:' + servers[0].port |
219 | const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle }) | |
8d427346 | 220 | |
d23dd9fb C |
221 | expect(total).to.equal(1) |
222 | expect(data).to.have.lengthOf(1) | |
8d427346 C |
223 | }) |
224 | ||
225 | it('Should list remote channel videos', async function () { | |
c0e8b12e C |
226 | const handle = 'root_channel@localhost:' + servers[1].port |
227 | const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle }) | |
8d427346 | 228 | |
d23dd9fb C |
229 | expect(total).to.equal(1) |
230 | expect(data).to.have.lengthOf(1) | |
8d427346 C |
231 | }) |
232 | }) | |
233 | }) | |
234 | ||
7c3b7976 C |
235 | after(async function () { |
236 | await cleanupTests(servers) | |
8d427346 C |
237 | }) |
238 | }) |