1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
8 flushAndRunMultipleServers,
14 setAccessTokensToServers,
18 } from '../../../../shared/extra-utils'
19 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
20 import { Video, VideoPrivacy } from '../../../../shared/models/videos'
22 const expect = chai.expect
24 describe('Test ActivityPub videos search', function () {
25 let servers: ServerInfo[]
26 let videoServer1UUID: string
27 let videoServer2UUID: string
29 before(async function () {
32 servers = await flushAndRunMultipleServers(2)
34 await setAccessTokensToServers(servers)
37 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video 1 on server 1' })
38 videoServer1UUID = res.body.video.uuid
42 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 1 on server 2' })
43 videoServer2UUID = res.body.video.uuid
46 await waitJobs(servers)
49 it('Should not find a remote video', async function () {
51 const search = 'http://localhost:' + servers[1].port + '/videos/watch/43'
52 const res = await searchVideoWithToken(servers[ 0 ].url, search, 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 search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
62 const res = await searchVideo(servers[0].url, search)
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 search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID
72 const res = await searchVideo(servers[0].url, search)
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 search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
82 const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken)
84 expect(res.body.total).to.equal(1)
85 expect(res.body.data).to.be.an('array')
86 expect(res.body.data).to.have.lengthOf(1)
87 expect(res.body.data[0].name).to.equal('video 1 on server 2')
90 it('Should not list this remote video', async function () {
91 const res = await getVideosList(servers[0].url)
92 expect(res.body.total).to.equal(1)
93 expect(res.body.data).to.have.lengthOf(1)
94 expect(res.body.data[0].name).to.equal('video 1 on server 1')
97 it('Should update video of server 2, and refresh it on server 1', async function () {
100 const channelAttributes = {
101 name: 'super_channel',
102 displayName: 'super channel'
104 const resChannel = await addVideoChannel(servers[1].url, servers[1].accessToken, channelAttributes)
105 const videoChannelId = resChannel.body.videoChannel.id
109 tag: [ 'tag1', 'tag2' ],
110 privacy: VideoPrivacy.UNLISTED,
111 channelId: videoChannelId
113 await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes)
115 await waitJobs(servers)
119 // Will run refresh async
120 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
121 await searchVideoWithToken(servers[0].url, search, servers[0].accessToken)
126 const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken)
127 expect(res.body.total).to.equal(1)
128 expect(res.body.data).to.have.lengthOf(1)
130 const video: Video = res.body.data[0]
131 expect(video.name).to.equal('updated')
132 expect(video.channel.name).to.equal('super_channel')
133 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
136 it('Should delete video of server 2, and delete it on server 1', async function () {
139 await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID)
141 await waitJobs(servers)
145 // Will run refresh async
146 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
147 await searchVideoWithToken(servers[0].url, search, servers[0].accessToken)
152 const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken)
153 expect(res.body.total).to.equal(0)
154 expect(res.body.data).to.have.lengthOf(0)
157 after(async function () {
158 await cleanupTests(servers)