]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/search/search-playlists.ts
Update search index tests
[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'
37a44fc9 5import {
37a44fc9 6 cleanupTests,
254d3579 7 createSingleServer,
fa47956e 8 doubleFollow,
254d3579 9 PeerTubeServer,
4c7e60bc 10 SearchCommand,
37a44fc9 11 setAccessTokensToServers,
d23dd9fb
C
12 setDefaultVideoChannel
13} from '@shared/extra-utils'
14import { VideoPlaylistPrivacy } from '@shared/models'
37a44fc9
C
15
16const expect = chai.expect
17
18describe('Test playlists search', function () {
fa47956e
C
19 let server: PeerTubeServer
20 let remoteServer: PeerTubeServer
af971e06 21 let command: SearchCommand
37a44fc9
C
22
23 before(async function () {
7bb52934 24 this.timeout(120000)
37a44fc9 25
254d3579 26 server = await createSingleServer(1)
fa47956e 27 remoteServer = await createSingleServer(2, { transcoding: { enabled: false } })
37a44fc9 28
fa47956e
C
29 await setAccessTokensToServers([ remoteServer, server ])
30 await setDefaultVideoChannel([ remoteServer, server ])
37a44fc9
C
31
32 {
fa47956e
C
33 const videoId = (await server.videos.upload()).uuid
34
37a44fc9
C
35 const attributes = {
36 displayName: 'Dr. Kenzo Tenma hospital videos',
37 privacy: VideoPlaylistPrivacy.PUBLIC,
89d241a7 38 videoChannelId: server.store.channel.id
37a44fc9 39 }
89d241a7 40 const created = await server.playlists.create({ attributes })
e6346d59 41
89d241a7 42 await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
37a44fc9
C
43 }
44
45 {
fa47956e
C
46 const videoId = (await remoteServer.videos.upload()).uuid
47
37a44fc9 48 const attributes = {
fa47956e 49 displayName: 'Johan & Anna Libert music videos',
37a44fc9 50 privacy: VideoPlaylistPrivacy.PUBLIC,
fa47956e 51 videoChannelId: remoteServer.store.channel.id
37a44fc9 52 }
fa47956e 53 const created = await remoteServer.playlists.create({ attributes })
e6346d59 54
fa47956e 55 await remoteServer.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
37a44fc9
C
56 }
57
58 {
59 const attributes = {
60 displayName: 'Inspector Lunge playlist',
61 privacy: VideoPlaylistPrivacy.PUBLIC,
89d241a7 62 videoChannelId: server.store.channel.id
37a44fc9 63 }
89d241a7 64 await server.playlists.create({ attributes })
37a44fc9 65 }
af971e06 66
fa47956e
C
67 await doubleFollow(server, remoteServer)
68
89d241a7 69 command = server.search
37a44fc9
C
70 })
71
72 it('Should make a simple search and not have results', async function () {
af971e06 73 const body = await command.searchPlaylists({ search: 'abc' })
37a44fc9 74
af971e06
C
75 expect(body.total).to.equal(0)
76 expect(body.data).to.have.lengthOf(0)
37a44fc9
C
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 }
af971e06
C
86 const body = await command.advancedPlaylistSearch({ search })
87 expect(body.total).to.equal(1)
88 expect(body.data).to.have.lengthOf(1)
37a44fc9 89
af971e06 90 const playlist = body.data[0]
37a44fc9
C
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 = {
fa47956e 97 search: 'Anna Livert music',
37a44fc9
C
98 start: 0,
99 count: 1
100 }
af971e06
C
101 const body = await command.advancedPlaylistSearch({ search })
102 expect(body.total).to.equal(1)
103 expect(body.data).to.have.lengthOf(1)
37a44fc9 104
af971e06 105 const playlist = body.data[0]
fa47956e
C
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')
37a44fc9
C
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 }
af971e06
C
145 const body = await command.advancedPlaylistSearch({ search })
146 expect(body.total).to.equal(0)
147 expect(body.data).to.have.lengthOf(0)
37a44fc9
C
148 })
149
150 after(async function () {
151 await cleanupTests([ server ])
152 })
153})