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