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