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