]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/search/search-activitypub-video-playlists.ts
Introduce experimental telemetry
[github/Chocobozzz/PeerTube.git] / server / tests / api / search / search-activitypub-video-playlists.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { wait } from '@shared/core-utils'
6 import { VideoPlaylistPrivacy } from '@shared/models'
7 import {
8 cleanupTests,
9 createMultipleServers,
10 PeerTubeServer,
11 SearchCommand,
12 setAccessTokensToServers,
13 setDefaultAccountAvatar,
14 setDefaultVideoChannel,
15 waitJobs
16 } from '@shared/server-commands'
17
18 const expect = chai.expect
19
20 describe('Test ActivityPub playlists search', function () {
21 let servers: PeerTubeServer[]
22 let playlistServer1UUID: string
23 let playlistServer2UUID: string
24 let video2Server2: string
25
26 let command: SearchCommand
27
28 before(async function () {
29 this.timeout(120000)
30
31 servers = await createMultipleServers(2)
32
33 await setAccessTokensToServers(servers)
34 await setDefaultVideoChannel(servers)
35 await setDefaultAccountAvatar(servers)
36
37 {
38 const video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).uuid
39 const video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).uuid
40
41 const attributes = {
42 displayName: 'playlist 1 on server 1',
43 privacy: VideoPlaylistPrivacy.PUBLIC,
44 videoChannelId: servers[0].store.channel.id
45 }
46 const created = await servers[0].playlists.create({ attributes })
47 playlistServer1UUID = created.uuid
48
49 for (const videoId of [ video1, video2 ]) {
50 await servers[0].playlists.addElement({ playlistId: playlistServer1UUID, attributes: { videoId } })
51 }
52 }
53
54 {
55 const videoId = (await servers[1].videos.quickUpload({ name: 'video 1' })).uuid
56 video2Server2 = (await servers[1].videos.quickUpload({ name: 'video 2' })).uuid
57
58 const attributes = {
59 displayName: 'playlist 1 on server 2',
60 privacy: VideoPlaylistPrivacy.PUBLIC,
61 videoChannelId: servers[1].store.channel.id
62 }
63 const created = await servers[1].playlists.create({ attributes })
64 playlistServer2UUID = created.uuid
65
66 await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId } })
67 }
68
69 await waitJobs(servers)
70
71 command = servers[0].search
72 })
73
74 it('Should not find a remote playlist', async function () {
75 {
76 const search = servers[1].url + '/video-playlists/43'
77 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
78
79 expect(body.total).to.equal(0)
80 expect(body.data).to.be.an('array')
81 expect(body.data).to.have.lengthOf(0)
82 }
83
84 {
85 // Without token
86 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
87 const body = await command.searchPlaylists({ search })
88
89 expect(body.total).to.equal(0)
90 expect(body.data).to.be.an('array')
91 expect(body.data).to.have.lengthOf(0)
92 }
93 })
94
95 it('Should search a local playlist', async function () {
96 const search = servers[0].url + '/video-playlists/' + playlistServer1UUID
97 const body = await command.searchPlaylists({ search })
98
99 expect(body.total).to.equal(1)
100 expect(body.data).to.be.an('array')
101 expect(body.data).to.have.lengthOf(1)
102 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
103 expect(body.data[0].videosLength).to.equal(2)
104 })
105
106 it('Should search a local playlist with an alternative URL', async function () {
107 const searches = [
108 servers[0].url + '/videos/watch/playlist/' + playlistServer1UUID,
109 servers[0].url + '/w/p/' + playlistServer1UUID
110 ]
111
112 for (const search of searches) {
113 for (const token of [ undefined, servers[0].accessToken ]) {
114 const body = await command.searchPlaylists({ search, token })
115
116 expect(body.total).to.equal(1)
117 expect(body.data).to.be.an('array')
118 expect(body.data).to.have.lengthOf(1)
119 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
120 expect(body.data[0].videosLength).to.equal(2)
121 }
122 }
123 })
124
125 it('Should search a local playlist with a query in URL', async function () {
126 const searches = [
127 servers[0].url + '/videos/watch/playlist/' + playlistServer1UUID,
128 servers[0].url + '/w/p/' + playlistServer1UUID
129 ]
130
131 for (const search of searches) {
132 for (const token of [ undefined, servers[0].accessToken ]) {
133 const body = await command.searchPlaylists({ search: search + '?param=1', token })
134
135 expect(body.total).to.equal(1)
136 expect(body.data).to.be.an('array')
137 expect(body.data).to.have.lengthOf(1)
138 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
139 expect(body.data[0].videosLength).to.equal(2)
140 }
141 }
142 })
143
144 it('Should search a remote playlist', async function () {
145 const searches = [
146 servers[1].url + '/video-playlists/' + playlistServer2UUID,
147 servers[1].url + '/videos/watch/playlist/' + playlistServer2UUID,
148 servers[1].url + '/w/p/' + playlistServer2UUID
149 ]
150
151 for (const search of searches) {
152 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
153
154 expect(body.total).to.equal(1)
155 expect(body.data).to.be.an('array')
156 expect(body.data).to.have.lengthOf(1)
157 expect(body.data[0].displayName).to.equal('playlist 1 on server 2')
158 expect(body.data[0].videosLength).to.equal(1)
159 }
160 })
161
162 it('Should not list this remote playlist', async function () {
163 const body = await servers[0].playlists.list({ start: 0, count: 10 })
164 expect(body.total).to.equal(1)
165 expect(body.data).to.have.lengthOf(1)
166 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
167 })
168
169 it('Should update the playlist of server 2, and refresh it on server 1', async function () {
170 this.timeout(60000)
171
172 await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId: video2Server2 } })
173
174 await waitJobs(servers)
175 // Expire playlist
176 await wait(10000)
177
178 // Will run refresh async
179 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
180 await command.searchPlaylists({ search, token: servers[0].accessToken })
181
182 // Wait refresh
183 await wait(5000)
184
185 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
186 expect(body.total).to.equal(1)
187 expect(body.data).to.have.lengthOf(1)
188
189 const playlist = body.data[0]
190 expect(playlist.videosLength).to.equal(2)
191 })
192
193 it('Should delete playlist of server 2, and delete it on server 1', async function () {
194 this.timeout(60000)
195
196 await servers[1].playlists.delete({ playlistId: playlistServer2UUID })
197
198 await waitJobs(servers)
199 // Expiration
200 await wait(10000)
201
202 // Will run refresh async
203 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
204 await command.searchPlaylists({ search, token: servers[0].accessToken })
205
206 // Wait refresh
207 await wait(5000)
208
209 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
210 expect(body.total).to.equal(0)
211 expect(body.data).to.have.lengthOf(0)
212 })
213
214 after(async function () {
215 await cleanupTests(servers)
216 })
217 })