1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } 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 describe('Test ActivityPub playlists search', function () {
18 let servers: PeerTubeServer[]
19 let playlistServer1UUID: string
20 let playlistServer2UUID: string
21 let video2Server2: string
23 let command: SearchCommand
25 before(async function () {
28 servers = await createMultipleServers(2)
30 await setAccessTokensToServers(servers)
31 await setDefaultVideoChannel(servers)
32 await setDefaultAccountAvatar(servers)
35 const video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).uuid
36 const video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).uuid
39 displayName: 'playlist 1 on server 1',
40 privacy: VideoPlaylistPrivacy.PUBLIC,
41 videoChannelId: servers[0].store.channel.id
43 const created = await servers[0].playlists.create({ attributes })
44 playlistServer1UUID = created.uuid
46 for (const videoId of [ video1, video2 ]) {
47 await servers[0].playlists.addElement({ playlistId: playlistServer1UUID, attributes: { videoId } })
52 const videoId = (await servers[1].videos.quickUpload({ name: 'video 1' })).uuid
53 video2Server2 = (await servers[1].videos.quickUpload({ name: 'video 2' })).uuid
56 displayName: 'playlist 1 on server 2',
57 privacy: VideoPlaylistPrivacy.PUBLIC,
58 videoChannelId: servers[1].store.channel.id
60 const created = await servers[1].playlists.create({ attributes })
61 playlistServer2UUID = created.uuid
63 await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId } })
66 await waitJobs(servers)
68 command = servers[0].search
71 it('Should not find a remote playlist', async function () {
73 const search = servers[1].url + '/video-playlists/43'
74 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
76 expect(body.total).to.equal(0)
77 expect(body.data).to.be.an('array')
78 expect(body.data).to.have.lengthOf(0)
83 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
84 const body = await command.searchPlaylists({ search })
86 expect(body.total).to.equal(0)
87 expect(body.data).to.be.an('array')
88 expect(body.data).to.have.lengthOf(0)
92 it('Should search a local playlist', async function () {
93 const search = servers[0].url + '/video-playlists/' + playlistServer1UUID
94 const body = await command.searchPlaylists({ search })
96 expect(body.total).to.equal(1)
97 expect(body.data).to.be.an('array')
98 expect(body.data).to.have.lengthOf(1)
99 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
100 expect(body.data[0].videosLength).to.equal(2)
103 it('Should search a local playlist with an alternative URL', async function () {
105 servers[0].url + '/videos/watch/playlist/' + playlistServer1UUID,
106 servers[0].url + '/w/p/' + playlistServer1UUID
109 for (const search of searches) {
110 for (const token of [ undefined, servers[0].accessToken ]) {
111 const body = await command.searchPlaylists({ search, token })
113 expect(body.total).to.equal(1)
114 expect(body.data).to.be.an('array')
115 expect(body.data).to.have.lengthOf(1)
116 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
117 expect(body.data[0].videosLength).to.equal(2)
122 it('Should search a local playlist with a query in URL', async function () {
124 servers[0].url + '/videos/watch/playlist/' + playlistServer1UUID,
125 servers[0].url + '/w/p/' + playlistServer1UUID
128 for (const search of searches) {
129 for (const token of [ undefined, servers[0].accessToken ]) {
130 const body = await command.searchPlaylists({ search: search + '?param=1', token })
132 expect(body.total).to.equal(1)
133 expect(body.data).to.be.an('array')
134 expect(body.data).to.have.lengthOf(1)
135 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
136 expect(body.data[0].videosLength).to.equal(2)
141 it('Should search a remote playlist', async function () {
143 servers[1].url + '/video-playlists/' + playlistServer2UUID,
144 servers[1].url + '/videos/watch/playlist/' + playlistServer2UUID,
145 servers[1].url + '/w/p/' + playlistServer2UUID
148 for (const search of searches) {
149 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
151 expect(body.total).to.equal(1)
152 expect(body.data).to.be.an('array')
153 expect(body.data).to.have.lengthOf(1)
154 expect(body.data[0].displayName).to.equal('playlist 1 on server 2')
155 expect(body.data[0].videosLength).to.equal(1)
159 it('Should not list this remote playlist', async function () {
160 const body = await servers[0].playlists.list({ start: 0, count: 10 })
161 expect(body.total).to.equal(1)
162 expect(body.data).to.have.lengthOf(1)
163 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
166 it('Should update the playlist of server 2, and refresh it on server 1', async function () {
169 await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId: video2Server2 } })
171 await waitJobs(servers)
175 // Will run refresh async
176 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
177 await command.searchPlaylists({ search, token: servers[0].accessToken })
182 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
183 expect(body.total).to.equal(1)
184 expect(body.data).to.have.lengthOf(1)
186 const playlist = body.data[0]
187 expect(playlist.videosLength).to.equal(2)
190 it('Should delete playlist of server 2, and delete it on server 1', async function () {
193 await servers[1].playlists.delete({ playlistId: playlistServer2UUID })
195 await waitJobs(servers)
199 // Will run refresh async
200 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
201 await command.searchPlaylists({ search, token: servers[0].accessToken })
206 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
207 expect(body.total).to.equal(0)
208 expect(body.data).to.have.lengthOf(0)
211 after(async function () {
212 await cleanupTests(servers)