1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 flushAndRunMultipleServers,
13 setAccessTokensToServers,
17 } from '../../../../shared/extra-utils'
18 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
19 import { VideoPrivacy } from '../../../../shared/models/videos'
21 const expect = chai.expect
23 describe('Test ActivityPub videos search', function () {
24 let servers: ServerInfo[]
25 let videoServer1UUID: string
26 let videoServer2UUID: string
28 let command: SearchCommand
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)
49 command = servers[0].searchCommand
52 it('Should not find a remote video', async function () {
54 const search = 'http://localhost:' + servers[1].port + '/videos/watch/43'
55 const body = await command.searchVideos({ search, token: servers[0].accessToken })
57 expect(body.total).to.equal(0)
58 expect(body.data).to.be.an('array')
59 expect(body.data).to.have.lengthOf(0)
64 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
65 const body = await command.searchVideos({ search })
67 expect(body.total).to.equal(0)
68 expect(body.data).to.be.an('array')
69 expect(body.data).to.have.lengthOf(0)
73 it('Should search a local video', async function () {
74 const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID
75 const body = await command.searchVideos({ search })
77 expect(body.total).to.equal(1)
78 expect(body.data).to.be.an('array')
79 expect(body.data).to.have.lengthOf(1)
80 expect(body.data[0].name).to.equal('video 1 on server 1')
83 it('Should search a local video with an alternative URL', async function () {
84 const search = 'http://localhost:' + servers[0].port + '/w/' + videoServer1UUID
85 const body1 = await command.searchVideos({ search })
86 const body2 = await command.searchVideos({ search, token: servers[0].accessToken })
88 for (const body of [ body1, body2 ]) {
89 expect(body.total).to.equal(1)
90 expect(body.data).to.be.an('array')
91 expect(body.data).to.have.lengthOf(1)
92 expect(body.data[0].name).to.equal('video 1 on server 1')
96 it('Should search a remote video', async function () {
98 'http://localhost:' + servers[1].port + '/w/' + videoServer2UUID,
99 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
102 for (const search of searches) {
103 const body = await command.searchVideos({ search, token: servers[0].accessToken })
105 expect(body.total).to.equal(1)
106 expect(body.data).to.be.an('array')
107 expect(body.data).to.have.lengthOf(1)
108 expect(body.data[0].name).to.equal('video 1 on server 2')
112 it('Should not list this remote video', async function () {
113 const res = await getVideosList(servers[0].url)
114 expect(res.body.total).to.equal(1)
115 expect(res.body.data).to.have.lengthOf(1)
116 expect(res.body.data[0].name).to.equal('video 1 on server 1')
119 it('Should update video of server 2, and refresh it on server 1', async function () {
122 const channelAttributes = {
123 name: 'super_channel',
124 displayName: 'super channel'
126 const resChannel = await addVideoChannel(servers[1].url, servers[1].accessToken, channelAttributes)
127 const videoChannelId = resChannel.body.videoChannel.id
131 tag: [ 'tag1', 'tag2' ],
132 privacy: VideoPrivacy.UNLISTED,
133 channelId: videoChannelId
135 await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes)
137 await waitJobs(servers)
141 // Will run refresh async
142 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
143 await command.searchVideos({ search, token: servers[0].accessToken })
148 const body = await command.searchVideos({ search, token: servers[0].accessToken })
149 expect(body.total).to.equal(1)
150 expect(body.data).to.have.lengthOf(1)
152 const video = body.data[0]
153 expect(video.name).to.equal('updated')
154 expect(video.channel.name).to.equal('super_channel')
155 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
158 it('Should delete video of server 2, and delete it on server 1', async function () {
161 await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID)
163 await waitJobs(servers)
167 // Will run refresh async
168 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
169 await command.searchVideos({ search, token: servers[0].accessToken })
174 const body = await command.searchVideos({ search, token: servers[0].accessToken })
175 expect(body.total).to.equal(0)
176 expect(body.data).to.have.lengthOf(0)
179 after(async function () {
180 await cleanupTests(servers)