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