]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import { expect } from 'chai' | |
4 | import { VideoPlaylistPrivacy } from '@shared/models' | |
5 | import { | |
6 | cleanupTests, | |
7 | createSingleServer, | |
8 | doubleFollow, | |
9 | PeerTubeServer, | |
10 | SearchCommand, | |
11 | setAccessTokensToServers, | |
12 | setDefaultAccountAvatar, | |
13 | setDefaultChannelAvatar, | |
14 | setDefaultVideoChannel | |
15 | } from '@shared/server-commands' | |
16 | ||
17 | describe('Test playlists search', function () { | |
18 | let server: PeerTubeServer | |
19 | let remoteServer: PeerTubeServer | |
20 | let command: SearchCommand | |
21 | let playlistUUID: string | |
22 | let playlistShortUUID: string | |
23 | ||
24 | before(async function () { | |
25 | this.timeout(120000) | |
26 | ||
27 | const servers = await Promise.all([ | |
28 | createSingleServer(1), | |
29 | createSingleServer(2) | |
30 | ]) | |
31 | server = servers[0] | |
32 | remoteServer = servers[1] | |
33 | ||
34 | await setAccessTokensToServers([ remoteServer, server ]) | |
35 | await setDefaultVideoChannel([ remoteServer, server ]) | |
36 | await setDefaultChannelAvatar([ remoteServer, server ]) | |
37 | await setDefaultAccountAvatar([ remoteServer, server ]) | |
38 | ||
39 | await servers[1].config.disableTranscoding() | |
40 | ||
41 | { | |
42 | const videoId = (await server.videos.upload()).uuid | |
43 | ||
44 | const attributes = { | |
45 | displayName: 'Dr. Kenzo Tenma hospital videos', | |
46 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
47 | videoChannelId: server.store.channel.id | |
48 | } | |
49 | const created = await server.playlists.create({ attributes }) | |
50 | playlistUUID = created.uuid | |
51 | playlistShortUUID = created.shortUUID | |
52 | ||
53 | await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } }) | |
54 | } | |
55 | ||
56 | { | |
57 | const videoId = (await remoteServer.videos.upload()).uuid | |
58 | ||
59 | const attributes = { | |
60 | displayName: 'Johan & Anna Libert music videos', | |
61 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
62 | videoChannelId: remoteServer.store.channel.id | |
63 | } | |
64 | const created = await remoteServer.playlists.create({ attributes }) | |
65 | ||
66 | await remoteServer.playlists.addElement({ playlistId: created.id, attributes: { videoId } }) | |
67 | } | |
68 | ||
69 | { | |
70 | const attributes = { | |
71 | displayName: 'Inspector Lunge playlist', | |
72 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
73 | videoChannelId: server.store.channel.id | |
74 | } | |
75 | await server.playlists.create({ attributes }) | |
76 | } | |
77 | ||
78 | await doubleFollow(server, remoteServer) | |
79 | ||
80 | command = server.search | |
81 | }) | |
82 | ||
83 | it('Should make a simple search and not have results', async function () { | |
84 | const body = await command.searchPlaylists({ search: 'abc' }) | |
85 | ||
86 | expect(body.total).to.equal(0) | |
87 | expect(body.data).to.have.lengthOf(0) | |
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 | } | |
97 | const body = await command.advancedPlaylistSearch({ search }) | |
98 | expect(body.total).to.equal(1) | |
99 | expect(body.data).to.have.lengthOf(1) | |
100 | ||
101 | const playlist = body.data[0] | |
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 = { | |
108 | search: 'Anna Livert music', | |
109 | start: 0, | |
110 | count: 1 | |
111 | } | |
112 | const body = await command.advancedPlaylistSearch({ search }) | |
113 | expect(body.total).to.equal(1) | |
114 | expect(body.data).to.have.lengthOf(1) | |
115 | ||
116 | const playlist = body.data[0] | |
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') | |
147 | } | |
148 | }) | |
149 | ||
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 | ||
166 | it('Should not display playlists without videos', async function () { | |
167 | const search = { | |
168 | search: 'Lunge', | |
169 | start: 0, | |
170 | count: 1 | |
171 | } | |
172 | const body = await command.advancedPlaylistSearch({ search }) | |
173 | expect(body.total).to.equal(0) | |
174 | expect(body.data).to.have.lengthOf(0) | |
175 | }) | |
176 | ||
177 | after(async function () { | |
178 | await cleanupTests([ server, remoteServer ]) | |
179 | }) | |
180 | }) |