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