]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
f5b0af50 | 2 | |
f5b0af50 | 3 | import 'mocha' |
af971e06 | 4 | import * as chai from 'chai' |
f5b0af50 | 5 | import { |
7243f84d | 6 | cleanupTests, |
254d3579 | 7 | createMultipleServers, |
254d3579 | 8 | PeerTubeServer, |
4c7e60bc | 9 | SearchCommand, |
f5b0af50 | 10 | setAccessTokensToServers, |
af971e06 C |
11 | wait, |
12 | waitJobs | |
bf54587a | 13 | } from '@shared/server-commands' |
af971e06 | 14 | import { VideoChannel } from '@shared/models' |
f5b0af50 C |
15 | |
16 | const expect = chai.expect | |
17 | ||
da3a3ab6 | 18 | describe('Test ActivityPub video channels search', function () { |
254d3579 | 19 | let servers: PeerTubeServer[] |
f5b0af50 | 20 | let userServer2Token: string |
687d638c C |
21 | let videoServer2UUID: string |
22 | let channelIdServer2: number | |
af971e06 | 23 | let command: SearchCommand |
f5b0af50 C |
24 | |
25 | before(async function () { | |
26 | this.timeout(120000) | |
27 | ||
254d3579 | 28 | servers = await createMultipleServers(2) |
f5b0af50 C |
29 | |
30 | await setAccessTokensToServers(servers) | |
31 | ||
32 | { | |
89d241a7 | 33 | await servers[0].users.create({ username: 'user1_server1', password: 'password' }) |
f5b0af50 C |
34 | const channel = { |
35 | name: 'channel1_server1', | |
36 | displayName: 'Channel 1 server 1' | |
37 | } | |
89d241a7 | 38 | await servers[0].channels.create({ attributes: channel }) |
f5b0af50 C |
39 | } |
40 | ||
41 | { | |
42 | const user = { username: 'user1_server2', password: 'password' } | |
89d241a7 C |
43 | await servers[1].users.create({ username: user.username, password: user.password }) |
44 | userServer2Token = await servers[1].login.getAccessToken(user) | |
f5b0af50 C |
45 | |
46 | const channel = { | |
47 | name: 'channel1_server2', | |
48 | displayName: 'Channel 1 server 2' | |
49 | } | |
89d241a7 | 50 | const created = await servers[1].channels.create({ token: userServer2Token, attributes: channel }) |
a5461888 | 51 | channelIdServer2 = created.id |
f5b0af50 | 52 | |
d23dd9fb | 53 | const attributes = { name: 'video 1 server 2', channelId: channelIdServer2 } |
89d241a7 | 54 | const { uuid } = await servers[1].videos.upload({ token: userServer2Token, attributes }) |
d23dd9fb | 55 | videoServer2UUID = uuid |
f5b0af50 C |
56 | } |
57 | ||
58 | await waitJobs(servers) | |
af971e06 | 59 | |
89d241a7 | 60 | command = servers[0].search |
f5b0af50 C |
61 | }) |
62 | ||
63 | it('Should not find a remote video channel', async function () { | |
8d2be0ed C |
64 | this.timeout(15000) |
65 | ||
f5b0af50 | 66 | { |
400043b1 | 67 | const search = servers[1].url + '/video-channels/channel1_server3' |
af971e06 | 68 | const body = await command.searchChannels({ search, token: servers[0].accessToken }) |
f5b0af50 | 69 | |
af971e06 C |
70 | expect(body.total).to.equal(0) |
71 | expect(body.data).to.be.an('array') | |
72 | expect(body.data).to.have.lengthOf(0) | |
f5b0af50 C |
73 | } |
74 | ||
75 | { | |
76 | // Without token | |
400043b1 | 77 | const search = servers[1].url + '/video-channels/channel1_server2' |
af971e06 | 78 | const body = await command.searchChannels({ search }) |
f5b0af50 | 79 | |
af971e06 C |
80 | expect(body.total).to.equal(0) |
81 | expect(body.data).to.be.an('array') | |
82 | expect(body.data).to.have.lengthOf(0) | |
f5b0af50 C |
83 | } |
84 | }) | |
85 | ||
86 | it('Should search a local video channel', async function () { | |
87 | const searches = [ | |
400043b1 | 88 | servers[0].url + '/video-channels/channel1_server1', |
a1587156 | 89 | 'channel1_server1@localhost:' + servers[0].port |
f5b0af50 C |
90 | ] |
91 | ||
92 | for (const search of searches) { | |
af971e06 | 93 | const body = await command.searchChannels({ search }) |
f5b0af50 | 94 | |
af971e06 C |
95 | expect(body.total).to.equal(1) |
96 | expect(body.data).to.be.an('array') | |
97 | expect(body.data).to.have.lengthOf(1) | |
98 | expect(body.data[0].name).to.equal('channel1_server1') | |
99 | expect(body.data[0].displayName).to.equal('Channel 1 server 1') | |
f5b0af50 C |
100 | } |
101 | }) | |
102 | ||
37a44fc9 | 103 | it('Should search a local video channel with an alternative URL', async function () { |
400043b1 | 104 | const search = servers[0].url + '/c/channel1_server1' |
37a44fc9 C |
105 | |
106 | for (const token of [ undefined, servers[0].accessToken ]) { | |
af971e06 | 107 | const body = await command.searchChannels({ search, token }) |
37a44fc9 | 108 | |
af971e06 C |
109 | expect(body.total).to.equal(1) |
110 | expect(body.data).to.be.an('array') | |
111 | expect(body.data).to.have.lengthOf(1) | |
112 | expect(body.data[0].name).to.equal('channel1_server1') | |
113 | expect(body.data[0].displayName).to.equal('Channel 1 server 1') | |
37a44fc9 C |
114 | } |
115 | }) | |
116 | ||
400043b1 C |
117 | it('Should search a local video channel with a query in URL', async function () { |
118 | const searches = [ | |
119 | servers[0].url + '/video-channels/channel1_server1', | |
120 | servers[0].url + '/c/channel1_server1' | |
121 | ] | |
122 | ||
123 | for (const search of searches) { | |
124 | for (const token of [ undefined, servers[0].accessToken ]) { | |
125 | const body = await command.searchChannels({ search: search + '?param=2', token }) | |
126 | ||
127 | expect(body.total).to.equal(1) | |
128 | expect(body.data).to.be.an('array') | |
129 | expect(body.data).to.have.lengthOf(1) | |
130 | expect(body.data[0].name).to.equal('channel1_server1') | |
131 | expect(body.data[0].displayName).to.equal('Channel 1 server 1') | |
132 | } | |
133 | } | |
134 | }) | |
135 | ||
f5b0af50 C |
136 | it('Should search a remote video channel with URL or handle', async function () { |
137 | const searches = [ | |
400043b1 C |
138 | servers[1].url + '/video-channels/channel1_server2', |
139 | servers[1].url + '/c/channel1_server2', | |
140 | servers[1].url + '/c/channel1_server2/videos', | |
a1587156 | 141 | 'channel1_server2@localhost:' + servers[1].port |
f5b0af50 C |
142 | ] |
143 | ||
144 | for (const search of searches) { | |
af971e06 | 145 | const body = await command.searchChannels({ search, token: servers[0].accessToken }) |
f5b0af50 | 146 | |
af971e06 C |
147 | expect(body.total).to.equal(1) |
148 | expect(body.data).to.be.an('array') | |
149 | expect(body.data).to.have.lengthOf(1) | |
150 | expect(body.data[0].name).to.equal('channel1_server2') | |
151 | expect(body.data[0].displayName).to.equal('Channel 1 server 2') | |
f5b0af50 C |
152 | } |
153 | }) | |
154 | ||
155 | it('Should not list this remote video channel', async function () { | |
89d241a7 | 156 | const body = await servers[0].channels.list() |
a5461888 C |
157 | expect(body.total).to.equal(3) |
158 | expect(body.data).to.have.lengthOf(3) | |
159 | expect(body.data[0].name).to.equal('channel1_server1') | |
160 | expect(body.data[1].name).to.equal('user1_server1_channel') | |
161 | expect(body.data[2].name).to.equal('root_channel') | |
f5b0af50 C |
162 | }) |
163 | ||
687d638c C |
164 | it('Should list video channel videos of server 2 without token', async function () { |
165 | this.timeout(30000) | |
166 | ||
167 | await waitJobs(servers) | |
168 | ||
89d241a7 | 169 | const { total, data } = await servers[0].videos.listByChannel({ |
d23dd9fb | 170 | token: null, |
c0e8b12e | 171 | handle: 'channel1_server2@localhost:' + servers[1].port |
d23dd9fb C |
172 | }) |
173 | expect(total).to.equal(0) | |
174 | expect(data).to.have.lengthOf(0) | |
687d638c C |
175 | }) |
176 | ||
177 | it('Should list video channel videos of server 2 with token', async function () { | |
89d241a7 | 178 | const { total, data } = await servers[0].videos.listByChannel({ |
c0e8b12e | 179 | handle: 'channel1_server2@localhost:' + servers[1].port |
d23dd9fb | 180 | }) |
687d638c | 181 | |
d23dd9fb C |
182 | expect(total).to.equal(1) |
183 | expect(data[0].name).to.equal('video 1 server 2') | |
687d638c C |
184 | }) |
185 | ||
f5b0af50 C |
186 | it('Should update video channel of server 2, and refresh it on server 1', async function () { |
187 | this.timeout(60000) | |
188 | ||
89d241a7 | 189 | await servers[1].channels.update({ |
a5461888 C |
190 | token: userServer2Token, |
191 | channelName: 'channel1_server2', | |
192 | attributes: { displayName: 'channel updated' } | |
193 | }) | |
89d241a7 | 194 | await servers[1].users.updateMe({ token: userServer2Token, displayName: 'user updated' }) |
f5b0af50 C |
195 | |
196 | await waitJobs(servers) | |
197 | // Expire video channel | |
198 | await wait(10000) | |
199 | ||
400043b1 | 200 | const search = servers[1].url + '/video-channels/channel1_server2' |
af971e06 C |
201 | const body = await command.searchChannels({ search, token: servers[0].accessToken }) |
202 | expect(body.total).to.equal(1) | |
203 | expect(body.data).to.have.lengthOf(1) | |
f5b0af50 | 204 | |
af971e06 | 205 | const videoChannel: VideoChannel = body.data[0] |
f5b0af50 C |
206 | expect(videoChannel.displayName).to.equal('channel updated') |
207 | ||
208 | // We don't return the owner account for now | |
209 | // expect(videoChannel.ownerAccount.displayName).to.equal('user updated') | |
210 | }) | |
211 | ||
687d638c C |
212 | it('Should update and add a video on server 2, and update it on server 1 after a search', async function () { |
213 | this.timeout(60000) | |
214 | ||
89d241a7 C |
215 | await servers[1].videos.update({ token: userServer2Token, id: videoServer2UUID, attributes: { name: 'video 1 updated' } }) |
216 | await servers[1].videos.upload({ token: userServer2Token, attributes: { name: 'video 2 server 2', channelId: channelIdServer2 } }) | |
687d638c C |
217 | |
218 | await waitJobs(servers) | |
219 | ||
220 | // Expire video channel | |
221 | await wait(10000) | |
222 | ||
400043b1 | 223 | const search = servers[1].url + '/video-channels/channel1_server2' |
af971e06 | 224 | await command.searchChannels({ search, token: servers[0].accessToken }) |
687d638c C |
225 | |
226 | await waitJobs(servers) | |
227 | ||
c0e8b12e C |
228 | const handle = 'channel1_server2@localhost:' + servers[1].port |
229 | const { total, data } = await servers[0].videos.listByChannel({ handle, sort: '-createdAt' }) | |
687d638c | 230 | |
d23dd9fb C |
231 | expect(total).to.equal(2) |
232 | expect(data[0].name).to.equal('video 2 server 2') | |
233 | expect(data[1].name).to.equal('video 1 updated') | |
687d638c C |
234 | }) |
235 | ||
f5b0af50 C |
236 | it('Should delete video channel of server 2, and delete it on server 1', async function () { |
237 | this.timeout(60000) | |
238 | ||
89d241a7 | 239 | await servers[1].channels.delete({ token: userServer2Token, channelName: 'channel1_server2' }) |
f5b0af50 C |
240 | |
241 | await waitJobs(servers) | |
242 | // Expire video | |
243 | await wait(10000) | |
244 | ||
400043b1 | 245 | const search = servers[1].url + '/video-channels/channel1_server2' |
af971e06 C |
246 | const body = await command.searchChannels({ search, token: servers[0].accessToken }) |
247 | expect(body.total).to.equal(0) | |
248 | expect(body.data).to.have.lengthOf(0) | |
f5b0af50 C |
249 | }) |
250 | ||
7c3b7976 C |
251 | after(async function () { |
252 | await cleanupTests(servers) | |
f5b0af50 C |
253 | }) |
254 | }) |