1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 flushAndRunMultipleServers,
11 getVideoPlaylistsList,
14 setAccessTokensToServers,
15 setDefaultVideoChannel,
19 } from '@shared/extra-utils'
20 import { VideoPlaylistPrivacy } from '@shared/models'
22 const expect = chai.expect
24 describe('Test ActivityPub playlists search', function () {
25 let servers: ServerInfo[]
26 let playlistServer1UUID: string
27 let playlistServer2UUID: string
28 let video2Server2: string
30 let command: SearchCommand
32 before(async function () {
35 servers = await flushAndRunMultipleServers(2)
37 await setAccessTokensToServers(servers)
38 await setDefaultVideoChannel(servers)
41 const video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid
42 const video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid
45 displayName: 'playlist 1 on server 1',
46 privacy: VideoPlaylistPrivacy.PUBLIC,
47 videoChannelId: servers[0].videoChannel.id
49 const res = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs: attributes })
50 playlistServer1UUID = res.body.videoPlaylist.uuid
52 for (const videoId of [ video1, video2 ]) {
53 await addVideoInPlaylist({
55 token: servers[0].accessToken,
56 playlistId: playlistServer1UUID,
57 elementAttrs: { videoId }
63 const videoId = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 1' })).uuid
64 video2Server2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2' })).uuid
67 displayName: 'playlist 1 on server 2',
68 privacy: VideoPlaylistPrivacy.PUBLIC,
69 videoChannelId: servers[1].videoChannel.id
71 const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs: attributes })
72 playlistServer2UUID = res.body.videoPlaylist.uuid
74 await addVideoInPlaylist({
76 token: servers[1].accessToken,
77 playlistId: playlistServer2UUID,
78 elementAttrs: { videoId }
82 await waitJobs(servers)
84 command = servers[0].searchCommand
87 it('Should not find a remote playlist', async function () {
89 const search = 'http://localhost:' + servers[1].port + '/video-playlists/43'
90 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
92 expect(body.total).to.equal(0)
93 expect(body.data).to.be.an('array')
94 expect(body.data).to.have.lengthOf(0)
99 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID
100 const body = await command.searchPlaylists({ search })
102 expect(body.total).to.equal(0)
103 expect(body.data).to.be.an('array')
104 expect(body.data).to.have.lengthOf(0)
108 it('Should search a local playlist', async function () {
109 const search = 'http://localhost:' + servers[0].port + '/video-playlists/' + playlistServer1UUID
110 const body = await command.searchPlaylists({ search })
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)
119 it('Should search a local playlist with an alternative URL', async function () {
121 'http://localhost:' + servers[0].port + '/videos/watch/playlist/' + playlistServer1UUID,
122 'http://localhost:' + servers[0].port + '/w/p/' + playlistServer1UUID
125 for (const search of searches) {
126 for (const token of [ undefined, servers[0].accessToken ]) {
127 const body = await command.searchPlaylists({ search, token })
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)
138 it('Should search a remote playlist', async function () {
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
145 for (const search of searches) {
146 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
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)
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')
163 it('Should update the playlist of server 2, and refresh it on server 1', async function () {
166 await addVideoInPlaylist({
168 token: servers[1].accessToken,
169 playlistId: playlistServer2UUID,
170 elementAttrs: { videoId: video2Server2 }
173 await waitJobs(servers)
177 // Will run refresh async
178 const search = 'http://localhost:' + servers[1].port + '/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 deleteVideoPlaylist(servers[1].url, servers[1].accessToken, playlistServer2UUID)
197 await waitJobs(servers)
201 // Will run refresh async
202 const search = 'http://localhost:' + servers[1].port + '/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)