1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
5 import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
7 describe('Test follow constraints', function () {
8 let servers: PeerTubeServer[] = []
10 let video2UUID: string
13 before(async function () {
16 servers = await createMultipleServers(2)
18 // Get the access tokens
19 await setAccessTokensToServers(servers)
22 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
26 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
32 password: 'super_password'
34 await servers[0].users.create({ username: user.username, password: user.password })
35 userToken = await servers[0].login.getAccessToken(user)
37 await doubleFollow(servers[0], servers[1])
40 describe('With a followed instance', function () {
42 describe('With an unlogged user', function () {
44 it('Should get the local video', async function () {
45 await servers[0].videos.get({ id: video1UUID })
48 it('Should get the remote video', async function () {
49 await servers[0].videos.get({ id: video2UUID })
52 it('Should list local account videos', async function () {
53 const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[0].port })
55 expect(total).to.equal(1)
56 expect(data).to.have.lengthOf(1)
59 it('Should list remote account videos', async function () {
60 const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[1].port })
62 expect(total).to.equal(1)
63 expect(data).to.have.lengthOf(1)
66 it('Should list local channel videos', async function () {
67 const handle = 'root_channel@localhost:' + servers[0].port
68 const { total, data } = await servers[0].videos.listByChannel({ handle })
70 expect(total).to.equal(1)
71 expect(data).to.have.lengthOf(1)
74 it('Should list remote channel videos', async function () {
75 const handle = 'root_channel@localhost:' + servers[1].port
76 const { total, data } = await servers[0].videos.listByChannel({ handle })
78 expect(total).to.equal(1)
79 expect(data).to.have.lengthOf(1)
83 describe('With a logged user', function () {
84 it('Should get the local video', async function () {
85 await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
88 it('Should get the remote video', async function () {
89 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
92 it('Should list local account videos', async function () {
93 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port })
95 expect(total).to.equal(1)
96 expect(data).to.have.lengthOf(1)
99 it('Should list remote account videos', async function () {
100 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port })
102 expect(total).to.equal(1)
103 expect(data).to.have.lengthOf(1)
106 it('Should list local channel videos', async function () {
107 const handle = 'root_channel@localhost:' + servers[0].port
108 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
110 expect(total).to.equal(1)
111 expect(data).to.have.lengthOf(1)
114 it('Should list remote channel videos', async function () {
115 const handle = 'root_channel@localhost:' + servers[1].port
116 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
118 expect(total).to.equal(1)
119 expect(data).to.have.lengthOf(1)
124 describe('With a non followed instance', function () {
126 before(async function () {
129 await servers[0].follows.unfollow({ target: servers[1] })
132 describe('With an unlogged user', function () {
134 it('Should get the local video', async function () {
135 await servers[0].videos.get({ id: video1UUID })
138 it('Should not get the remote video', async function () {
139 const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
140 const error = body as unknown as PeerTubeProblemDocument
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)
146 expect(error.detail).to.equal('Cannot get this video regarding follow constraints')
147 expect(error.error).to.equal(error.detail)
149 expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403)
151 expect(error.originUrl).to.contains(servers[1].url)
154 it('Should list local account videos', async function () {
155 const { total, data } = await servers[0].videos.listByAccount({
157 handle: 'root@localhost:' + servers[0].port
160 expect(total).to.equal(1)
161 expect(data).to.have.lengthOf(1)
164 it('Should not list remote account videos', async function () {
165 const { total, data } = await servers[0].videos.listByAccount({
167 handle: 'root@localhost:' + servers[1].port
170 expect(total).to.equal(0)
171 expect(data).to.have.lengthOf(0)
174 it('Should list local channel videos', async function () {
175 const handle = 'root_channel@localhost:' + servers[0].port
176 const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
178 expect(total).to.equal(1)
179 expect(data).to.have.lengthOf(1)
182 it('Should not list remote channel videos', async function () {
183 const handle = 'root_channel@localhost:' + servers[1].port
184 const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
186 expect(total).to.equal(0)
187 expect(data).to.have.lengthOf(0)
191 describe('With a logged user', function () {
192 it('Should get the local video', async function () {
193 await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
196 it('Should get the remote video', async function () {
197 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
200 it('Should list local account videos', async function () {
201 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port })
203 expect(total).to.equal(1)
204 expect(data).to.have.lengthOf(1)
207 it('Should list remote account videos', async function () {
208 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port })
210 expect(total).to.equal(1)
211 expect(data).to.have.lengthOf(1)
214 it('Should list local channel videos', async function () {
215 const handle = 'root_channel@localhost:' + servers[0].port
216 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
218 expect(total).to.equal(1)
219 expect(data).to.have.lengthOf(1)
222 it('Should list remote channel videos', async function () {
223 const handle = 'root_channel@localhost:' + servers[1].port
224 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
226 expect(total).to.equal(1)
227 expect(data).to.have.lengthOf(1)
232 after(async function () {
233 await cleanupTests(servers)