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