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