1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 setAccessTokensToServers,
11 setDefaultVideoChannel
12 } from '@shared/extra-utils'
13 import { VideoPlaylistPrivacy } from '@shared/models'
15 const expect = chai.expect
17 describe('Test playlists search', function () {
18 let server: PeerTubeServer = null
19 let command: SearchCommand
21 before(async function () {
24 server = await createSingleServer(1)
26 await setAccessTokensToServers([ server ])
27 await setDefaultVideoChannel([ server ])
29 const videoId = (await server.videos.quickUpload({ name: 'video' })).uuid
33 displayName: 'Dr. Kenzo Tenma hospital videos',
34 privacy: VideoPlaylistPrivacy.PUBLIC,
35 videoChannelId: server.store.channel.id
37 const created = await server.playlists.create({ attributes })
39 await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
44 displayName: 'Johan & Anna Libert musics',
45 privacy: VideoPlaylistPrivacy.PUBLIC,
46 videoChannelId: server.store.channel.id
48 const created = await server.playlists.create({ attributes })
50 await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
55 displayName: 'Inspector Lunge playlist',
56 privacy: VideoPlaylistPrivacy.PUBLIC,
57 videoChannelId: server.store.channel.id
59 await server.playlists.create({ attributes })
62 command = server.search
65 it('Should make a simple search and not have results', async function () {
66 const body = await command.searchPlaylists({ search: 'abc' })
68 expect(body.total).to.equal(0)
69 expect(body.data).to.have.lengthOf(0)
72 it('Should make a search and have results', async function () {
79 const body = await command.advancedPlaylistSearch({ search })
80 expect(body.total).to.equal(1)
81 expect(body.data).to.have.lengthOf(1)
83 const playlist = body.data[0]
84 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
85 expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid)
90 search: 'Anna Livert',
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('Johan & Anna Libert musics')
103 it('Should not display playlists without videos', async function () {
109 const body = await command.advancedPlaylistSearch({ search })
110 expect(body.total).to.equal(0)
111 expect(body.data).to.have.lengthOf(0)
114 after(async function () {
115 await cleanupTests([ server ])