]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/search/search-playlists.ts
Introduce playlist command
[github/Chocobozzz/PeerTube.git] / server / tests / api / search / search-playlists.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { VideoPlaylistPrivacy } from '@shared/models'
6 import {
7 cleanupTests,
8 flushAndRunServer,
9 SearchCommand,
10 ServerInfo,
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
13 uploadVideoAndGetId
14 } from '../../../../shared/extra-utils'
15
16 const expect = chai.expect
17
18 describe('Test playlists search', function () {
19 let server: ServerInfo = null
20 let command: SearchCommand
21
22 before(async function () {
23 this.timeout(30000)
24
25 server = await flushAndRunServer(1)
26
27 await setAccessTokensToServers([ server ])
28 await setDefaultVideoChannel([ server ])
29
30 const videoId = (await uploadVideoAndGetId({ server: server, videoName: 'video' })).uuid
31
32 {
33 const attributes = {
34 displayName: 'Dr. Kenzo Tenma hospital videos',
35 privacy: VideoPlaylistPrivacy.PUBLIC,
36 videoChannelId: server.videoChannel.id
37 }
38 const created = await server.playlistsCommand.create({ attributes })
39
40 await server.playlistsCommand.addElement({ playlistId: created.id, attributes: { videoId } })
41 }
42
43 {
44 const attributes = {
45 displayName: 'Johan & Anna Libert musics',
46 privacy: VideoPlaylistPrivacy.PUBLIC,
47 videoChannelId: server.videoChannel.id
48 }
49 const created = await server.playlistsCommand.create({ attributes })
50
51 await server.playlistsCommand.addElement({ playlistId: created.id, attributes: { videoId } })
52 }
53
54 {
55 const attributes = {
56 displayName: 'Inspector Lunge playlist',
57 privacy: VideoPlaylistPrivacy.PUBLIC,
58 videoChannelId: server.videoChannel.id
59 }
60 await server.playlistsCommand.create({ attributes })
61 }
62
63 command = server.searchCommand
64 })
65
66 it('Should make a simple search and not have results', async function () {
67 const body = await command.searchPlaylists({ search: 'abc' })
68
69 expect(body.total).to.equal(0)
70 expect(body.data).to.have.lengthOf(0)
71 })
72
73 it('Should make a search and have results', async function () {
74 {
75 const search = {
76 search: 'tenma',
77 start: 0,
78 count: 1
79 }
80 const body = await command.advancedPlaylistSearch({ search })
81 expect(body.total).to.equal(1)
82 expect(body.data).to.have.lengthOf(1)
83
84 const playlist = body.data[0]
85 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
86 expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid)
87 }
88
89 {
90 const search = {
91 search: 'Anna Livert',
92 start: 0,
93 count: 1
94 }
95 const body = await command.advancedPlaylistSearch({ search })
96 expect(body.total).to.equal(1)
97 expect(body.data).to.have.lengthOf(1)
98
99 const playlist = body.data[0]
100 expect(playlist.displayName).to.equal('Johan & Anna Libert musics')
101 }
102 })
103
104 it('Should not display playlists without videos', async function () {
105 const search = {
106 search: 'Lunge',
107 start: 0,
108 count: 1
109 }
110 const body = await command.advancedPlaylistSearch({ search })
111 expect(body.total).to.equal(0)
112 expect(body.data).to.have.lengthOf(0)
113 })
114
115 after(async function () {
116 await cleanupTests([ server ])
117 })
118 })