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