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