1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
7 flushAndRunMultipleServers,
12 setAccessTokensToServers,
16 } from '../../../../shared/extra-utils'
17 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
18 import { VideoPrivacy } from '../../../../shared/models/videos'
20 const expect = chai.expect
22 describe('Test ActivityPub videos search', function () {
23 let servers: ServerInfo[]
24 let videoServer1UUID: string
25 let videoServer2UUID: string
27 let command: SearchCommand
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)
48 command = servers[0].searchCommand
51 it('Should not find a remote video', async function () {
53 const search = 'http://localhost:' + servers[1].port + '/videos/watch/43'
54 const body = await command.searchVideos({ search, token: servers[0].accessToken })
56 expect(body.total).to.equal(0)
57 expect(body.data).to.be.an('array')
58 expect(body.data).to.have.lengthOf(0)
63 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
64 const body = await command.searchVideos({ search })
66 expect(body.total).to.equal(0)
67 expect(body.data).to.be.an('array')
68 expect(body.data).to.have.lengthOf(0)
72 it('Should search a local video', async function () {
73 const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID
74 const body = await command.searchVideos({ search })
76 expect(body.total).to.equal(1)
77 expect(body.data).to.be.an('array')
78 expect(body.data).to.have.lengthOf(1)
79 expect(body.data[0].name).to.equal('video 1 on server 1')
82 it('Should search a local video with an alternative URL', async function () {
83 const search = 'http://localhost:' + servers[0].port + '/w/' + videoServer1UUID
84 const body1 = await command.searchVideos({ search })
85 const body2 = await command.searchVideos({ search, token: servers[0].accessToken })
87 for (const body of [ body1, body2 ]) {
88 expect(body.total).to.equal(1)
89 expect(body.data).to.be.an('array')
90 expect(body.data).to.have.lengthOf(1)
91 expect(body.data[0].name).to.equal('video 1 on server 1')
95 it('Should search a remote video', async function () {
97 'http://localhost:' + servers[1].port + '/w/' + videoServer2UUID,
98 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
101 for (const search of searches) {
102 const body = await command.searchVideos({ search, token: servers[0].accessToken })
104 expect(body.total).to.equal(1)
105 expect(body.data).to.be.an('array')
106 expect(body.data).to.have.lengthOf(1)
107 expect(body.data[0].name).to.equal('video 1 on server 2')
111 it('Should not list this remote video', async function () {
112 const res = await getVideosList(servers[0].url)
113 expect(res.body.total).to.equal(1)
114 expect(res.body.data).to.have.lengthOf(1)
115 expect(res.body.data[0].name).to.equal('video 1 on server 1')
118 it('Should update video of server 2, and refresh it on server 1', async function () {
121 const channelAttributes = {
122 name: 'super_channel',
123 displayName: 'super channel'
125 const created = await servers[1].channelsCommand.create({ attributes: channelAttributes })
126 const videoChannelId = created.id
130 tag: [ 'tag1', 'tag2' ],
131 privacy: VideoPrivacy.UNLISTED,
132 channelId: videoChannelId
134 await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes)
136 await waitJobs(servers)
140 // Will run refresh async
141 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
142 await command.searchVideos({ search, token: servers[0].accessToken })
147 const body = await command.searchVideos({ search, token: servers[0].accessToken })
148 expect(body.total).to.equal(1)
149 expect(body.data).to.have.lengthOf(1)
151 const video = body.data[0]
152 expect(video.name).to.equal('updated')
153 expect(video.channel.name).to.equal('super_channel')
154 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
157 it('Should delete video of server 2, and delete it on server 1', async function () {
160 await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID)
162 await waitJobs(servers)
166 // Will run refresh async
167 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
168 await command.searchVideos({ search, token: servers[0].accessToken })
173 const body = await command.searchVideos({ search, token: servers[0].accessToken })
174 expect(body.total).to.equal(0)
175 expect(body.data).to.have.lengthOf(0)
178 after(async function () {
179 await cleanupTests(servers)