1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
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 local video with an alternative URL', async function () {
81 const search = 'http://localhost:' + servers[0].port + '/w/' + videoServer1UUID
82 const res1 = await searchVideo(servers[0].url, search)
83 const res2 = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken)
85 for (const res of [ res1, res2 ]) {
86 expect(res.body.total).to.equal(1)
87 expect(res.body.data).to.be.an('array')
88 expect(res.body.data).to.have.lengthOf(1)
89 expect(res.body.data[0].name).to.equal('video 1 on server 1')
93 it('Should search a remote video', async function () {
95 'http://localhost:' + servers[1].port + '/w/' + videoServer2UUID,
96 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
99 for (const search of searches) {
100 const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken)
102 expect(res.body.total).to.equal(1)
103 expect(res.body.data).to.be.an('array')
104 expect(res.body.data).to.have.lengthOf(1)
105 expect(res.body.data[0].name).to.equal('video 1 on server 2')
109 it('Should not list this remote video', async function () {
110 const res = await getVideosList(servers[0].url)
111 expect(res.body.total).to.equal(1)
112 expect(res.body.data).to.have.lengthOf(1)
113 expect(res.body.data[0].name).to.equal('video 1 on server 1')
116 it('Should update video of server 2, and refresh it on server 1', async function () {
119 const channelAttributes = {
120 name: 'super_channel',
121 displayName: 'super channel'
123 const resChannel = await addVideoChannel(servers[1].url, servers[1].accessToken, channelAttributes)
124 const videoChannelId = resChannel.body.videoChannel.id
128 tag: [ 'tag1', 'tag2' ],
129 privacy: VideoPrivacy.UNLISTED,
130 channelId: videoChannelId
132 await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes)
134 await waitJobs(servers)
138 // Will run refresh async
139 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
140 await searchVideoWithToken(servers[0].url, search, servers[0].accessToken)
145 const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken)
146 expect(res.body.total).to.equal(1)
147 expect(res.body.data).to.have.lengthOf(1)
149 const video: Video = res.body.data[0]
150 expect(video.name).to.equal('updated')
151 expect(video.channel.name).to.equal('super_channel')
152 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
155 it('Should delete video of server 2, and delete it on server 1', async function () {
158 await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID)
160 await waitJobs(servers)
164 // Will run refresh async
165 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
166 await searchVideoWithToken(servers[0].url, search, servers[0].accessToken)
171 const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken)
172 expect(res.body.total).to.equal(0)
173 expect(res.body.data).to.have.lengthOf(0)
176 after(async function () {
177 await cleanupTests(servers)