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