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