diff options
Diffstat (limited to 'server/tests/api/search/search-activitypub-video-channels.ts')
-rw-r--r-- | server/tests/api/search/search-activitypub-video-channels.ts | 255 |
1 files changed, 0 insertions, 255 deletions
diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts deleted file mode 100644 index 003bd34d0..000000000 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ /dev/null | |||
@@ -1,255 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { wait } from '@shared/core-utils' | ||
5 | import { VideoChannel } from '@shared/models' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | PeerTubeServer, | ||
10 | SearchCommand, | ||
11 | setAccessTokensToServers, | ||
12 | setDefaultAccountAvatar, | ||
13 | setDefaultVideoChannel, | ||
14 | waitJobs | ||
15 | } from '@shared/server-commands' | ||
16 | |||
17 | describe('Test ActivityPub video channels search', function () { | ||
18 | let servers: PeerTubeServer[] | ||
19 | let userServer2Token: string | ||
20 | let videoServer2UUID: string | ||
21 | let channelIdServer2: number | ||
22 | let command: SearchCommand | ||
23 | |||
24 | before(async function () { | ||
25 | this.timeout(120000) | ||
26 | |||
27 | servers = await createMultipleServers(2) | ||
28 | |||
29 | await setAccessTokensToServers(servers) | ||
30 | await setDefaultVideoChannel(servers) | ||
31 | await setDefaultAccountAvatar(servers) | ||
32 | |||
33 | { | ||
34 | await servers[0].users.create({ username: 'user1_server1', password: 'password' }) | ||
35 | const channel = { | ||
36 | name: 'channel1_server1', | ||
37 | displayName: 'Channel 1 server 1' | ||
38 | } | ||
39 | await servers[0].channels.create({ attributes: channel }) | ||
40 | } | ||
41 | |||
42 | { | ||
43 | const user = { username: 'user1_server2', password: 'password' } | ||
44 | await servers[1].users.create({ username: user.username, password: user.password }) | ||
45 | userServer2Token = await servers[1].login.getAccessToken(user) | ||
46 | |||
47 | const channel = { | ||
48 | name: 'channel1_server2', | ||
49 | displayName: 'Channel 1 server 2' | ||
50 | } | ||
51 | const created = await servers[1].channels.create({ token: userServer2Token, attributes: channel }) | ||
52 | channelIdServer2 = created.id | ||
53 | |||
54 | const attributes = { name: 'video 1 server 2', channelId: channelIdServer2 } | ||
55 | const { uuid } = await servers[1].videos.upload({ token: userServer2Token, attributes }) | ||
56 | videoServer2UUID = uuid | ||
57 | } | ||
58 | |||
59 | await waitJobs(servers) | ||
60 | |||
61 | command = servers[0].search | ||
62 | }) | ||
63 | |||
64 | it('Should not find a remote video channel', async function () { | ||
65 | this.timeout(15000) | ||
66 | |||
67 | { | ||
68 | const search = servers[1].url + '/video-channels/channel1_server3' | ||
69 | const body = await command.searchChannels({ search, token: servers[0].accessToken }) | ||
70 | |||
71 | expect(body.total).to.equal(0) | ||
72 | expect(body.data).to.be.an('array') | ||
73 | expect(body.data).to.have.lengthOf(0) | ||
74 | } | ||
75 | |||
76 | { | ||
77 | // Without token | ||
78 | const search = servers[1].url + '/video-channels/channel1_server2' | ||
79 | const body = await command.searchChannels({ search }) | ||
80 | |||
81 | expect(body.total).to.equal(0) | ||
82 | expect(body.data).to.be.an('array') | ||
83 | expect(body.data).to.have.lengthOf(0) | ||
84 | } | ||
85 | }) | ||
86 | |||
87 | it('Should search a local video channel', async function () { | ||
88 | const searches = [ | ||
89 | servers[0].url + '/video-channels/channel1_server1', | ||
90 | 'channel1_server1@' + servers[0].host | ||
91 | ] | ||
92 | |||
93 | for (const search of searches) { | ||
94 | const body = await command.searchChannels({ search }) | ||
95 | |||
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') | ||
101 | } | ||
102 | }) | ||
103 | |||
104 | it('Should search a local video channel with an alternative URL', async function () { | ||
105 | const search = servers[0].url + '/c/channel1_server1' | ||
106 | |||
107 | for (const token of [ undefined, servers[0].accessToken ]) { | ||
108 | const body = await command.searchChannels({ search, token }) | ||
109 | |||
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') | ||
115 | } | ||
116 | }) | ||
117 | |||
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 | |||
137 | it('Should search a remote video channel with URL or handle', async function () { | ||
138 | const searches = [ | ||
139 | servers[1].url + '/video-channels/channel1_server2', | ||
140 | servers[1].url + '/c/channel1_server2', | ||
141 | servers[1].url + '/c/channel1_server2/videos', | ||
142 | 'channel1_server2@' + servers[1].host | ||
143 | ] | ||
144 | |||
145 | for (const search of searches) { | ||
146 | const body = await command.searchChannels({ search, token: servers[0].accessToken }) | ||
147 | |||
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') | ||
153 | } | ||
154 | }) | ||
155 | |||
156 | it('Should not list this remote video channel', async function () { | ||
157 | const body = await servers[0].channels.list() | ||
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') | ||
163 | }) | ||
164 | |||
165 | it('Should list video channel videos of server 2 without token', async function () { | ||
166 | this.timeout(30000) | ||
167 | |||
168 | await waitJobs(servers) | ||
169 | |||
170 | const { total, data } = await servers[0].videos.listByChannel({ | ||
171 | token: null, | ||
172 | handle: 'channel1_server2@' + servers[1].host | ||
173 | }) | ||
174 | expect(total).to.equal(0) | ||
175 | expect(data).to.have.lengthOf(0) | ||
176 | }) | ||
177 | |||
178 | it('Should list video channel videos of server 2 with token', async function () { | ||
179 | const { total, data } = await servers[0].videos.listByChannel({ | ||
180 | handle: 'channel1_server2@' + servers[1].host | ||
181 | }) | ||
182 | |||
183 | expect(total).to.equal(1) | ||
184 | expect(data[0].name).to.equal('video 1 server 2') | ||
185 | }) | ||
186 | |||
187 | it('Should update video channel of server 2, and refresh it on server 1', async function () { | ||
188 | this.timeout(120000) | ||
189 | |||
190 | await servers[1].channels.update({ | ||
191 | token: userServer2Token, | ||
192 | channelName: 'channel1_server2', | ||
193 | attributes: { displayName: 'channel updated' } | ||
194 | }) | ||
195 | await servers[1].users.updateMe({ token: userServer2Token, displayName: 'user updated' }) | ||
196 | |||
197 | await waitJobs(servers) | ||
198 | // Expire video channel | ||
199 | await wait(10000) | ||
200 | |||
201 | const search = servers[1].url + '/video-channels/channel1_server2' | ||
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) | ||
205 | |||
206 | const videoChannel: VideoChannel = body.data[0] | ||
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 | |||
213 | it('Should update and add a video on server 2, and update it on server 1 after a search', async function () { | ||
214 | this.timeout(120000) | ||
215 | |||
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 } }) | ||
218 | |||
219 | await waitJobs(servers) | ||
220 | |||
221 | // Expire video channel | ||
222 | await wait(10000) | ||
223 | |||
224 | const search = servers[1].url + '/video-channels/channel1_server2' | ||
225 | await command.searchChannels({ search, token: servers[0].accessToken }) | ||
226 | |||
227 | await waitJobs(servers) | ||
228 | |||
229 | const handle = 'channel1_server2@' + servers[1].host | ||
230 | const { total, data } = await servers[0].videos.listByChannel({ handle, sort: '-createdAt' }) | ||
231 | |||
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') | ||
235 | }) | ||
236 | |||
237 | it('Should delete video channel of server 2, and delete it on server 1', async function () { | ||
238 | this.timeout(120000) | ||
239 | |||
240 | await servers[1].channels.delete({ token: userServer2Token, channelName: 'channel1_server2' }) | ||
241 | |||
242 | await waitJobs(servers) | ||
243 | // Expire video | ||
244 | await wait(10000) | ||
245 | |||
246 | const search = servers[1].url + '/video-channels/channel1_server2' | ||
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) | ||
250 | }) | ||
251 | |||
252 | after(async function () { | ||
253 | await cleanupTests(servers) | ||
254 | }) | ||
255 | }) | ||