1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 setAccessTokensToServers,
13 } from '@shared/extra-utils'
14 import { VideoPrivacy } from '@shared/models'
16 const expect = chai.expect
18 describe('Test ActivityPub videos search', function () {
19 let servers: PeerTubeServer[]
20 let videoServer1UUID: string
21 let videoServer2UUID: string
23 let command: SearchCommand
25 before(async function () {
28 servers = await createMultipleServers(2)
30 await setAccessTokensToServers(servers)
33 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1 on server 1' } })
34 videoServer1UUID = uuid
38 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 on server 2' } })
39 videoServer2UUID = uuid
42 await waitJobs(servers)
44 command = servers[0].search
47 it('Should not find a remote video', async function () {
49 const search = 'http://localhost:' + servers[1].port + '/videos/watch/43'
50 const body = await command.searchVideos({ search, token: servers[0].accessToken })
52 expect(body.total).to.equal(0)
53 expect(body.data).to.be.an('array')
54 expect(body.data).to.have.lengthOf(0)
59 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
60 const body = await command.searchVideos({ search })
62 expect(body.total).to.equal(0)
63 expect(body.data).to.be.an('array')
64 expect(body.data).to.have.lengthOf(0)
68 it('Should search a local video', async function () {
69 const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID
70 const body = await command.searchVideos({ search })
72 expect(body.total).to.equal(1)
73 expect(body.data).to.be.an('array')
74 expect(body.data).to.have.lengthOf(1)
75 expect(body.data[0].name).to.equal('video 1 on server 1')
78 it('Should search a local video with an alternative URL', async function () {
79 const search = 'http://localhost:' + servers[0].port + '/w/' + videoServer1UUID
80 const body1 = await command.searchVideos({ search })
81 const body2 = await command.searchVideos({ search, token: servers[0].accessToken })
83 for (const body of [ body1, body2 ]) {
84 expect(body.total).to.equal(1)
85 expect(body.data).to.be.an('array')
86 expect(body.data).to.have.lengthOf(1)
87 expect(body.data[0].name).to.equal('video 1 on server 1')
91 it('Should search a remote video', async function () {
93 'http://localhost:' + servers[1].port + '/w/' + videoServer2UUID,
94 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
97 for (const search of searches) {
98 const body = await command.searchVideos({ search, token: servers[0].accessToken })
100 expect(body.total).to.equal(1)
101 expect(body.data).to.be.an('array')
102 expect(body.data).to.have.lengthOf(1)
103 expect(body.data[0].name).to.equal('video 1 on server 2')
107 it('Should not list this remote video', async function () {
108 const { total, data } = await servers[0].videos.list()
109 expect(total).to.equal(1)
110 expect(data).to.have.lengthOf(1)
111 expect(data[0].name).to.equal('video 1 on server 1')
114 it('Should update video of server 2, and refresh it on server 1', async function () {
117 const channelAttributes = {
118 name: 'super_channel',
119 displayName: 'super channel'
121 const created = await servers[1].channels.create({ attributes: channelAttributes })
122 const videoChannelId = created.id
126 tag: [ 'tag1', 'tag2' ],
127 privacy: VideoPrivacy.UNLISTED,
128 channelId: videoChannelId
130 await servers[1].videos.update({ id: videoServer2UUID, attributes })
132 await waitJobs(servers)
136 // Will run refresh async
137 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
138 await command.searchVideos({ search, token: servers[0].accessToken })
143 const body = await command.searchVideos({ search, token: servers[0].accessToken })
144 expect(body.total).to.equal(1)
145 expect(body.data).to.have.lengthOf(1)
147 const video = body.data[0]
148 expect(video.name).to.equal('updated')
149 expect(video.channel.name).to.equal('super_channel')
150 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
153 it('Should delete video of server 2, and delete it on server 1', async function () {
156 await servers[1].videos.remove({ id: videoServer2UUID })
158 await waitJobs(servers)
162 // Will run refresh async
163 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
164 await command.searchVideos({ search, token: servers[0].accessToken })
169 const body = await command.searchVideos({ search, token: servers[0].accessToken })
170 expect(body.total).to.equal(0)
171 expect(body.data).to.have.lengthOf(0)
174 after(async function () {
175 await cleanupTests(servers)