]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { | |
6 | cleanupTests, | |
7 | createMultipleServers, | |
8 | PeerTubeServer, | |
9 | SearchCommand, | |
10 | setAccessTokensToServers, | |
11 | wait, | |
12 | waitJobs | |
13 | } from '@shared/extra-utils' | |
14 | import { VideoChannel } from '@shared/models' | |
15 | ||
16 | const expect = chai.expect | |
17 | ||
18 | describe('Test ActivityPub video channels search', function () { | |
19 | let servers: PeerTubeServer[] | |
20 | let userServer2Token: string | |
21 | let videoServer2UUID: string | |
22 | let channelIdServer2: number | |
23 | let command: SearchCommand | |
24 | ||
25 | before(async function () { | |
26 | this.timeout(120000) | |
27 | ||
28 | servers = await createMultipleServers(2) | |
29 | ||
30 | await setAccessTokensToServers(servers) | |
31 | ||
32 | { | |
33 | await servers[0].users.create({ username: 'user1_server1', password: 'password' }) | |
34 | const channel = { | |
35 | name: 'channel1_server1', | |
36 | displayName: 'Channel 1 server 1' | |
37 | } | |
38 | await servers[0].channels.create({ attributes: channel }) | |
39 | } | |
40 | ||
41 | { | |
42 | const user = { username: 'user1_server2', password: 'password' } | |
43 | await servers[1].users.create({ username: user.username, password: user.password }) | |
44 | userServer2Token = await servers[1].login.getAccessToken(user) | |
45 | ||
46 | const channel = { | |
47 | name: 'channel1_server2', | |
48 | displayName: 'Channel 1 server 2' | |
49 | } | |
50 | const created = await servers[1].channels.create({ token: userServer2Token, attributes: channel }) | |
51 | channelIdServer2 = created.id | |
52 | ||
53 | const attributes = { name: 'video 1 server 2', channelId: channelIdServer2 } | |
54 | const { uuid } = await servers[1].videos.upload({ token: userServer2Token, attributes }) | |
55 | videoServer2UUID = uuid | |
56 | } | |
57 | ||
58 | await waitJobs(servers) | |
59 | ||
60 | command = servers[0].search | |
61 | }) | |
62 | ||
63 | it('Should not find a remote video channel', async function () { | |
64 | this.timeout(15000) | |
65 | ||
66 | { | |
67 | const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3' | |
68 | const body = await command.searchChannels({ search, token: servers[0].accessToken }) | |
69 | ||
70 | expect(body.total).to.equal(0) | |
71 | expect(body.data).to.be.an('array') | |
72 | expect(body.data).to.have.lengthOf(0) | |
73 | } | |
74 | ||
75 | { | |
76 | // Without token | |
77 | const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' | |
78 | const body = await command.searchChannels({ search }) | |
79 | ||
80 | expect(body.total).to.equal(0) | |
81 | expect(body.data).to.be.an('array') | |
82 | expect(body.data).to.have.lengthOf(0) | |
83 | } | |
84 | }) | |
85 | ||
86 | it('Should search a local video channel', async function () { | |
87 | const searches = [ | |
88 | 'http://localhost:' + servers[0].port + '/video-channels/channel1_server1', | |
89 | 'channel1_server1@localhost:' + servers[0].port | |
90 | ] | |
91 | ||
92 | for (const search of searches) { | |
93 | const body = await command.searchChannels({ search }) | |
94 | ||
95 | expect(body.total).to.equal(1) | |
96 | expect(body.data).to.be.an('array') | |
97 | expect(body.data).to.have.lengthOf(1) | |
98 | expect(body.data[0].name).to.equal('channel1_server1') | |
99 | expect(body.data[0].displayName).to.equal('Channel 1 server 1') | |
100 | } | |
101 | }) | |
102 | ||
103 | it('Should search a local video channel with an alternative URL', async function () { | |
104 | const search = 'http://localhost:' + servers[0].port + '/c/channel1_server1' | |
105 | ||
106 | for (const token of [ undefined, servers[0].accessToken ]) { | |
107 | const body = await command.searchChannels({ search, token }) | |
108 | ||
109 | expect(body.total).to.equal(1) | |
110 | expect(body.data).to.be.an('array') | |
111 | expect(body.data).to.have.lengthOf(1) | |
112 | expect(body.data[0].name).to.equal('channel1_server1') | |
113 | expect(body.data[0].displayName).to.equal('Channel 1 server 1') | |
114 | } | |
115 | }) | |
116 | ||
117 | it('Should search a remote video channel with URL or handle', async function () { | |
118 | const searches = [ | |
119 | 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2', | |
120 | 'http://localhost:' + servers[1].port + '/c/channel1_server2', | |
121 | 'http://localhost:' + servers[1].port + '/c/channel1_server2/videos', | |
122 | 'channel1_server2@localhost:' + servers[1].port | |
123 | ] | |
124 | ||
125 | for (const search of searches) { | |
126 | const body = await command.searchChannels({ search, token: servers[0].accessToken }) | |
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_server2') | |
132 | expect(body.data[0].displayName).to.equal('Channel 1 server 2') | |
133 | } | |
134 | }) | |
135 | ||
136 | it('Should not list this remote video channel', async function () { | |
137 | const body = await servers[0].channels.list() | |
138 | expect(body.total).to.equal(3) | |
139 | expect(body.data).to.have.lengthOf(3) | |
140 | expect(body.data[0].name).to.equal('channel1_server1') | |
141 | expect(body.data[1].name).to.equal('user1_server1_channel') | |
142 | expect(body.data[2].name).to.equal('root_channel') | |
143 | }) | |
144 | ||
145 | it('Should list video channel videos of server 2 without token', async function () { | |
146 | this.timeout(30000) | |
147 | ||
148 | await waitJobs(servers) | |
149 | ||
150 | const { total, data } = await servers[0].videos.listByChannel({ | |
151 | token: null, | |
152 | handle: 'channel1_server2@localhost:' + servers[1].port | |
153 | }) | |
154 | expect(total).to.equal(0) | |
155 | expect(data).to.have.lengthOf(0) | |
156 | }) | |
157 | ||
158 | it('Should list video channel videos of server 2 with token', async function () { | |
159 | const { total, data } = await servers[0].videos.listByChannel({ | |
160 | handle: 'channel1_server2@localhost:' + servers[1].port | |
161 | }) | |
162 | ||
163 | expect(total).to.equal(1) | |
164 | expect(data[0].name).to.equal('video 1 server 2') | |
165 | }) | |
166 | ||
167 | it('Should update video channel of server 2, and refresh it on server 1', async function () { | |
168 | this.timeout(60000) | |
169 | ||
170 | await servers[1].channels.update({ | |
171 | token: userServer2Token, | |
172 | channelName: 'channel1_server2', | |
173 | attributes: { displayName: 'channel updated' } | |
174 | }) | |
175 | await servers[1].users.updateMe({ token: userServer2Token, displayName: 'user updated' }) | |
176 | ||
177 | await waitJobs(servers) | |
178 | // Expire video channel | |
179 | await wait(10000) | |
180 | ||
181 | const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' | |
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) | |
185 | ||
186 | const videoChannel: VideoChannel = body.data[0] | |
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 | ||
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 servers[1].videos.update({ token: userServer2Token, id: videoServer2UUID, attributes: { name: 'video 1 updated' } }) | |
197 | await servers[1].videos.upload({ token: userServer2Token, attributes: { name: 'video 2 server 2', channelId: channelIdServer2 } }) | |
198 | ||
199 | await waitJobs(servers) | |
200 | ||
201 | // Expire video channel | |
202 | await wait(10000) | |
203 | ||
204 | const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' | |
205 | await command.searchChannels({ search, token: servers[0].accessToken }) | |
206 | ||
207 | await waitJobs(servers) | |
208 | ||
209 | const handle = 'channel1_server2@localhost:' + servers[1].port | |
210 | const { total, data } = await servers[0].videos.listByChannel({ handle, sort: '-createdAt' }) | |
211 | ||
212 | expect(total).to.equal(2) | |
213 | expect(data[0].name).to.equal('video 2 server 2') | |
214 | expect(data[1].name).to.equal('video 1 updated') | |
215 | }) | |
216 | ||
217 | it('Should delete video channel of server 2, and delete it on server 1', async function () { | |
218 | this.timeout(60000) | |
219 | ||
220 | await servers[1].channels.delete({ token: userServer2Token, channelName: 'channel1_server2' }) | |
221 | ||
222 | await waitJobs(servers) | |
223 | // Expire video | |
224 | await wait(10000) | |
225 | ||
226 | const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' | |
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) | |
230 | }) | |
231 | ||
232 | after(async function () { | |
233 | await cleanupTests(servers) | |
234 | }) | |
235 | }) |