1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { VideoPlaylistPrivacy } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultAccountAvatar,
13 setDefaultChannelAvatar,
14 setDefaultVideoChannel
15 } from '@shared/server-commands'
17 describe('Test playlists search', function () {
18 let server: PeerTubeServer
19 let remoteServer: PeerTubeServer
20 let command: SearchCommand
21 let playlistUUID: string
22 let playlistShortUUID: string
24 before(async function () {
27 const servers = await Promise.all([
28 createSingleServer(1),
32 remoteServer = servers[1]
34 await setAccessTokensToServers([ remoteServer, server ])
35 await setDefaultVideoChannel([ remoteServer, server ])
36 await setDefaultChannelAvatar([ remoteServer, server ])
37 await setDefaultAccountAvatar([ remoteServer, server ])
39 await servers[1].config.disableTranscoding()
42 const videoId = (await server.videos.upload()).uuid
45 displayName: 'Dr. Kenzo Tenma hospital videos',
46 privacy: VideoPlaylistPrivacy.PUBLIC,
47 videoChannelId: server.store.channel.id
49 const created = await server.playlists.create({ attributes })
50 playlistUUID = created.uuid
51 playlistShortUUID = created.shortUUID
53 await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
57 const videoId = (await remoteServer.videos.upload()).uuid
60 displayName: 'Johan & Anna Libert music videos',
61 privacy: VideoPlaylistPrivacy.PUBLIC,
62 videoChannelId: remoteServer.store.channel.id
64 const created = await remoteServer.playlists.create({ attributes })
66 await remoteServer.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
71 displayName: 'Inspector Lunge playlist',
72 privacy: VideoPlaylistPrivacy.PUBLIC,
73 videoChannelId: server.store.channel.id
75 await server.playlists.create({ attributes })
78 await doubleFollow(server, remoteServer)
80 command = server.search
83 it('Should make a simple search and not have results', async function () {
84 const body = await command.searchPlaylists({ search: 'abc' })
86 expect(body.total).to.equal(0)
87 expect(body.data).to.have.lengthOf(0)
90 it('Should make a search and have results', async function () {
97 const body = await command.advancedPlaylistSearch({ search })
98 expect(body.total).to.equal(1)
99 expect(body.data).to.have.lengthOf(1)
101 const playlist = body.data[0]
102 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
103 expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid)
108 search: 'Anna Livert music',
112 const body = await command.advancedPlaylistSearch({ search })
113 expect(body.total).to.equal(1)
114 expect(body.data).to.have.lengthOf(1)
116 const playlist = body.data[0]
117 expect(playlist.displayName).to.equal('Johan & Anna Libert music videos')
121 it('Should filter by host', async function () {
123 const search = { search: 'tenma', host: server.host }
124 const body = await command.advancedPlaylistSearch({ search })
125 expect(body.total).to.equal(1)
126 expect(body.data).to.have.lengthOf(1)
128 const playlist = body.data[0]
129 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
133 const search = { search: 'Anna', host: 'example.com' }
134 const body = await command.advancedPlaylistSearch({ search })
135 expect(body.total).to.equal(0)
136 expect(body.data).to.have.lengthOf(0)
140 const search = { search: 'video', host: remoteServer.host }
141 const body = await command.advancedPlaylistSearch({ search })
142 expect(body.total).to.equal(1)
143 expect(body.data).to.have.lengthOf(1)
145 const playlist = body.data[0]
146 expect(playlist.displayName).to.equal('Johan & Anna Libert music videos')
150 it('Should filter by UUIDs', async function () {
151 for (const uuid of [ playlistUUID, playlistShortUUID ]) {
152 const body = await command.advancedPlaylistSearch({ search: { uuids: [ uuid ] } })
154 expect(body.total).to.equal(1)
155 expect(body.data[0].displayName).to.equal('Dr. Kenzo Tenma hospital videos')
159 const body = await command.advancedPlaylistSearch({ search: { uuids: [ 'dfd70b83-639f-4980-94af-304a56ab4b35' ] } })
161 expect(body.total).to.equal(0)
162 expect(body.data).to.have.lengthOf(0)
166 it('Should not display playlists without videos', async function () {
172 const body = await command.advancedPlaylistSearch({ search })
173 expect(body.total).to.equal(0)
174 expect(body.data).to.have.lengthOf(0)
177 after(async function () {
178 await cleanupTests([ server, remoteServer ])