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