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