1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { wait } from '@shared/core-utils'
6 import { VideoPlaylistPrivacy } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultAccountAvatar,
14 setDefaultVideoChannel,
16 } from '@shared/server-commands'
18 const expect = chai.expect
20 describe('Test ActivityPub playlists search', function () {
21 let servers: PeerTubeServer[]
22 let playlistServer1UUID: string
23 let playlistServer2UUID: string
24 let video2Server2: string
26 let command: SearchCommand
28 before(async function () {
31 servers = await createMultipleServers(2)
33 await setAccessTokensToServers(servers)
34 await setDefaultVideoChannel(servers)
35 await setDefaultAccountAvatar(servers)
38 const video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).uuid
39 const video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).uuid
42 displayName: 'playlist 1 on server 1',
43 privacy: VideoPlaylistPrivacy.PUBLIC,
44 videoChannelId: servers[0].store.channel.id
46 const created = await servers[0].playlists.create({ attributes })
47 playlistServer1UUID = created.uuid
49 for (const videoId of [ video1, video2 ]) {
50 await servers[0].playlists.addElement({ playlistId: playlistServer1UUID, attributes: { videoId } })
55 const videoId = (await servers[1].videos.quickUpload({ name: 'video 1' })).uuid
56 video2Server2 = (await servers[1].videos.quickUpload({ name: 'video 2' })).uuid
59 displayName: 'playlist 1 on server 2',
60 privacy: VideoPlaylistPrivacy.PUBLIC,
61 videoChannelId: servers[1].store.channel.id
63 const created = await servers[1].playlists.create({ attributes })
64 playlistServer2UUID = created.uuid
66 await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId } })
69 await waitJobs(servers)
71 command = servers[0].search
74 it('Should not find a remote playlist', async function () {
76 const search = servers[1].url + '/video-playlists/43'
77 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
79 expect(body.total).to.equal(0)
80 expect(body.data).to.be.an('array')
81 expect(body.data).to.have.lengthOf(0)
86 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
87 const body = await command.searchPlaylists({ search })
89 expect(body.total).to.equal(0)
90 expect(body.data).to.be.an('array')
91 expect(body.data).to.have.lengthOf(0)
95 it('Should search a local playlist', async function () {
96 const search = servers[0].url + '/video-playlists/' + playlistServer1UUID
97 const body = await command.searchPlaylists({ search })
99 expect(body.total).to.equal(1)
100 expect(body.data).to.be.an('array')
101 expect(body.data).to.have.lengthOf(1)
102 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
103 expect(body.data[0].videosLength).to.equal(2)
106 it('Should search a local playlist with an alternative URL', async function () {
108 servers[0].url + '/videos/watch/playlist/' + playlistServer1UUID,
109 servers[0].url + '/w/p/' + playlistServer1UUID
112 for (const search of searches) {
113 for (const token of [ undefined, servers[0].accessToken ]) {
114 const body = await command.searchPlaylists({ search, token })
116 expect(body.total).to.equal(1)
117 expect(body.data).to.be.an('array')
118 expect(body.data).to.have.lengthOf(1)
119 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
120 expect(body.data[0].videosLength).to.equal(2)
125 it('Should search a local playlist with a query in URL', async function () {
127 servers[0].url + '/videos/watch/playlist/' + playlistServer1UUID,
128 servers[0].url + '/w/p/' + playlistServer1UUID
131 for (const search of searches) {
132 for (const token of [ undefined, servers[0].accessToken ]) {
133 const body = await command.searchPlaylists({ search: search + '?param=1', token })
135 expect(body.total).to.equal(1)
136 expect(body.data).to.be.an('array')
137 expect(body.data).to.have.lengthOf(1)
138 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
139 expect(body.data[0].videosLength).to.equal(2)
144 it('Should search a remote playlist', async function () {
146 servers[1].url + '/video-playlists/' + playlistServer2UUID,
147 servers[1].url + '/videos/watch/playlist/' + playlistServer2UUID,
148 servers[1].url + '/w/p/' + playlistServer2UUID
151 for (const search of searches) {
152 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
154 expect(body.total).to.equal(1)
155 expect(body.data).to.be.an('array')
156 expect(body.data).to.have.lengthOf(1)
157 expect(body.data[0].displayName).to.equal('playlist 1 on server 2')
158 expect(body.data[0].videosLength).to.equal(1)
162 it('Should not list this remote playlist', async function () {
163 const body = await servers[0].playlists.list({ start: 0, count: 10 })
164 expect(body.total).to.equal(1)
165 expect(body.data).to.have.lengthOf(1)
166 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
169 it('Should update the playlist of server 2, and refresh it on server 1', async function () {
172 await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId: video2Server2 } })
174 await waitJobs(servers)
178 // Will run refresh async
179 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
180 await command.searchPlaylists({ search, token: servers[0].accessToken })
185 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
186 expect(body.total).to.equal(1)
187 expect(body.data).to.have.lengthOf(1)
189 const playlist = body.data[0]
190 expect(playlist.videosLength).to.equal(2)
193 it('Should delete playlist of server 2, and delete it on server 1', async function () {
196 await servers[1].playlists.delete({ playlistId: playlistServer2UUID })
198 await waitJobs(servers)
202 // Will run refresh async
203 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
204 await command.searchPlaylists({ search, token: servers[0].accessToken })
209 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
210 expect(body.total).to.equal(0)
211 expect(body.data).to.have.lengthOf(0)
214 after(async function () {
215 await cleanupTests(servers)