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