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