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