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