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