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