]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/search/search-playlists.ts
Add ability to search by uuids/actor names
[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 {
6 cleanupTests,
7 createSingleServer,
8 doubleFollow,
9 PeerTubeServer,
10 SearchCommand,
11 setAccessTokensToServers,
12 setDefaultVideoChannel
13 } from '@shared/extra-utils'
14 import { VideoPlaylistPrivacy } from '@shared/models'
15
16 const expect = chai.expect
17
18 describe('Test playlists search', function () {
19 let server: PeerTubeServer
20 let remoteServer: PeerTubeServer
21 let command: SearchCommand
22 let playlistUUID: string
23 let playlistShortUUID: string
24
25 before(async function () {
26 this.timeout(120000)
27
28 const servers = await Promise.all([
29 createSingleServer(1),
30 createSingleServer(2, { transcoding: { enabled: false } })
31 ])
32 server = servers[0]
33 remoteServer = servers[1]
34
35 await setAccessTokensToServers([ remoteServer, server ])
36 await setDefaultVideoChannel([ remoteServer, server ])
37
38 {
39 const videoId = (await server.videos.upload()).uuid
40
41 const attributes = {
42 displayName: 'Dr. Kenzo Tenma hospital videos',
43 privacy: VideoPlaylistPrivacy.PUBLIC,
44 videoChannelId: server.store.channel.id
45 }
46 const created = await server.playlists.create({ attributes })
47 playlistUUID = created.uuid
48 playlistShortUUID = created.shortUUID
49
50 await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
51 }
52
53 {
54 const videoId = (await remoteServer.videos.upload()).uuid
55
56 const attributes = {
57 displayName: 'Johan & Anna Libert music videos',
58 privacy: VideoPlaylistPrivacy.PUBLIC,
59 videoChannelId: remoteServer.store.channel.id
60 }
61 const created = await remoteServer.playlists.create({ attributes })
62
63 await remoteServer.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
64 }
65
66 {
67 const attributes = {
68 displayName: 'Inspector Lunge playlist',
69 privacy: VideoPlaylistPrivacy.PUBLIC,
70 videoChannelId: server.store.channel.id
71 }
72 await server.playlists.create({ attributes })
73 }
74
75 await doubleFollow(server, remoteServer)
76
77 command = server.search
78 })
79
80 it('Should make a simple search and not have results', async function () {
81 const body = await command.searchPlaylists({ search: 'abc' })
82
83 expect(body.total).to.equal(0)
84 expect(body.data).to.have.lengthOf(0)
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 }
94 const body = await command.advancedPlaylistSearch({ search })
95 expect(body.total).to.equal(1)
96 expect(body.data).to.have.lengthOf(1)
97
98 const playlist = body.data[0]
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 = {
105 search: 'Anna Livert music',
106 start: 0,
107 count: 1
108 }
109 const body = await command.advancedPlaylistSearch({ search })
110 expect(body.total).to.equal(1)
111 expect(body.data).to.have.lengthOf(1)
112
113 const playlist = body.data[0]
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')
144 }
145 })
146
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
163 it('Should not display playlists without videos', async function () {
164 const search = {
165 search: 'Lunge',
166 start: 0,
167 count: 1
168 }
169 const body = await command.advancedPlaylistSearch({ search })
170 expect(body.total).to.equal(0)
171 expect(body.data).to.have.lengthOf(0)
172 })
173
174 after(async function () {
175 await cleanupTests([ server ])
176 })
177 })