]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/search/search-activitypub-video-channels.ts
Shared utils -> extra-utils
[github/Chocobozzz/PeerTube.git] / server / tests / api / search / search-activitypub-video-channels.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6 addVideoChannel,
7 createUser,
8 deleteVideoChannel,
9 flushAndRunMultipleServers,
10 flushTests,
11 getVideoChannelsList, getVideoChannelVideos,
12 killallServers,
13 ServerInfo,
14 setAccessTokensToServers,
15 updateMyUser, updateVideo,
16 updateVideoChannel,
17 uploadVideo,
18 userLogin,
19 wait
20 } from '../../../../shared/extra-utils'
21 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
22 import { VideoChannel } from '../../../../shared/models/videos'
23 import { searchVideoChannel } from '../../../../shared/extra-utils/search/video-channels'
24
25 const expect = chai.expect
26
27 describe('Test a ActivityPub video channels search', function () {
28 let servers: ServerInfo[]
29 let userServer2Token: string
30 let videoServer2UUID: string
31 let channelIdServer2: number
32
33 before(async function () {
34 this.timeout(120000)
35
36 await flushTests()
37
38 servers = await flushAndRunMultipleServers(2)
39
40 await setAccessTokensToServers(servers)
41
42 {
43 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'user1_server1', password: 'password' })
44 const channel = {
45 name: 'channel1_server1',
46 displayName: 'Channel 1 server 1'
47 }
48 await addVideoChannel(servers[0].url, servers[0].accessToken, channel)
49 }
50
51 {
52 const user = { username: 'user1_server2', password: 'password' }
53 await createUser({ url: servers[ 1 ].url, accessToken: servers[ 1 ].accessToken, username: user.username, password: user.password })
54 userServer2Token = await userLogin(servers[1], user)
55
56 const channel = {
57 name: 'channel1_server2',
58 displayName: 'Channel 1 server 2'
59 }
60 const resChannel = await addVideoChannel(servers[1].url, userServer2Token, channel)
61 channelIdServer2 = resChannel.body.videoChannel.id
62
63 const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 })
64 videoServer2UUID = res.body.video.uuid
65 }
66
67 await waitJobs(servers)
68 })
69
70 it('Should not find a remote video channel', async function () {
71 {
72 const search = 'http://localhost:9002/video-channels/channel1_server3'
73 const res = await searchVideoChannel(servers[ 0 ].url, search, servers[ 0 ].accessToken)
74
75 expect(res.body.total).to.equal(0)
76 expect(res.body.data).to.be.an('array')
77 expect(res.body.data).to.have.lengthOf(0)
78 }
79
80 {
81 // Without token
82 const search = 'http://localhost:9002/video-channels/channel1_server2'
83 const res = await searchVideoChannel(servers[0].url, search)
84
85 expect(res.body.total).to.equal(0)
86 expect(res.body.data).to.be.an('array')
87 expect(res.body.data).to.have.lengthOf(0)
88 }
89 })
90
91 it('Should search a local video channel', async function () {
92 const searches = [
93 'http://localhost:9001/video-channels/channel1_server1',
94 'channel1_server1@localhost:9001'
95 ]
96
97 for (const search of searches) {
98 const res = await searchVideoChannel(servers[ 0 ].url, search)
99
100 expect(res.body.total).to.equal(1)
101 expect(res.body.data).to.be.an('array')
102 expect(res.body.data).to.have.lengthOf(1)
103 expect(res.body.data[ 0 ].name).to.equal('channel1_server1')
104 expect(res.body.data[ 0 ].displayName).to.equal('Channel 1 server 1')
105 }
106 })
107
108 it('Should search a remote video channel with URL or handle', async function () {
109 const searches = [
110 'http://localhost:9002/video-channels/channel1_server2',
111 'channel1_server2@localhost:9002'
112 ]
113
114 for (const search of searches) {
115 const res = await searchVideoChannel(servers[ 0 ].url, search, servers[ 0 ].accessToken)
116
117 expect(res.body.total).to.equal(1)
118 expect(res.body.data).to.be.an('array')
119 expect(res.body.data).to.have.lengthOf(1)
120 expect(res.body.data[ 0 ].name).to.equal('channel1_server2')
121 expect(res.body.data[ 0 ].displayName).to.equal('Channel 1 server 2')
122 }
123 })
124
125 it('Should not list this remote video channel', async function () {
126 const res = await getVideoChannelsList(servers[0].url, 0, 5)
127 expect(res.body.total).to.equal(3)
128 expect(res.body.data).to.have.lengthOf(3)
129 expect(res.body.data[0].name).to.equal('channel1_server1')
130 expect(res.body.data[1].name).to.equal('user1_server1_channel')
131 expect(res.body.data[2].name).to.equal('root_channel')
132 })
133
134 it('Should list video channel videos of server 2 without token', async function () {
135 this.timeout(30000)
136
137 await waitJobs(servers)
138
139 const res = await getVideoChannelVideos(servers[0].url, null, 'channel1_server2@localhost:9002', 0, 5)
140 expect(res.body.total).to.equal(0)
141 expect(res.body.data).to.have.lengthOf(0)
142 })
143
144 it('Should list video channel videos of server 2 with token', async function () {
145 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:9002', 0, 5)
146
147 expect(res.body.total).to.equal(1)
148 expect(res.body.data[0].name).to.equal('video 1 server 2')
149 })
150
151 it('Should update video channel of server 2, and refresh it on server 1', async function () {
152 this.timeout(60000)
153
154 await updateVideoChannel(servers[1].url, userServer2Token, 'channel1_server2', { displayName: 'channel updated' })
155 await updateMyUser({ url: servers[1].url, accessToken: userServer2Token, displayName: 'user updated' })
156
157 await waitJobs(servers)
158 // Expire video channel
159 await wait(10000)
160
161 const search = 'http://localhost:9002/video-channels/channel1_server2'
162 const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken)
163 expect(res.body.total).to.equal(1)
164 expect(res.body.data).to.have.lengthOf(1)
165
166 const videoChannel: VideoChannel = res.body.data[0]
167 expect(videoChannel.displayName).to.equal('channel updated')
168
169 // We don't return the owner account for now
170 // expect(videoChannel.ownerAccount.displayName).to.equal('user updated')
171 })
172
173 it('Should update and add a video on server 2, and update it on server 1 after a search', async function () {
174 this.timeout(60000)
175
176 await updateVideo(servers[1].url, userServer2Token, videoServer2UUID, { name: 'video 1 updated' })
177 await uploadVideo(servers[1].url, userServer2Token, { name: 'video 2 server 2', channelId: channelIdServer2 })
178
179 await waitJobs(servers)
180
181 // Expire video channel
182 await wait(10000)
183
184 const search = 'http://localhost:9002/video-channels/channel1_server2'
185 await searchVideoChannel(servers[0].url, search, servers[0].accessToken)
186
187 await waitJobs(servers)
188
189 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:9002', 0, 5, '-createdAt')
190
191 expect(res.body.total).to.equal(2)
192 expect(res.body.data[0].name).to.equal('video 2 server 2')
193 expect(res.body.data[1].name).to.equal('video 1 updated')
194 })
195
196 it('Should delete video channel of server 2, and delete it on server 1', async function () {
197 this.timeout(60000)
198
199 await deleteVideoChannel(servers[1].url, userServer2Token, 'channel1_server2')
200
201 await waitJobs(servers)
202 // Expire video
203 await wait(10000)
204
205 const res = await searchVideoChannel(servers[0].url, 'http://localhost:9002/video-channels/channel1_server2', servers[0].accessToken)
206 expect(res.body.total).to.equal(0)
207 expect(res.body.data).to.have.lengthOf(0)
208 })
209
210 after(async function () {
211 killallServers(servers)
212
213 // Keep the logs if the test failed
214 if (this['ok']) {
215 await flushTests()
216 }
217 })
218 })