1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
9 flushAndRunMultipleServers,
11 getVideoChannelsList, getVideoChannelVideos,
14 setAccessTokensToServers,
15 updateMyUser, updateVideo,
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'
25 const expect = chai.expect
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
33 before(async function () {
38 servers = await flushAndRunMultipleServers(2)
40 await setAccessTokensToServers(servers)
43 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'user1_server1', password: 'password' })
45 name: 'channel1_server1',
46 displayName: 'Channel 1 server 1'
48 await addVideoChannel(servers[0].url, servers[0].accessToken, channel)
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)
57 name: 'channel1_server2',
58 displayName: 'Channel 1 server 2'
60 const resChannel = await addVideoChannel(servers[1].url, userServer2Token, channel)
61 channelIdServer2 = resChannel.body.videoChannel.id
63 const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 })
64 videoServer2UUID = res.body.video.uuid
67 await waitJobs(servers)
70 it('Should not find a remote video channel', async function () {
72 const search = 'http://localhost:9002/video-channels/channel1_server3'
73 const res = await searchVideoChannel(servers[ 0 ].url, search, servers[ 0 ].accessToken)
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)
82 const search = 'http://localhost:9002/video-channels/channel1_server2'
83 const res = await searchVideoChannel(servers[0].url, search)
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)
91 it('Should search a local video channel', async function () {
93 'http://localhost:9001/video-channels/channel1_server1',
94 'channel1_server1@localhost:9001'
97 for (const search of searches) {
98 const res = await searchVideoChannel(servers[ 0 ].url, search)
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')
108 it('Should search a remote video channel with URL or handle', async function () {
110 'http://localhost:9002/video-channels/channel1_server2',
111 'channel1_server2@localhost:9002'
114 for (const search of searches) {
115 const res = await searchVideoChannel(servers[ 0 ].url, search, servers[ 0 ].accessToken)
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')
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')
134 it('Should list video channel videos of server 2 without token', async function () {
137 await waitJobs(servers)
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)
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)
147 expect(res.body.total).to.equal(1)
148 expect(res.body.data[0].name).to.equal('video 1 server 2')
151 it('Should update video channel of server 2, and refresh it on server 1', async function () {
154 await updateVideoChannel(servers[1].url, userServer2Token, 'channel1_server2', { displayName: 'channel updated' })
155 await updateMyUser({ url: servers[1].url, accessToken: userServer2Token, displayName: 'user updated' })
157 await waitJobs(servers)
158 // Expire video channel
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)
166 const videoChannel: VideoChannel = res.body.data[0]
167 expect(videoChannel.displayName).to.equal('channel updated')
169 // We don't return the owner account for now
170 // expect(videoChannel.ownerAccount.displayName).to.equal('user updated')
173 it('Should update and add a video on server 2, and update it on server 1 after a search', async function () {
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 })
179 await waitJobs(servers)
181 // Expire video channel
184 const search = 'http://localhost:9002/video-channels/channel1_server2'
185 await searchVideoChannel(servers[0].url, search, servers[0].accessToken)
187 await waitJobs(servers)
189 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:9002', 0, 5, '-createdAt')
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')
196 it('Should delete video channel of server 2, and delete it on server 1', async function () {
199 await deleteVideoChannel(servers[1].url, userServer2Token, 'channel1_server2')
201 await waitJobs(servers)
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)
210 after(async function () {
211 killallServers(servers)
213 // Keep the logs if the test failed