]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/search/search-activitypub-videos.ts
Use an object to represent a server
[github/Chocobozzz/PeerTube.git] / server / tests / api / search / search-activitypub-videos.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
1297eb5d 2
1297eb5d 3import 'mocha'
af971e06 4import * as chai from 'chai'
1297eb5d 5import {
7243f84d 6 cleanupTests,
254d3579 7 createMultipleServers,
af971e06 8 SearchCommand,
254d3579 9 PeerTubeServer,
1297eb5d 10 setAccessTokensToServers,
d23dd9fb
C
11 wait,
12 waitJobs
13} from '@shared/extra-utils'
14import { VideoPrivacy } from '@shared/models'
1297eb5d
C
15
16const expect = chai.expect
17
da3a3ab6 18describe('Test ActivityPub videos search', function () {
254d3579 19 let servers: PeerTubeServer[]
1297eb5d
C
20 let videoServer1UUID: string
21 let videoServer2UUID: string
22
af971e06
C
23 let command: SearchCommand
24
1297eb5d
C
25 before(async function () {
26 this.timeout(120000)
27
254d3579 28 servers = await createMultipleServers(2)
1297eb5d
C
29
30 await setAccessTokensToServers(servers)
31
32 {
89d241a7 33 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1 on server 1' } })
d23dd9fb 34 videoServer1UUID = uuid
1297eb5d
C
35 }
36
37 {
89d241a7 38 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 on server 2' } })
d23dd9fb 39 videoServer2UUID = uuid
1297eb5d
C
40 }
41
42 await waitJobs(servers)
af971e06 43
89d241a7 44 command = servers[0].search
1297eb5d
C
45 })
46
47 it('Should not find a remote video', async function () {
48 {
7243f84d 49 const search = 'http://localhost:' + servers[1].port + '/videos/watch/43'
af971e06 50 const body = await command.searchVideos({ search, token: servers[0].accessToken })
1297eb5d 51
af971e06
C
52 expect(body.total).to.equal(0)
53 expect(body.data).to.be.an('array')
54 expect(body.data).to.have.lengthOf(0)
1297eb5d
C
55 }
56
57 {
f5b0af50 58 // Without token
7243f84d 59 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
af971e06 60 const body = await command.searchVideos({ search })
1297eb5d 61
af971e06
C
62 expect(body.total).to.equal(0)
63 expect(body.data).to.be.an('array')
64 expect(body.data).to.have.lengthOf(0)
1297eb5d
C
65 }
66 })
67
68 it('Should search a local video', async function () {
7243f84d 69 const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID
2d1ad5b9 70 const body = await command.searchVideos({ search })
1297eb5d 71
af971e06
C
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')
1297eb5d
C
76 })
77
37a44fc9
C
78 it('Should search a local video with an alternative URL', async function () {
79 const search = 'http://localhost:' + servers[0].port + '/w/' + videoServer1UUID
af971e06
C
80 const body1 = await command.searchVideos({ search })
81 const body2 = await command.searchVideos({ search, token: servers[0].accessToken })
82
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')
37a44fc9
C
88 }
89 })
90
1297eb5d 91 it('Should search a remote video', async function () {
37a44fc9
C
92 const searches = [
93 'http://localhost:' + servers[1].port + '/w/' + videoServer2UUID,
94 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
95 ]
1297eb5d 96
37a44fc9 97 for (const search of searches) {
af971e06 98 const body = await command.searchVideos({ search, token: servers[0].accessToken })
37a44fc9 99
af971e06
C
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')
37a44fc9 104 }
1297eb5d
C
105 })
106
107 it('Should not list this remote video', async function () {
89d241a7 108 const { total, data } = await servers[0].videos.list()
d23dd9fb
C
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')
1297eb5d
C
112 })
113
114 it('Should update video of server 2, and refresh it on server 1', async function () {
37a44fc9 115 this.timeout(120000)
1297eb5d
C
116
117 const channelAttributes = {
118 name: 'super_channel',
119 displayName: 'super channel'
120 }
89d241a7 121 const created = await servers[1].channels.create({ attributes: channelAttributes })
a5461888 122 const videoChannelId = created.id
1297eb5d
C
123
124 const attributes = {
125 name: 'updated',
126 tag: [ 'tag1', 'tag2' ],
127 privacy: VideoPrivacy.UNLISTED,
128 channelId: videoChannelId
129 }
89d241a7 130 await servers[1].videos.update({ id: videoServer2UUID, attributes })
1297eb5d
C
131
132 await waitJobs(servers)
133 // Expire video
134 await wait(10000)
135
136 // Will run refresh async
7243f84d 137 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
af971e06 138 await command.searchVideos({ search, token: servers[0].accessToken })
1297eb5d
C
139
140 // Wait refresh
141 await wait(5000)
142
af971e06
C
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)
1297eb5d 146
af971e06 147 const video = body.data[0]
1297eb5d
C
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)
151 })
152
153 it('Should delete video of server 2, and delete it on server 1', async function () {
37a44fc9 154 this.timeout(120000)
1297eb5d 155
89d241a7 156 await servers[1].videos.remove({ id: videoServer2UUID })
1297eb5d
C
157
158 await waitJobs(servers)
159 // Expire video
160 await wait(10000)
161
162 // Will run refresh async
7243f84d 163 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
af971e06 164 await command.searchVideos({ search, token: servers[0].accessToken })
1297eb5d
C
165
166 // Wait refresh
167 await wait(5000)
168
af971e06
C
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)
1297eb5d
C
172 })
173
7c3b7976
C
174 after(async function () {
175 await cleanupTests(servers)
1297eb5d
C
176 })
177})