1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
7 flushAndRunMultipleServers,
14 setAccessTokensToServers,
19 } from '../../../../shared/utils'
20 import { waitJobs } from '../../../../shared/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)
63 const res = await searchVideo(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID)
65 expect(res.body.total).to.equal(0)
66 expect(res.body.data).to.be.an('array')
67 expect(res.body.data).to.have.lengthOf(0)
71 it('Should search a local video', async function () {
72 const res = await searchVideo(servers[0].url, 'http://localhost:9001/videos/watch/' + videoServer1UUID)
74 expect(res.body.total).to.equal(1)
75 expect(res.body.data).to.be.an('array')
76 expect(res.body.data).to.have.lengthOf(1)
77 expect(res.body.data[0].name).to.equal('video 1 on server 1')
80 it('Should search a remote video', async function () {
81 const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
83 expect(res.body.total).to.equal(1)
84 expect(res.body.data).to.be.an('array')
85 expect(res.body.data).to.have.lengthOf(1)
86 expect(res.body.data[0].name).to.equal('video 1 on server 2')
89 it('Should not list this remote video', async function () {
90 const res = await getVideosList(servers[0].url)
91 expect(res.body.total).to.equal(1)
92 expect(res.body.data).to.have.lengthOf(1)
93 expect(res.body.data[0].name).to.equal('video 1 on server 1')
96 it('Should update video of server 2, and refresh it on server 1', async function () {
99 const channelAttributes = {
100 name: 'super_channel',
101 displayName: 'super channel'
103 const resChannel = await addVideoChannel(servers[1].url, servers[1].accessToken, channelAttributes)
104 const videoChannelId = resChannel.body.videoChannel.id
108 tag: [ 'tag1', 'tag2' ],
109 privacy: VideoPrivacy.UNLISTED,
110 channelId: videoChannelId
112 await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes)
114 await waitJobs(servers)
118 // Will run refresh async
119 await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
124 const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
125 expect(res.body.total).to.equal(1)
126 expect(res.body.data).to.have.lengthOf(1)
128 const video: Video = res.body.data[0]
129 expect(video.name).to.equal('updated')
130 expect(video.channel.name).to.equal('super_channel')
131 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
134 it('Should delete video of server 2, and delete it on server 1', async function () {
137 await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID)
139 await waitJobs(servers)
143 // Will run refresh async
144 await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
149 const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
150 expect(res.body.total).to.equal(0)
151 expect(res.body.data).to.have.lengthOf(0)
154 after(async function () {
155 killallServers(servers)
157 // Keep the logs if the test failed