]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/search/search-playlists.ts
e7e53ff411afee0b1b2a88f9273b9b2975f1fa20
[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
23 before(async function () {
24 this.timeout(120000)
25
26 server = await createSingleServer(1)
27 remoteServer = await createSingleServer(2, { transcoding: { enabled: false } })
28
29 await setAccessTokensToServers([ remoteServer, server ])
30 await setDefaultVideoChannel([ remoteServer, server ])
31
32 {
33 const videoId = (await server.videos.upload()).uuid
34
35 const attributes = {
36 displayName: 'Dr. Kenzo Tenma hospital videos',
37 privacy: VideoPlaylistPrivacy.PUBLIC,
38 videoChannelId: server.store.channel.id
39 }
40 const created = await server.playlists.create({ attributes })
41
42 await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
43 }
44
45 {
46 const videoId = (await remoteServer.videos.upload()).uuid
47
48 const attributes = {
49 displayName: 'Johan & Anna Libert music videos',
50 privacy: VideoPlaylistPrivacy.PUBLIC,
51 videoChannelId: remoteServer.store.channel.id
52 }
53 const created = await remoteServer.playlists.create({ attributes })
54
55 await remoteServer.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
56 }
57
58 {
59 const attributes = {
60 displayName: 'Inspector Lunge playlist',
61 privacy: VideoPlaylistPrivacy.PUBLIC,
62 videoChannelId: server.store.channel.id
63 }
64 await server.playlists.create({ attributes })
65 }
66
67 await doubleFollow(server, remoteServer)
68
69 command = server.search
70 })
71
72 it('Should make a simple search and not have results', async function () {
73 const body = await command.searchPlaylists({ search: 'abc' })
74
75 expect(body.total).to.equal(0)
76 expect(body.data).to.have.lengthOf(0)
77 })
78
79 it('Should make a search and have results', async function () {
80 {
81 const search = {
82 search: 'tenma',
83 start: 0,
84 count: 1
85 }
86 const body = await command.advancedPlaylistSearch({ search })
87 expect(body.total).to.equal(1)
88 expect(body.data).to.have.lengthOf(1)
89
90 const playlist = body.data[0]
91 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
92 expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid)
93 }
94
95 {
96 const search = {
97 search: 'Anna Livert music',
98 start: 0,
99 count: 1
100 }
101 const body = await command.advancedPlaylistSearch({ search })
102 expect(body.total).to.equal(1)
103 expect(body.data).to.have.lengthOf(1)
104
105 const playlist = body.data[0]
106 expect(playlist.displayName).to.equal('Johan & Anna Libert music videos')
107 }
108 })
109
110 it('Should filter by host', async function () {
111 {
112 const search = { search: 'tenma', host: server.host }
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('Dr. Kenzo Tenma hospital videos')
119 }
120
121 {
122 const search = { search: 'Anna', host: 'example.com' }
123 const body = await command.advancedPlaylistSearch({ search })
124 expect(body.total).to.equal(0)
125 expect(body.data).to.have.lengthOf(0)
126 }
127
128 {
129 const search = { search: 'video', host: remoteServer.host }
130 const body = await command.advancedPlaylistSearch({ search })
131 expect(body.total).to.equal(1)
132 expect(body.data).to.have.lengthOf(1)
133
134 const playlist = body.data[0]
135 expect(playlist.displayName).to.equal('Johan & Anna Libert music videos')
136 }
137 })
138
139 it('Should not display playlists without videos', async function () {
140 const search = {
141 search: 'Lunge',
142 start: 0,
143 count: 1
144 }
145 const body = await command.advancedPlaylistSearch({ search })
146 expect(body.total).to.equal(0)
147 expect(body.data).to.have.lengthOf(0)
148 })
149
150 after(async function () {
151 await cleanupTests([ server ])
152 })
153 })