1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
4 import { VideoPlaylistPrivacy } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultAccountAvatar,
13 setDefaultChannelAvatar,
14 setDefaultVideoChannel
15 } from '@shared/server-commands'
17 const expect = chai.expect
19 describe('Test playlists search', function () {
20 let server: PeerTubeServer
21 let remoteServer: PeerTubeServer
22 let command: SearchCommand
23 let playlistUUID: string
24 let playlistShortUUID: string
26 before(async function () {
29 const servers = await Promise.all([
30 createSingleServer(1),
34 remoteServer = servers[1]
36 await setAccessTokensToServers([ remoteServer, server ])
37 await setDefaultVideoChannel([ remoteServer, server ])
38 await setDefaultChannelAvatar([ remoteServer, server ])
39 await setDefaultAccountAvatar([ remoteServer, server ])
41 await servers[1].config.disableTranscoding()
44 const videoId = (await server.videos.upload()).uuid
47 displayName: 'Dr. Kenzo Tenma hospital videos',
48 privacy: VideoPlaylistPrivacy.PUBLIC,
49 videoChannelId: server.store.channel.id
51 const created = await server.playlists.create({ attributes })
52 playlistUUID = created.uuid
53 playlistShortUUID = created.shortUUID
55 await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
59 const videoId = (await remoteServer.videos.upload()).uuid
62 displayName: 'Johan & Anna Libert music videos',
63 privacy: VideoPlaylistPrivacy.PUBLIC,
64 videoChannelId: remoteServer.store.channel.id
66 const created = await remoteServer.playlists.create({ attributes })
68 await remoteServer.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
73 displayName: 'Inspector Lunge playlist',
74 privacy: VideoPlaylistPrivacy.PUBLIC,
75 videoChannelId: server.store.channel.id
77 await server.playlists.create({ attributes })
80 await doubleFollow(server, remoteServer)
82 command = server.search
85 it('Should make a simple search and not have results', async function () {
86 const body = await command.searchPlaylists({ search: 'abc' })
88 expect(body.total).to.equal(0)
89 expect(body.data).to.have.lengthOf(0)
92 it('Should make a search and have results', async function () {
99 const body = await command.advancedPlaylistSearch({ search })
100 expect(body.total).to.equal(1)
101 expect(body.data).to.have.lengthOf(1)
103 const playlist = body.data[0]
104 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
105 expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid)
110 search: 'Anna Livert music',
114 const body = await command.advancedPlaylistSearch({ search })
115 expect(body.total).to.equal(1)
116 expect(body.data).to.have.lengthOf(1)
118 const playlist = body.data[0]
119 expect(playlist.displayName).to.equal('Johan & Anna Libert music videos')
123 it('Should filter by host', async function () {
125 const search = { search: 'tenma', host: server.host }
126 const body = await command.advancedPlaylistSearch({ search })
127 expect(body.total).to.equal(1)
128 expect(body.data).to.have.lengthOf(1)
130 const playlist = body.data[0]
131 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
135 const search = { search: 'Anna', host: 'example.com' }
136 const body = await command.advancedPlaylistSearch({ search })
137 expect(body.total).to.equal(0)
138 expect(body.data).to.have.lengthOf(0)
142 const search = { search: 'video', host: remoteServer.host }
143 const body = await command.advancedPlaylistSearch({ search })
144 expect(body.total).to.equal(1)
145 expect(body.data).to.have.lengthOf(1)
147 const playlist = body.data[0]
148 expect(playlist.displayName).to.equal('Johan & Anna Libert music videos')
152 it('Should filter by UUIDs', async function () {
153 for (const uuid of [ playlistUUID, playlistShortUUID ]) {
154 const body = await command.advancedPlaylistSearch({ search: { uuids: [ uuid ] } })
156 expect(body.total).to.equal(1)
157 expect(body.data[0].displayName).to.equal('Dr. Kenzo Tenma hospital videos')
161 const body = await command.advancedPlaylistSearch({ search: { uuids: [ 'dfd70b83-639f-4980-94af-304a56ab4b35' ] } })
163 expect(body.total).to.equal(0)
164 expect(body.data).to.have.lengthOf(0)
168 it('Should not display playlists without videos', async function () {
174 const body = await command.advancedPlaylistSearch({ search })
175 expect(body.total).to.equal(0)
176 expect(body.data).to.have.lengthOf(0)
179 after(async function () {
180 await cleanupTests([ server, remoteServer ])