1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
4 import { wait } from '@shared/core-utils'
5 import { VideoPlaylistPrivacy } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultAccountAvatar,
13 setDefaultVideoChannel,
15 } from '@shared/server-commands'
17 const expect = chai.expect
19 describe('Test ActivityPub playlists search', function () {
20 let servers: PeerTubeServer[]
21 let playlistServer1UUID: string
22 let playlistServer2UUID: string
23 let video2Server2: string
25 let command: SearchCommand
27 before(async function () {
30 servers = await createMultipleServers(2)
32 await setAccessTokensToServers(servers)
33 await setDefaultVideoChannel(servers)
34 await setDefaultAccountAvatar(servers)
37 const video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).uuid
38 const video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).uuid
41 displayName: 'playlist 1 on server 1',
42 privacy: VideoPlaylistPrivacy.PUBLIC,
43 videoChannelId: servers[0].store.channel.id
45 const created = await servers[0].playlists.create({ attributes })
46 playlistServer1UUID = created.uuid
48 for (const videoId of [ video1, video2 ]) {
49 await servers[0].playlists.addElement({ playlistId: playlistServer1UUID, attributes: { videoId } })
54 const videoId = (await servers[1].videos.quickUpload({ name: 'video 1' })).uuid
55 video2Server2 = (await servers[1].videos.quickUpload({ name: 'video 2' })).uuid
58 displayName: 'playlist 1 on server 2',
59 privacy: VideoPlaylistPrivacy.PUBLIC,
60 videoChannelId: servers[1].store.channel.id
62 const created = await servers[1].playlists.create({ attributes })
63 playlistServer2UUID = created.uuid
65 await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId } })
68 await waitJobs(servers)
70 command = servers[0].search
73 it('Should not find a remote playlist', async function () {
75 const search = servers[1].url + '/video-playlists/43'
76 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
78 expect(body.total).to.equal(0)
79 expect(body.data).to.be.an('array')
80 expect(body.data).to.have.lengthOf(0)
85 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
86 const body = await command.searchPlaylists({ search })
88 expect(body.total).to.equal(0)
89 expect(body.data).to.be.an('array')
90 expect(body.data).to.have.lengthOf(0)
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 })
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)
105 it('Should search a local playlist with an alternative URL', async function () {
107 servers[0].url + '/videos/watch/playlist/' + playlistServer1UUID,
108 servers[0].url + '/w/p/' + playlistServer1UUID
111 for (const search of searches) {
112 for (const token of [ undefined, servers[0].accessToken ]) {
113 const body = await command.searchPlaylists({ search, token })
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)
124 it('Should search a local playlist with a query in URL', async function () {
126 servers[0].url + '/videos/watch/playlist/' + playlistServer1UUID,
127 servers[0].url + '/w/p/' + playlistServer1UUID
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 })
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)
143 it('Should search a remote playlist', async function () {
145 servers[1].url + '/video-playlists/' + playlistServer2UUID,
146 servers[1].url + '/videos/watch/playlist/' + playlistServer2UUID,
147 servers[1].url + '/w/p/' + playlistServer2UUID
150 for (const search of searches) {
151 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
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)
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')
168 it('Should update the playlist of server 2, and refresh it on server 1', async function () {
171 await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId: video2Server2 } })
173 await waitJobs(servers)
177 // Will run refresh async
178 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
179 await command.searchPlaylists({ search, token: servers[0].accessToken })
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)
188 const playlist = body.data[0]
189 expect(playlist.videosLength).to.equal(2)
192 it('Should delete playlist of server 2, and delete it on server 1', async function () {
195 await servers[1].playlists.delete({ playlistId: playlistServer2UUID })
197 await waitJobs(servers)
201 // Will run refresh async
202 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
203 await command.searchPlaylists({ search, token: servers[0].accessToken })
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)
213 after(async function () {
214 await cleanupTests(servers)