Add public settings endpoint
[oweals/peertube.git] / server / tests / api / server / follow-constraints.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6   cleanupTests,
7   doubleFollow,
8   flushAndRunMultipleServers,
9   getAccountVideos,
10   getVideo,
11   getVideoChannelVideos,
12   getVideoWithToken,
13   ServerInfo,
14   setAccessTokensToServers,
15   uploadVideo
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'
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 () {
30     this.timeout(30000)
31
32     servers = await flushAndRunMultipleServers(2)
33
34     // Get the access tokens
35     await setAccessTokensToServers(servers)
36
37     {
38       const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video server 1' })
39       video1UUID = res.body.video.uuid
40     }
41     {
42       const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video server 2' })
43       video2UUID = res.body.video.uuid
44     }
45
46     const user = {
47       username: 'user1',
48       password: 'super_password'
49     }
50     await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
51     userAccessToken = await userLogin(servers[0], user)
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 () {
61         await getVideo(servers[0].url, video1UUID, 200)
62       })
63
64       it('Should get the remote video', async function () {
65         await getVideo(servers[0].url, video2UUID, 200)
66       })
67
68       it('Should list local account videos', async function () {
69         const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5)
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 () {
76         const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5)
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 () {
83         const videoChannelName = 'root_channel@localhost:' + servers[0].port
84         const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
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 () {
91         const videoChannelName = 'root_channel@localhost:' + servers[1].port
92         const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
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 () {
101         await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, 200)
102       })
103
104       it('Should get the remote video', async function () {
105         await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, 200)
106       })
107
108       it('Should list local account videos', async function () {
109         const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
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 () {
116         const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
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 () {
123         const videoChannelName = 'root_channel@localhost:' + servers[0].port
124         const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
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 () {
131         const videoChannelName = 'root_channel@localhost:' + servers[1].port
132         const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
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
145       await unfollow(servers[0].url, servers[0].accessToken, servers[1])
146     })
147
148     describe('With an unlogged user', function () {
149
150       it('Should get the local video', async function () {
151         await getVideo(servers[0].url, video1UUID, 200)
152       })
153
154       it('Should not get the remote video', async function () {
155         await getVideo(servers[0].url, video2UUID, 403)
156       })
157
158       it('Should list local account videos', async function () {
159         const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5)
160
161         expect(res.body.total).to.equal(1)
162         expect(res.body.data).to.have.lengthOf(1)
163       })
164
165       it('Should not list remote account videos', async function () {
166         const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5)
167
168         expect(res.body.total).to.equal(0)
169         expect(res.body.data).to.have.lengthOf(0)
170       })
171
172       it('Should list local channel videos', async function () {
173         const videoChannelName = 'root_channel@localhost:' + servers[0].port
174         const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
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 channel videos', async function () {
181         const videoChannelName = 'root_channel@localhost:' + servers[1].port
182         const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
183
184         expect(res.body.total).to.equal(0)
185         expect(res.body.data).to.have.lengthOf(0)
186       })
187     })
188
189     describe('With a logged user', function () {
190       it('Should get the local video', async function () {
191         await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, 200)
192       })
193
194       it('Should get the remote video', async function () {
195         await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, 200)
196       })
197
198       it('Should list local account videos', async function () {
199         const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
200
201         expect(res.body.total).to.equal(1)
202         expect(res.body.data).to.have.lengthOf(1)
203       })
204
205       it('Should list remote account videos', async function () {
206         const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
207
208         expect(res.body.total).to.equal(1)
209         expect(res.body.data).to.have.lengthOf(1)
210       })
211
212       it('Should list local channel videos', async function () {
213         const videoChannelName = 'root_channel@localhost:' + servers[0].port
214         const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
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 channel videos', async function () {
221         const videoChannelName = 'root_channel@localhost:' + servers[1].port
222         const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
223
224         expect(res.body.total).to.equal(1)
225         expect(res.body.data).to.have.lengthOf(1)
226       })
227     })
228   })
229
230   after(async function () {
231     await cleanupTests(servers)
232   })
233 })