]>
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' | |
c55e3d72 C |
5 | import { wait } from '@shared/core-utils' |
6 | import { VideoPlaylistPrivacy } from '@shared/models' | |
37a44fc9 | 7 | import { |
37a44fc9 | 8 | cleanupTests, |
254d3579 | 9 | createMultipleServers, |
254d3579 | 10 | PeerTubeServer, |
4c7e60bc | 11 | SearchCommand, |
37a44fc9 | 12 | setAccessTokensToServers, |
d0800f76 | 13 | setDefaultAccountAvatar, |
37a44fc9 | 14 | setDefaultVideoChannel, |
af971e06 | 15 | waitJobs |
bf54587a | 16 | } from '@shared/server-commands' |
37a44fc9 C |
17 | |
18 | const expect = chai.expect | |
19 | ||
20 | describe('Test ActivityPub playlists search', function () { | |
254d3579 | 21 | let servers: PeerTubeServer[] |
37a44fc9 C |
22 | let playlistServer1UUID: string |
23 | let playlistServer2UUID: string | |
24 | let video2Server2: string | |
25 | ||
af971e06 C |
26 | let command: SearchCommand |
27 | ||
37a44fc9 C |
28 | before(async function () { |
29 | this.timeout(120000) | |
30 | ||
254d3579 | 31 | servers = await createMultipleServers(2) |
37a44fc9 C |
32 | |
33 | await setAccessTokensToServers(servers) | |
34 | await setDefaultVideoChannel(servers) | |
d0800f76 | 35 | await setDefaultAccountAvatar(servers) |
37a44fc9 C |
36 | |
37 | { | |
89d241a7 C |
38 | const video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).uuid |
39 | const video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).uuid | |
37a44fc9 C |
40 | |
41 | const attributes = { | |
42 | displayName: 'playlist 1 on server 1', | |
43 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
89d241a7 | 44 | videoChannelId: servers[0].store.channel.id |
37a44fc9 | 45 | } |
89d241a7 | 46 | const created = await servers[0].playlists.create({ attributes }) |
e6346d59 | 47 | playlistServer1UUID = created.uuid |
37a44fc9 C |
48 | |
49 | for (const videoId of [ video1, video2 ]) { | |
89d241a7 | 50 | await servers[0].playlists.addElement({ playlistId: playlistServer1UUID, attributes: { videoId } }) |
37a44fc9 C |
51 | } |
52 | } | |
53 | ||
54 | { | |
89d241a7 C |
55 | const videoId = (await servers[1].videos.quickUpload({ name: 'video 1' })).uuid |
56 | video2Server2 = (await servers[1].videos.quickUpload({ name: 'video 2' })).uuid | |
37a44fc9 C |
57 | |
58 | const attributes = { | |
59 | displayName: 'playlist 1 on server 2', | |
60 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
89d241a7 | 61 | videoChannelId: servers[1].store.channel.id |
37a44fc9 | 62 | } |
89d241a7 | 63 | const created = await servers[1].playlists.create({ attributes }) |
e6346d59 C |
64 | playlistServer2UUID = created.uuid |
65 | ||
89d241a7 | 66 | await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId } }) |
37a44fc9 C |
67 | } |
68 | ||
69 | await waitJobs(servers) | |
af971e06 | 70 | |
89d241a7 | 71 | command = servers[0].search |
37a44fc9 C |
72 | }) |
73 | ||
74 | it('Should not find a remote playlist', async function () { | |
75 | { | |
400043b1 | 76 | const search = servers[1].url + '/video-playlists/43' |
af971e06 | 77 | const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) |
37a44fc9 | 78 | |
af971e06 C |
79 | expect(body.total).to.equal(0) |
80 | expect(body.data).to.be.an('array') | |
81 | expect(body.data).to.have.lengthOf(0) | |
37a44fc9 C |
82 | } |
83 | ||
84 | { | |
85 | // Without token | |
400043b1 | 86 | const search = servers[1].url + '/video-playlists/' + playlistServer2UUID |
af971e06 | 87 | const body = await command.searchPlaylists({ search }) |
37a44fc9 | 88 | |
af971e06 C |
89 | expect(body.total).to.equal(0) |
90 | expect(body.data).to.be.an('array') | |
91 | expect(body.data).to.have.lengthOf(0) | |
37a44fc9 C |
92 | } |
93 | }) | |
94 | ||
95 | it('Should search a local playlist', async function () { | |
400043b1 | 96 | const search = servers[0].url + '/video-playlists/' + playlistServer1UUID |
af971e06 | 97 | const body = await command.searchPlaylists({ search }) |
37a44fc9 | 98 | |
af971e06 C |
99 | expect(body.total).to.equal(1) |
100 | expect(body.data).to.be.an('array') | |
101 | expect(body.data).to.have.lengthOf(1) | |
102 | expect(body.data[0].displayName).to.equal('playlist 1 on server 1') | |
103 | expect(body.data[0].videosLength).to.equal(2) | |
37a44fc9 C |
104 | }) |
105 | ||
106 | it('Should search a local playlist with an alternative URL', async function () { | |
107 | const searches = [ | |
400043b1 C |
108 | servers[0].url + '/videos/watch/playlist/' + playlistServer1UUID, |
109 | servers[0].url + '/w/p/' + playlistServer1UUID | |
37a44fc9 C |
110 | ] |
111 | ||
112 | for (const search of searches) { | |
113 | for (const token of [ undefined, servers[0].accessToken ]) { | |
af971e06 | 114 | const body = await command.searchPlaylists({ search, token }) |
37a44fc9 | 115 | |
af971e06 C |
116 | expect(body.total).to.equal(1) |
117 | expect(body.data).to.be.an('array') | |
118 | expect(body.data).to.have.lengthOf(1) | |
119 | expect(body.data[0].displayName).to.equal('playlist 1 on server 1') | |
120 | expect(body.data[0].videosLength).to.equal(2) | |
37a44fc9 C |
121 | } |
122 | } | |
123 | }) | |
124 | ||
400043b1 C |
125 | it('Should search a local playlist with a query in URL', async function () { |
126 | const searches = [ | |
127 | servers[0].url + '/videos/watch/playlist/' + playlistServer1UUID, | |
128 | servers[0].url + '/w/p/' + playlistServer1UUID | |
129 | ] | |
130 | ||
131 | for (const search of searches) { | |
132 | for (const token of [ undefined, servers[0].accessToken ]) { | |
133 | const body = await command.searchPlaylists({ search: search + '?param=1', token }) | |
134 | ||
135 | expect(body.total).to.equal(1) | |
136 | expect(body.data).to.be.an('array') | |
137 | expect(body.data).to.have.lengthOf(1) | |
138 | expect(body.data[0].displayName).to.equal('playlist 1 on server 1') | |
139 | expect(body.data[0].videosLength).to.equal(2) | |
140 | } | |
141 | } | |
142 | }) | |
143 | ||
37a44fc9 C |
144 | it('Should search a remote playlist', async function () { |
145 | const searches = [ | |
400043b1 C |
146 | servers[1].url + '/video-playlists/' + playlistServer2UUID, |
147 | servers[1].url + '/videos/watch/playlist/' + playlistServer2UUID, | |
148 | servers[1].url + '/w/p/' + playlistServer2UUID | |
37a44fc9 C |
149 | ] |
150 | ||
151 | for (const search of searches) { | |
af971e06 | 152 | const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) |
37a44fc9 | 153 | |
af971e06 C |
154 | expect(body.total).to.equal(1) |
155 | expect(body.data).to.be.an('array') | |
156 | expect(body.data).to.have.lengthOf(1) | |
157 | expect(body.data[0].displayName).to.equal('playlist 1 on server 2') | |
158 | expect(body.data[0].videosLength).to.equal(1) | |
37a44fc9 C |
159 | } |
160 | }) | |
161 | ||
162 | it('Should not list this remote playlist', async function () { | |
89d241a7 | 163 | const body = await servers[0].playlists.list({ start: 0, count: 10 }) |
e6346d59 C |
164 | expect(body.total).to.equal(1) |
165 | expect(body.data).to.have.lengthOf(1) | |
166 | expect(body.data[0].displayName).to.equal('playlist 1 on server 1') | |
37a44fc9 C |
167 | }) |
168 | ||
169 | it('Should update the playlist of server 2, and refresh it on server 1', async function () { | |
170 | this.timeout(60000) | |
171 | ||
89d241a7 | 172 | await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId: video2Server2 } }) |
37a44fc9 C |
173 | |
174 | await waitJobs(servers) | |
175 | // Expire playlist | |
176 | await wait(10000) | |
177 | ||
178 | // Will run refresh async | |
400043b1 | 179 | const search = servers[1].url + '/video-playlists/' + playlistServer2UUID |
af971e06 | 180 | await command.searchPlaylists({ search, token: servers[0].accessToken }) |
37a44fc9 C |
181 | |
182 | // Wait refresh | |
183 | await wait(5000) | |
184 | ||
af971e06 C |
185 | const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) |
186 | expect(body.total).to.equal(1) | |
187 | expect(body.data).to.have.lengthOf(1) | |
37a44fc9 | 188 | |
af971e06 | 189 | const playlist = body.data[0] |
37a44fc9 C |
190 | expect(playlist.videosLength).to.equal(2) |
191 | }) | |
192 | ||
193 | it('Should delete playlist of server 2, and delete it on server 1', async function () { | |
194 | this.timeout(60000) | |
195 | ||
89d241a7 | 196 | await servers[1].playlists.delete({ playlistId: playlistServer2UUID }) |
37a44fc9 C |
197 | |
198 | await waitJobs(servers) | |
199 | // Expiration | |
200 | await wait(10000) | |
201 | ||
202 | // Will run refresh async | |
400043b1 | 203 | const search = servers[1].url + '/video-playlists/' + playlistServer2UUID |
af971e06 | 204 | await command.searchPlaylists({ search, token: servers[0].accessToken }) |
37a44fc9 C |
205 | |
206 | // Wait refresh | |
207 | await wait(5000) | |
208 | ||
af971e06 C |
209 | const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) |
210 | expect(body.total).to.equal(0) | |
211 | expect(body.data).to.have.lengthOf(0) | |
37a44fc9 C |
212 | }) |
213 | ||
214 | after(async function () { | |
215 | await cleanupTests(servers) | |
216 | }) | |
217 | }) |