1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
11 setAccessTokensToServers,
12 setDefaultVideoChannel
13 } from '@shared/server-commands'
14 import { VideoPlaylistPrivacy } from '@shared/models'
16 const expect = chai.expect
18 describe('Test playlists search', function () {
19 let server: PeerTubeServer
20 let remoteServer: PeerTubeServer
21 let command: SearchCommand
22 let playlistUUID: string
23 let playlistShortUUID: string
25 before(async function () {
28 const servers = await Promise.all([
29 createSingleServer(1),
30 createSingleServer(2, { transcoding: { enabled: false } })
33 remoteServer = servers[1]
35 await setAccessTokensToServers([ remoteServer, server ])
36 await setDefaultVideoChannel([ remoteServer, server ])
39 const videoId = (await server.videos.upload()).uuid
42 displayName: 'Dr. Kenzo Tenma hospital videos',
43 privacy: VideoPlaylistPrivacy.PUBLIC,
44 videoChannelId: server.store.channel.id
46 const created = await server.playlists.create({ attributes })
47 playlistUUID = created.uuid
48 playlistShortUUID = created.shortUUID
50 await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
54 const videoId = (await remoteServer.videos.upload()).uuid
57 displayName: 'Johan & Anna Libert music videos',
58 privacy: VideoPlaylistPrivacy.PUBLIC,
59 videoChannelId: remoteServer.store.channel.id
61 const created = await remoteServer.playlists.create({ attributes })
63 await remoteServer.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
68 displayName: 'Inspector Lunge playlist',
69 privacy: VideoPlaylistPrivacy.PUBLIC,
70 videoChannelId: server.store.channel.id
72 await server.playlists.create({ attributes })
75 await doubleFollow(server, remoteServer)
77 command = server.search
80 it('Should make a simple search and not have results', async function () {
81 const body = await command.searchPlaylists({ search: 'abc' })
83 expect(body.total).to.equal(0)
84 expect(body.data).to.have.lengthOf(0)
87 it('Should make a search and have results', async function () {
94 const body = await command.advancedPlaylistSearch({ search })
95 expect(body.total).to.equal(1)
96 expect(body.data).to.have.lengthOf(1)
98 const playlist = body.data[0]
99 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
100 expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid)
105 search: 'Anna Livert music',
109 const body = await command.advancedPlaylistSearch({ search })
110 expect(body.total).to.equal(1)
111 expect(body.data).to.have.lengthOf(1)
113 const playlist = body.data[0]
114 expect(playlist.displayName).to.equal('Johan & Anna Libert music videos')
118 it('Should filter by host', async function () {
120 const search = { search: 'tenma', host: server.host }
121 const body = await command.advancedPlaylistSearch({ search })
122 expect(body.total).to.equal(1)
123 expect(body.data).to.have.lengthOf(1)
125 const playlist = body.data[0]
126 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
130 const search = { search: 'Anna', host: 'example.com' }
131 const body = await command.advancedPlaylistSearch({ search })
132 expect(body.total).to.equal(0)
133 expect(body.data).to.have.lengthOf(0)
137 const search = { search: 'video', host: remoteServer.host }
138 const body = await command.advancedPlaylistSearch({ search })
139 expect(body.total).to.equal(1)
140 expect(body.data).to.have.lengthOf(1)
142 const playlist = body.data[0]
143 expect(playlist.displayName).to.equal('Johan & Anna Libert music videos')
147 it('Should filter by UUIDs', async function () {
148 for (const uuid of [ playlistUUID, playlistShortUUID ]) {
149 const body = await command.advancedPlaylistSearch({ search: { uuids: [ uuid ] } })
151 expect(body.total).to.equal(1)
152 expect(body.data[0].displayName).to.equal('Dr. Kenzo Tenma hospital videos')
156 const body = await command.advancedPlaylistSearch({ search: { uuids: [ 'dfd70b83-639f-4980-94af-304a56ab4b35' ] } })
158 expect(body.total).to.equal(0)
159 expect(body.data).to.have.lengthOf(0)
163 it('Should not display playlists without videos', async function () {
169 const body = await command.advancedPlaylistSearch({ search })
170 expect(body.total).to.equal(0)
171 expect(body.data).to.have.lengthOf(0)
174 after(async function () {
175 await cleanupTests([ server, remoteServer ])