1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
7 flushAndRunMultipleServers,
14 setAccessTokensToServers,
20 import { waitJobs } from '../../utils/server/jobs'
21 import { Video, VideoPrivacy } from '../../../../shared/models/videos'
23 const expect = chai.expect
25 describe('Test a ActivityPub videos search', function () {
26 let servers: ServerInfo[]
27 let videoServer1UUID: string
28 let videoServer2UUID: string
30 before(async function () {
35 servers = await flushAndRunMultipleServers(2)
37 await setAccessTokensToServers(servers)
40 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video 1 on server 1' })
41 videoServer1UUID = res.body.video.uuid
45 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 1 on server 2' })
46 videoServer2UUID = res.body.video.uuid
49 await waitJobs(servers)
52 it('Should not find a remote video', async function () {
54 const res = await searchVideoWithToken(servers[ 0 ].url, 'http://localhost:9002/videos/watch/43', servers[ 0 ].accessToken)
56 expect(res.body.total).to.equal(0)
57 expect(res.body.data).to.be.an('array')
58 expect(res.body.data).to.have.lengthOf(0)
62 const res = await searchVideo(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID)
64 expect(res.body.total).to.equal(0)
65 expect(res.body.data).to.be.an('array')
66 expect(res.body.data).to.have.lengthOf(0)
70 it('Should search a local video', async function () {
71 const res = await searchVideo(servers[0].url, 'http://localhost:9001/videos/watch/' + videoServer1UUID)
73 expect(res.body.total).to.equal(1)
74 expect(res.body.data).to.be.an('array')
75 expect(res.body.data).to.have.lengthOf(1)
76 expect(res.body.data[0].name).to.equal('video 1 on server 1')
79 it('Should search a remote video', async function () {
80 const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
82 expect(res.body.total).to.equal(1)
83 expect(res.body.data).to.be.an('array')
84 expect(res.body.data).to.have.lengthOf(1)
85 expect(res.body.data[0].name).to.equal('video 1 on server 2')
88 it('Should not list this remote video', async function () {
89 const res = await getVideosList(servers[0].url)
90 expect(res.body.total).to.equal(1)
91 expect(res.body.data).to.have.lengthOf(1)
92 expect(res.body.data[0].name).to.equal('video 1 on server 1')
95 it('Should update video of server 2, and refresh it on server 1', async function () {
98 const channelAttributes = {
99 name: 'super_channel',
100 displayName: 'super channel'
102 const resChannel = await addVideoChannel(servers[1].url, servers[1].accessToken, channelAttributes)
103 const videoChannelId = resChannel.body.videoChannel.id
107 tag: [ 'tag1', 'tag2' ],
108 privacy: VideoPrivacy.UNLISTED,
109 channelId: videoChannelId
111 await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes)
113 await waitJobs(servers)
117 // Will run refresh async
118 await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
123 const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
124 expect(res.body.total).to.equal(1)
125 expect(res.body.data).to.have.lengthOf(1)
127 const video: Video = res.body.data[0]
128 expect(video.name).to.equal('updated')
129 expect(video.channel.name).to.equal('super_channel')
130 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
133 it('Should delete video of server 2, and delete it on server 1', async function () {
136 await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID)
138 await waitJobs(servers)
142 // Will run refresh async
143 await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
148 const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
149 expect(res.body.total).to.equal(0)
150 expect(res.body.data).to.have.lengthOf(0)
153 after(async function () {
154 killallServers(servers)
156 // Keep the logs if the test failed