]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - 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
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { VideoPlaylistPrivacy } from '@shared/models'
6import {
7 cleanupTests,
8 createSingleServer,
9 doubleFollow,
10 PeerTubeServer,
11 SearchCommand,
12 setAccessTokensToServers,
13 setDefaultAccountAvatar,
14 setDefaultChannelAvatar,
15 setDefaultVideoChannel
16} from '@shared/server-commands'
17
18const expect = chai.expect
19
20describe('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, { transcoding: { enabled: false } })
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 {
43 const videoId = (await server.videos.upload()).uuid
44
45 const attributes = {
46 displayName: 'Dr. Kenzo Tenma hospital videos',
47 privacy: VideoPlaylistPrivacy.PUBLIC,
48 videoChannelId: server.store.channel.id
49 }
50 const created = await server.playlists.create({ attributes })
51 playlistUUID = created.uuid
52 playlistShortUUID = created.shortUUID
53
54 await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
55 }
56
57 {
58 const videoId = (await remoteServer.videos.upload()).uuid
59
60 const attributes = {
61 displayName: 'Johan & Anna Libert music videos',
62 privacy: VideoPlaylistPrivacy.PUBLIC,
63 videoChannelId: remoteServer.store.channel.id
64 }
65 const created = await remoteServer.playlists.create({ attributes })
66
67 await remoteServer.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
68 }
69
70 {
71 const attributes = {
72 displayName: 'Inspector Lunge playlist',
73 privacy: VideoPlaylistPrivacy.PUBLIC,
74 videoChannelId: server.store.channel.id
75 }
76 await server.playlists.create({ attributes })
77 }
78
79 await doubleFollow(server, remoteServer)
80
81 command = server.search
82 })
83
84 it('Should make a simple search and not have results', async function () {
85 const body = await command.searchPlaylists({ search: 'abc' })
86
87 expect(body.total).to.equal(0)
88 expect(body.data).to.have.lengthOf(0)
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 }
98 const body = await command.advancedPlaylistSearch({ search })
99 expect(body.total).to.equal(1)
100 expect(body.data).to.have.lengthOf(1)
101
102 const playlist = body.data[0]
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 = {
109 search: 'Anna Livert music',
110 start: 0,
111 count: 1
112 }
113 const body = await command.advancedPlaylistSearch({ search })
114 expect(body.total).to.equal(1)
115 expect(body.data).to.have.lengthOf(1)
116
117 const playlist = body.data[0]
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')
148 }
149 })
150
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
167 it('Should not display playlists without videos', async function () {
168 const search = {
169 search: 'Lunge',
170 start: 0,
171 count: 1
172 }
173 const body = await command.advancedPlaylistSearch({ search })
174 expect(body.total).to.equal(0)
175 expect(body.data).to.have.lengthOf(0)
176 })
177
178 after(async function () {
179 await cleanupTests([ server, remoteServer ])
180 })
181})