]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/search/search-activitypub-videos.ts
Improve wait transcoding help
[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'
c55e3d72
C
5import { wait } from '@shared/core-utils'
6import { VideoPrivacy } from '@shared/models'
1297eb5d 7import {
7243f84d 8 cleanupTests,
254d3579 9 createMultipleServers,
254d3579 10 PeerTubeServer,
4c7e60bc 11 SearchCommand,
1297eb5d 12 setAccessTokensToServers,
d0800f76 13 setDefaultAccountAvatar,
14 setDefaultVideoChannel,
d23dd9fb 15 waitJobs
bf54587a 16} from '@shared/server-commands'
1297eb5d
C
17
18const expect = chai.expect
19
da3a3ab6 20describe('Test ActivityPub videos search', function () {
254d3579 21 let servers: PeerTubeServer[]
1297eb5d
C
22 let videoServer1UUID: string
23 let videoServer2UUID: string
24
af971e06
C
25 let command: SearchCommand
26
1297eb5d
C
27 before(async function () {
28 this.timeout(120000)
29
254d3579 30 servers = await createMultipleServers(2)
1297eb5d
C
31
32 await setAccessTokensToServers(servers)
d0800f76 33 await setDefaultVideoChannel(servers)
34 await setDefaultAccountAvatar(servers)
1297eb5d
C
35
36 {
89d241a7 37 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1 on server 1' } })
d23dd9fb 38 videoServer1UUID = uuid
1297eb5d
C
39 }
40
41 {
89d241a7 42 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 on server 2' } })
d23dd9fb 43 videoServer2UUID = uuid
1297eb5d
C
44 }
45
46 await waitJobs(servers)
af971e06 47
89d241a7 48 command = servers[0].search
1297eb5d
C
49 })
50
51 it('Should not find a remote video', async function () {
52 {
400043b1 53 const search = servers[1].url + '/videos/watch/43'
af971e06 54 const body = await command.searchVideos({ search, token: servers[0].accessToken })
1297eb5d 55
af971e06
C
56 expect(body.total).to.equal(0)
57 expect(body.data).to.be.an('array')
58 expect(body.data).to.have.lengthOf(0)
1297eb5d
C
59 }
60
61 {
f5b0af50 62 // Without token
400043b1 63 const search = servers[1].url + '/videos/watch/' + videoServer2UUID
af971e06 64 const body = await command.searchVideos({ search })
1297eb5d 65
af971e06
C
66 expect(body.total).to.equal(0)
67 expect(body.data).to.be.an('array')
68 expect(body.data).to.have.lengthOf(0)
1297eb5d
C
69 }
70 })
71
72 it('Should search a local video', async function () {
400043b1 73 const search = servers[0].url + '/videos/watch/' + videoServer1UUID
2d1ad5b9 74 const body = await command.searchVideos({ search })
1297eb5d 75
af971e06
C
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')
1297eb5d
C
80 })
81
37a44fc9 82 it('Should search a local video with an alternative URL', async function () {
400043b1 83 const search = servers[0].url + '/w/' + videoServer1UUID
af971e06
C
84 const body1 = await command.searchVideos({ search })
85 const body2 = await command.searchVideos({ search, token: servers[0].accessToken })
86
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')
37a44fc9
C
92 }
93 })
94
400043b1
C
95 it('Should search a local video with a query in URL', async function () {
96 const searches = [
97 servers[0].url + '/w/' + videoServer1UUID,
98 servers[0].url + '/videos/watch/' + videoServer1UUID
99 ]
100
101 for (const search of searches) {
102 for (const token of [ undefined, servers[0].accessToken ]) {
103 const body = await command.searchVideos({ search: search + '?startTime=4', token })
104
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 1')
109 }
110 }
111 })
112
1297eb5d 113 it('Should search a remote video', async function () {
37a44fc9 114 const searches = [
400043b1
C
115 servers[1].url + '/w/' + videoServer2UUID,
116 servers[1].url + '/videos/watch/' + videoServer2UUID
37a44fc9 117 ]
1297eb5d 118
37a44fc9 119 for (const search of searches) {
af971e06 120 const body = await command.searchVideos({ search, token: servers[0].accessToken })
37a44fc9 121
af971e06
C
122 expect(body.total).to.equal(1)
123 expect(body.data).to.be.an('array')
124 expect(body.data).to.have.lengthOf(1)
125 expect(body.data[0].name).to.equal('video 1 on server 2')
37a44fc9 126 }
1297eb5d
C
127 })
128
129 it('Should not list this remote video', async function () {
89d241a7 130 const { total, data } = await servers[0].videos.list()
d23dd9fb
C
131 expect(total).to.equal(1)
132 expect(data).to.have.lengthOf(1)
133 expect(data[0].name).to.equal('video 1 on server 1')
1297eb5d
C
134 })
135
136 it('Should update video of server 2, and refresh it on server 1', async function () {
37a44fc9 137 this.timeout(120000)
1297eb5d
C
138
139 const channelAttributes = {
140 name: 'super_channel',
141 displayName: 'super channel'
142 }
89d241a7 143 const created = await servers[1].channels.create({ attributes: channelAttributes })
a5461888 144 const videoChannelId = created.id
1297eb5d
C
145
146 const attributes = {
147 name: 'updated',
148 tag: [ 'tag1', 'tag2' ],
149 privacy: VideoPrivacy.UNLISTED,
150 channelId: videoChannelId
151 }
89d241a7 152 await servers[1].videos.update({ id: videoServer2UUID, attributes })
1297eb5d
C
153
154 await waitJobs(servers)
155 // Expire video
156 await wait(10000)
157
158 // Will run refresh async
400043b1 159 const search = servers[1].url + '/videos/watch/' + videoServer2UUID
af971e06 160 await command.searchVideos({ search, token: servers[0].accessToken })
1297eb5d
C
161
162 // Wait refresh
163 await wait(5000)
164
af971e06
C
165 const body = await command.searchVideos({ search, token: servers[0].accessToken })
166 expect(body.total).to.equal(1)
167 expect(body.data).to.have.lengthOf(1)
1297eb5d 168
af971e06 169 const video = body.data[0]
1297eb5d
C
170 expect(video.name).to.equal('updated')
171 expect(video.channel.name).to.equal('super_channel')
172 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
173 })
174
175 it('Should delete video of server 2, and delete it on server 1', async function () {
37a44fc9 176 this.timeout(120000)
1297eb5d 177
89d241a7 178 await servers[1].videos.remove({ id: videoServer2UUID })
1297eb5d
C
179
180 await waitJobs(servers)
181 // Expire video
182 await wait(10000)
183
184 // Will run refresh async
400043b1 185 const search = servers[1].url + '/videos/watch/' + videoServer2UUID
af971e06 186 await command.searchVideos({ search, token: servers[0].accessToken })
1297eb5d
C
187
188 // Wait refresh
189 await wait(5000)
190
af971e06
C
191 const body = await command.searchVideos({ search, token: servers[0].accessToken })
192 expect(body.total).to.equal(0)
193 expect(body.data).to.have.lengthOf(0)
1297eb5d
C
194 })
195
7c3b7976
C
196 after(async function () {
197 await cleanupTests(servers)
1297eb5d
C
198 })
199})