]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/search/search-playlists.ts
Add ability to search by URL with query params
[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,
254d3579 7 createSingleServer,
fa47956e 8 doubleFollow,
254d3579 9 PeerTubeServer,
4c7e60bc 10 SearchCommand,
37a44fc9 11 setAccessTokensToServers,
d23dd9fb
C
12 setDefaultVideoChannel
13} from '@shared/extra-utils'
14import { VideoPlaylistPrivacy } from '@shared/models'
37a44fc9
C
15
16const expect = chai.expect
17
18describe('Test playlists search', function () {
fa47956e
C
19 let server: PeerTubeServer
20 let remoteServer: PeerTubeServer
af971e06 21 let command: SearchCommand
fbd67e7f
C
22 let playlistUUID: string
23 let playlistShortUUID: string
37a44fc9
C
24
25 before(async function () {
7bb52934 26 this.timeout(120000)
37a44fc9 27
fbd67e7f
C
28 const servers = await Promise.all([
29 createSingleServer(1),
30 createSingleServer(2, { transcoding: { enabled: false } })
31 ])
32 server = servers[0]
33 remoteServer = servers[1]
37a44fc9 34
fa47956e
C
35 await setAccessTokensToServers([ remoteServer, server ])
36 await setDefaultVideoChannel([ remoteServer, server ])
37a44fc9
C
37
38 {
fa47956e
C
39 const videoId = (await server.videos.upload()).uuid
40
37a44fc9
C
41 const attributes = {
42 displayName: 'Dr. Kenzo Tenma hospital videos',
43 privacy: VideoPlaylistPrivacy.PUBLIC,
89d241a7 44 videoChannelId: server.store.channel.id
37a44fc9 45 }
89d241a7 46 const created = await server.playlists.create({ attributes })
fbd67e7f
C
47 playlistUUID = created.uuid
48 playlistShortUUID = created.shortUUID
e6346d59 49
89d241a7 50 await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
37a44fc9
C
51 }
52
53 {
fa47956e
C
54 const videoId = (await remoteServer.videos.upload()).uuid
55
37a44fc9 56 const attributes = {
fa47956e 57 displayName: 'Johan & Anna Libert music videos',
37a44fc9 58 privacy: VideoPlaylistPrivacy.PUBLIC,
fa47956e 59 videoChannelId: remoteServer.store.channel.id
37a44fc9 60 }
fa47956e 61 const created = await remoteServer.playlists.create({ attributes })
e6346d59 62
fa47956e 63 await remoteServer.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
37a44fc9
C
64 }
65
66 {
67 const attributes = {
68 displayName: 'Inspector Lunge playlist',
69 privacy: VideoPlaylistPrivacy.PUBLIC,
89d241a7 70 videoChannelId: server.store.channel.id
37a44fc9 71 }
89d241a7 72 await server.playlists.create({ attributes })
37a44fc9 73 }
af971e06 74
fa47956e
C
75 await doubleFollow(server, remoteServer)
76
89d241a7 77 command = server.search
37a44fc9
C
78 })
79
80 it('Should make a simple search and not have results', async function () {
af971e06 81 const body = await command.searchPlaylists({ search: 'abc' })
37a44fc9 82
af971e06
C
83 expect(body.total).to.equal(0)
84 expect(body.data).to.have.lengthOf(0)
37a44fc9
C
85 })
86
87 it('Should make a search and have results', async function () {
88 {
89 const search = {
90 search: 'tenma',
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('Dr. Kenzo Tenma hospital videos')
100 expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid)
101 }
102
103 {
104 const search = {
fa47956e 105 search: 'Anna Livert music',
37a44fc9
C
106 start: 0,
107 count: 1
108 }
af971e06
C
109 const body = await command.advancedPlaylistSearch({ search })
110 expect(body.total).to.equal(1)
111 expect(body.data).to.have.lengthOf(1)
37a44fc9 112
af971e06 113 const playlist = body.data[0]
fa47956e
C
114 expect(playlist.displayName).to.equal('Johan & Anna Libert music videos')
115 }
116 })
117
118 it('Should filter by host', async function () {
119 {
120 const search = { search: 'tenma', host: server.host }
121 const body = await command.advancedPlaylistSearch({ search })
122 expect(body.total).to.equal(1)
123 expect(body.data).to.have.lengthOf(1)
124
125 const playlist = body.data[0]
126 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
127 }
128
129 {
130 const search = { search: 'Anna', host: 'example.com' }
131 const body = await command.advancedPlaylistSearch({ search })
132 expect(body.total).to.equal(0)
133 expect(body.data).to.have.lengthOf(0)
134 }
135
136 {
137 const search = { search: 'video', host: remoteServer.host }
138 const body = await command.advancedPlaylistSearch({ search })
139 expect(body.total).to.equal(1)
140 expect(body.data).to.have.lengthOf(1)
141
142 const playlist = body.data[0]
143 expect(playlist.displayName).to.equal('Johan & Anna Libert music videos')
37a44fc9
C
144 }
145 })
146
fbd67e7f
C
147 it('Should filter by UUIDs', async function () {
148 for (const uuid of [ playlistUUID, playlistShortUUID ]) {
149 const body = await command.advancedPlaylistSearch({ search: { uuids: [ uuid ] } })
150
151 expect(body.total).to.equal(1)
152 expect(body.data[0].displayName).to.equal('Dr. Kenzo Tenma hospital videos')
153 }
154
155 {
156 const body = await command.advancedPlaylistSearch({ search: { uuids: [ 'dfd70b83-639f-4980-94af-304a56ab4b35' ] } })
157
158 expect(body.total).to.equal(0)
159 expect(body.data).to.have.lengthOf(0)
160 }
161 })
162
37a44fc9
C
163 it('Should not display playlists without videos', async function () {
164 const search = {
165 search: 'Lunge',
166 start: 0,
167 count: 1
168 }
af971e06
C
169 const body = await command.advancedPlaylistSearch({ search })
170 expect(body.total).to.equal(0)
171 expect(body.data).to.have.lengthOf(0)
37a44fc9
C
172 })
173
174 after(async function () {
20c70876 175 await cleanupTests([ server, remoteServer ])
37a44fc9
C
176 })
177})