1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
7 flushAndRunMultipleServers,
14 setAccessTokensToServers,
18 searchVideo, cleanupTests
19 } from '../../../../shared/extra-utils'
20 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21 import { Video, VideoPrivacy } from '../../../../shared/models/videos'
23 const expect = chai.expect
25 describe('Test ActivityPub videos search', function () {
26 let servers: ServerInfo[]
27 let videoServer1UUID: string
28 let videoServer2UUID: string
30 before(async function () {
33 servers = await flushAndRunMultipleServers(2)
35 await setAccessTokensToServers(servers)
38 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video 1 on server 1' })
39 videoServer1UUID = res.body.video.uuid
43 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 1 on server 2' })
44 videoServer2UUID = res.body.video.uuid
47 await waitJobs(servers)
50 it('Should not find a remote video', async function () {
52 const res = await searchVideoWithToken(servers[ 0 ].url, 'http://localhost:9002/videos/watch/43', servers[ 0 ].accessToken)
54 expect(res.body.total).to.equal(0)
55 expect(res.body.data).to.be.an('array')
56 expect(res.body.data).to.have.lengthOf(0)
61 const res = await searchVideo(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID)
63 expect(res.body.total).to.equal(0)
64 expect(res.body.data).to.be.an('array')
65 expect(res.body.data).to.have.lengthOf(0)
69 it('Should search a local video', async function () {
70 const res = await searchVideo(servers[0].url, 'http://localhost:9001/videos/watch/' + videoServer1UUID)
72 expect(res.body.total).to.equal(1)
73 expect(res.body.data).to.be.an('array')
74 expect(res.body.data).to.have.lengthOf(1)
75 expect(res.body.data[0].name).to.equal('video 1 on server 1')
78 it('Should search a remote video', async function () {
79 const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
81 expect(res.body.total).to.equal(1)
82 expect(res.body.data).to.be.an('array')
83 expect(res.body.data).to.have.lengthOf(1)
84 expect(res.body.data[0].name).to.equal('video 1 on server 2')
87 it('Should not list this remote video', async function () {
88 const res = await getVideosList(servers[0].url)
89 expect(res.body.total).to.equal(1)
90 expect(res.body.data).to.have.lengthOf(1)
91 expect(res.body.data[0].name).to.equal('video 1 on server 1')
94 it('Should update video of server 2, and refresh it on server 1', async function () {
97 const channelAttributes = {
98 name: 'super_channel',
99 displayName: 'super channel'
101 const resChannel = await addVideoChannel(servers[1].url, servers[1].accessToken, channelAttributes)
102 const videoChannelId = resChannel.body.videoChannel.id
106 tag: [ 'tag1', 'tag2' ],
107 privacy: VideoPrivacy.UNLISTED,
108 channelId: videoChannelId
110 await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes)
112 await waitJobs(servers)
116 // Will run refresh async
117 await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
122 const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
123 expect(res.body.total).to.equal(1)
124 expect(res.body.data).to.have.lengthOf(1)
126 const video: Video = res.body.data[0]
127 expect(video.name).to.equal('updated')
128 expect(video.channel.name).to.equal('super_channel')
129 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
132 it('Should delete video of server 2, and delete it on server 1', async function () {
135 await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID)
137 await waitJobs(servers)
141 // Will run refresh async
142 await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
147 const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
148 expect(res.body.total).to.equal(0)
149 expect(res.body.data).to.have.lengthOf(0)
152 after(async function () {
153 await cleanupTests(servers)