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