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