]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/search/search-playlists.ts
Introduce stats command
[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 { VideoPlaylistPrivacy } from '@shared/models'
6 import {
7 addVideoInPlaylist,
8 cleanupTests,
9 createVideoPlaylist,
10 flushAndRunServer,
11 SearchCommand,
12 ServerInfo,
13 setAccessTokensToServers,
14 setDefaultVideoChannel,
15 uploadVideoAndGetId
16 } from '../../../../shared/extra-utils'
17
18 const expect = chai.expect
19
20 describe('Test playlists search', function () {
21 let server: ServerInfo = null
22 let command: SearchCommand
23
24 before(async function () {
25 this.timeout(30000)
26
27 server = await flushAndRunServer(1)
28
29 await setAccessTokensToServers([ server ])
30 await setDefaultVideoChannel([ server ])
31
32 const videoId = (await uploadVideoAndGetId({ server: server, videoName: 'video' })).uuid
33
34 {
35 const attributes = {
36 displayName: 'Dr. Kenzo Tenma hospital videos',
37 privacy: VideoPlaylistPrivacy.PUBLIC,
38 videoChannelId: server.videoChannel.id
39 }
40 const res = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes })
41
42 await addVideoInPlaylist({
43 url: server.url,
44 token: server.accessToken,
45 playlistId: res.body.videoPlaylist.id,
46 elementAttrs: { videoId }
47 })
48 }
49
50 {
51 const attributes = {
52 displayName: 'Johan & Anna Libert musics',
53 privacy: VideoPlaylistPrivacy.PUBLIC,
54 videoChannelId: server.videoChannel.id
55 }
56 const res = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes })
57
58 await addVideoInPlaylist({
59 url: server.url,
60 token: server.accessToken,
61 playlistId: res.body.videoPlaylist.id,
62 elementAttrs: { videoId }
63 })
64 }
65
66 {
67 const attributes = {
68 displayName: 'Inspector Lunge playlist',
69 privacy: VideoPlaylistPrivacy.PUBLIC,
70 videoChannelId: server.videoChannel.id
71 }
72 await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes })
73 }
74
75 command = server.searchCommand
76 })
77
78 it('Should make a simple search and not have results', async function () {
79 const body = await command.searchPlaylists({ search: 'abc' })
80
81 expect(body.total).to.equal(0)
82 expect(body.data).to.have.lengthOf(0)
83 })
84
85 it('Should make a search and have results', async function () {
86 {
87 const search = {
88 search: 'tenma',
89 start: 0,
90 count: 1
91 }
92 const body = await command.advancedPlaylistSearch({ search })
93 expect(body.total).to.equal(1)
94 expect(body.data).to.have.lengthOf(1)
95
96 const playlist = body.data[0]
97 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
98 expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid)
99 }
100
101 {
102 const search = {
103 search: 'Anna Livert',
104 start: 0,
105 count: 1
106 }
107 const body = await command.advancedPlaylistSearch({ search })
108 expect(body.total).to.equal(1)
109 expect(body.data).to.have.lengthOf(1)
110
111 const playlist = body.data[0]
112 expect(playlist.displayName).to.equal('Johan & Anna Libert musics')
113 }
114 })
115
116 it('Should not display playlists without videos', async function () {
117 const search = {
118 search: 'Lunge',
119 start: 0,
120 count: 1
121 }
122 const body = await command.advancedPlaylistSearch({ search })
123 expect(body.total).to.equal(0)
124 expect(body.data).to.have.lengthOf(0)
125 })
126
127 after(async function () {
128 await cleanupTests([ server ])
129 })
130 })