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