1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
7 flushAndRunMultipleServers,
10 setAccessTokensToServers,
11 setDefaultVideoChannel,
15 } from '@shared/extra-utils'
16 import { VideoPlaylistPrivacy } from '@shared/models'
18 const expect = chai.expect
20 describe('Test ActivityPub playlists search', function () {
21 let servers: ServerInfo[]
22 let playlistServer1UUID: string
23 let playlistServer2UUID: string
24 let video2Server2: string
26 let command: SearchCommand
28 before(async function () {
31 servers = await flushAndRunMultipleServers(2)
33 await setAccessTokensToServers(servers)
34 await setDefaultVideoChannel(servers)
37 const video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid
38 const video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid
41 displayName: 'playlist 1 on server 1',
42 privacy: VideoPlaylistPrivacy.PUBLIC,
43 videoChannelId: servers[0].videoChannel.id
45 const created = await servers[0].playlistsCommand.create({ attributes })
46 playlistServer1UUID = created.uuid
48 for (const videoId of [ video1, video2 ]) {
49 await servers[0].playlistsCommand.addElement({ playlistId: playlistServer1UUID, attributes: { videoId } })
54 const videoId = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 1' })).uuid
55 video2Server2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2' })).uuid
58 displayName: 'playlist 1 on server 2',
59 privacy: VideoPlaylistPrivacy.PUBLIC,
60 videoChannelId: servers[1].videoChannel.id
62 const created = await servers[1].playlistsCommand.create({ attributes })
63 playlistServer2UUID = created.uuid
65 await servers[1].playlistsCommand.addElement({ playlistId: playlistServer2UUID, attributes: { videoId } })
68 await waitJobs(servers)
70 command = servers[0].searchCommand
73 it('Should not find a remote playlist', async function () {
75 const search = 'http://localhost:' + servers[1].port + '/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 = 'http://localhost:' + servers[1].port + '/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 = 'http://localhost:' + servers[0].port + '/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 'http://localhost:' + servers[0].port + '/videos/watch/playlist/' + playlistServer1UUID,
108 'http://localhost:' + servers[0].port + '/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 remote playlist', async function () {
126 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID,
127 'http://localhost:' + servers[1].port + '/videos/watch/playlist/' + playlistServer2UUID,
128 'http://localhost:' + servers[1].port + '/w/p/' + playlistServer2UUID
131 for (const search of searches) {
132 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
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 2')
138 expect(body.data[0].videosLength).to.equal(1)
142 it('Should not list this remote playlist', async function () {
143 const body = await servers[0].playlistsCommand.list({ start: 0, count: 10 })
144 expect(body.total).to.equal(1)
145 expect(body.data).to.have.lengthOf(1)
146 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
149 it('Should update the playlist of server 2, and refresh it on server 1', async function () {
152 await servers[1].playlistsCommand.addElement({ playlistId: playlistServer2UUID, attributes: { videoId: video2Server2 } })
154 await waitJobs(servers)
158 // Will run refresh async
159 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID
160 await command.searchPlaylists({ search, token: servers[0].accessToken })
165 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
166 expect(body.total).to.equal(1)
167 expect(body.data).to.have.lengthOf(1)
169 const playlist = body.data[0]
170 expect(playlist.videosLength).to.equal(2)
173 it('Should delete playlist of server 2, and delete it on server 1', async function () {
176 await servers[1].playlistsCommand.delete({ playlistId: playlistServer2UUID })
178 await waitJobs(servers)
182 // Will run refresh async
183 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID
184 await command.searchPlaylists({ search, token: servers[0].accessToken })
189 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
190 expect(body.total).to.equal(0)
191 expect(body.data).to.have.lengthOf(0)
194 after(async function () {
195 await cleanupTests(servers)