1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { VideoPlaylistPrivacy } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultAccountAvatar,
14 setDefaultChannelAvatar,
15 setDefaultVideoChannel
16 } from '@shared/server-commands'
18 const expect = chai.expect
20 describe('Test playlists search', function () {
21 let server: PeerTubeServer
22 let remoteServer: PeerTubeServer
23 let command: SearchCommand
24 let playlistUUID: string
25 let playlistShortUUID: string
27 before(async function () {
30 const servers = await Promise.all([
31 createSingleServer(1),
35 remoteServer = servers[1]
37 await setAccessTokensToServers([ remoteServer, server ])
38 await setDefaultVideoChannel([ remoteServer, server ])
39 await setDefaultChannelAvatar([ remoteServer, server ])
40 await setDefaultAccountAvatar([ remoteServer, server ])
42 await servers[1].config.disableTranscoding()
45 const videoId = (await server.videos.upload()).uuid
48 displayName: 'Dr. Kenzo Tenma hospital videos',
49 privacy: VideoPlaylistPrivacy.PUBLIC,
50 videoChannelId: server.store.channel.id
52 const created = await server.playlists.create({ attributes })
53 playlistUUID = created.uuid
54 playlistShortUUID = created.shortUUID
56 await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
60 const videoId = (await remoteServer.videos.upload()).uuid
63 displayName: 'Johan & Anna Libert music videos',
64 privacy: VideoPlaylistPrivacy.PUBLIC,
65 videoChannelId: remoteServer.store.channel.id
67 const created = await remoteServer.playlists.create({ attributes })
69 await remoteServer.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
74 displayName: 'Inspector Lunge playlist',
75 privacy: VideoPlaylistPrivacy.PUBLIC,
76 videoChannelId: server.store.channel.id
78 await server.playlists.create({ attributes })
81 await doubleFollow(server, remoteServer)
83 command = server.search
86 it('Should make a simple search and not have results', async function () {
87 const body = await command.searchPlaylists({ search: 'abc' })
89 expect(body.total).to.equal(0)
90 expect(body.data).to.have.lengthOf(0)
93 it('Should make a search and have results', async function () {
100 const body = await command.advancedPlaylistSearch({ search })
101 expect(body.total).to.equal(1)
102 expect(body.data).to.have.lengthOf(1)
104 const playlist = body.data[0]
105 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
106 expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid)
111 search: 'Anna Livert music',
115 const body = await command.advancedPlaylistSearch({ search })
116 expect(body.total).to.equal(1)
117 expect(body.data).to.have.lengthOf(1)
119 const playlist = body.data[0]
120 expect(playlist.displayName).to.equal('Johan & Anna Libert music videos')
124 it('Should filter by host', async function () {
126 const search = { search: 'tenma', host: server.host }
127 const body = await command.advancedPlaylistSearch({ search })
128 expect(body.total).to.equal(1)
129 expect(body.data).to.have.lengthOf(1)
131 const playlist = body.data[0]
132 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
136 const search = { search: 'Anna', host: 'example.com' }
137 const body = await command.advancedPlaylistSearch({ search })
138 expect(body.total).to.equal(0)
139 expect(body.data).to.have.lengthOf(0)
143 const search = { search: 'video', host: remoteServer.host }
144 const body = await command.advancedPlaylistSearch({ search })
145 expect(body.total).to.equal(1)
146 expect(body.data).to.have.lengthOf(1)
148 const playlist = body.data[0]
149 expect(playlist.displayName).to.equal('Johan & Anna Libert music videos')
153 it('Should filter by UUIDs', async function () {
154 for (const uuid of [ playlistUUID, playlistShortUUID ]) {
155 const body = await command.advancedPlaylistSearch({ search: { uuids: [ uuid ] } })
157 expect(body.total).to.equal(1)
158 expect(body.data[0].displayName).to.equal('Dr. Kenzo Tenma hospital videos')
162 const body = await command.advancedPlaylistSearch({ search: { uuids: [ 'dfd70b83-639f-4980-94af-304a56ab4b35' ] } })
164 expect(body.total).to.equal(0)
165 expect(body.data).to.have.lengthOf(0)
169 it('Should not display playlists without videos', async function () {
175 const body = await command.advancedPlaylistSearch({ search })
176 expect(body.total).to.equal(0)
177 expect(body.data).to.have.lengthOf(0)
180 after(async function () {
181 await cleanupTests([ server, remoteServer ])