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