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/extra-utils'
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
23 before(async function () {
26 server = await createSingleServer(1)
27 remoteServer = await createSingleServer(2, { transcoding: { enabled: false } })
29 await setAccessTokensToServers([ remoteServer, server ])
30 await setDefaultVideoChannel([ remoteServer, server ])
33 const videoId = (await server.videos.upload()).uuid
36 displayName: 'Dr. Kenzo Tenma hospital videos',
37 privacy: VideoPlaylistPrivacy.PUBLIC,
38 videoChannelId: server.store.channel.id
40 const created = await server.playlists.create({ attributes })
42 await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
46 const videoId = (await remoteServer.videos.upload()).uuid
49 displayName: 'Johan & Anna Libert music videos',
50 privacy: VideoPlaylistPrivacy.PUBLIC,
51 videoChannelId: remoteServer.store.channel.id
53 const created = await remoteServer.playlists.create({ attributes })
55 await remoteServer.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
60 displayName: 'Inspector Lunge playlist',
61 privacy: VideoPlaylistPrivacy.PUBLIC,
62 videoChannelId: server.store.channel.id
64 await server.playlists.create({ attributes })
67 await doubleFollow(server, remoteServer)
69 command = server.search
72 it('Should make a simple search and not have results', async function () {
73 const body = await command.searchPlaylists({ search: 'abc' })
75 expect(body.total).to.equal(0)
76 expect(body.data).to.have.lengthOf(0)
79 it('Should make a search and have results', async function () {
86 const body = await command.advancedPlaylistSearch({ search })
87 expect(body.total).to.equal(1)
88 expect(body.data).to.have.lengthOf(1)
90 const playlist = body.data[0]
91 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
92 expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid)
97 search: 'Anna Livert music',
101 const body = await command.advancedPlaylistSearch({ search })
102 expect(body.total).to.equal(1)
103 expect(body.data).to.have.lengthOf(1)
105 const playlist = body.data[0]
106 expect(playlist.displayName).to.equal('Johan & Anna Libert music videos')
110 it('Should filter by host', async function () {
112 const search = { search: 'tenma', host: server.host }
113 const body = await command.advancedPlaylistSearch({ search })
114 expect(body.total).to.equal(1)
115 expect(body.data).to.have.lengthOf(1)
117 const playlist = body.data[0]
118 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
122 const search = { search: 'Anna', host: 'example.com' }
123 const body = await command.advancedPlaylistSearch({ search })
124 expect(body.total).to.equal(0)
125 expect(body.data).to.have.lengthOf(0)
129 const search = { search: 'video', host: remoteServer.host }
130 const body = await command.advancedPlaylistSearch({ search })
131 expect(body.total).to.equal(1)
132 expect(body.data).to.have.lengthOf(1)
134 const playlist = body.data[0]
135 expect(playlist.displayName).to.equal('Johan & Anna Libert music videos')
139 it('Should not display playlists without videos', async function () {
145 const body = await command.advancedPlaylistSearch({ search })
146 expect(body.total).to.equal(0)
147 expect(body.data).to.have.lengthOf(0)
150 after(async function () {
151 await cleanupTests([ server ])