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