]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
1297eb5d | 2 | |
1297eb5d | 3 | import 'mocha' |
af971e06 | 4 | import * as chai from 'chai' |
c55e3d72 C |
5 | import { wait } from '@shared/core-utils' |
6 | import { VideoPrivacy } from '@shared/models' | |
1297eb5d | 7 | import { |
7243f84d | 8 | cleanupTests, |
254d3579 | 9 | createMultipleServers, |
254d3579 | 10 | PeerTubeServer, |
4c7e60bc | 11 | SearchCommand, |
1297eb5d | 12 | setAccessTokensToServers, |
d23dd9fb | 13 | waitJobs |
bf54587a | 14 | } from '@shared/server-commands' |
1297eb5d C |
15 | |
16 | const expect = chai.expect | |
17 | ||
da3a3ab6 | 18 | describe('Test ActivityPub videos search', function () { |
254d3579 | 19 | let servers: PeerTubeServer[] |
1297eb5d C |
20 | let videoServer1UUID: string |
21 | let videoServer2UUID: string | |
22 | ||
af971e06 C |
23 | let command: SearchCommand |
24 | ||
1297eb5d C |
25 | before(async function () { |
26 | this.timeout(120000) | |
27 | ||
254d3579 | 28 | servers = await createMultipleServers(2) |
1297eb5d C |
29 | |
30 | await setAccessTokensToServers(servers) | |
31 | ||
32 | { | |
89d241a7 | 33 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1 on server 1' } }) |
d23dd9fb | 34 | videoServer1UUID = uuid |
1297eb5d C |
35 | } |
36 | ||
37 | { | |
89d241a7 | 38 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 on server 2' } }) |
d23dd9fb | 39 | videoServer2UUID = uuid |
1297eb5d C |
40 | } |
41 | ||
42 | await waitJobs(servers) | |
af971e06 | 43 | |
89d241a7 | 44 | command = servers[0].search |
1297eb5d C |
45 | }) |
46 | ||
47 | it('Should not find a remote video', async function () { | |
48 | { | |
400043b1 | 49 | const search = servers[1].url + '/videos/watch/43' |
af971e06 | 50 | const body = await command.searchVideos({ search, token: servers[0].accessToken }) |
1297eb5d | 51 | |
af971e06 C |
52 | expect(body.total).to.equal(0) |
53 | expect(body.data).to.be.an('array') | |
54 | expect(body.data).to.have.lengthOf(0) | |
1297eb5d C |
55 | } |
56 | ||
57 | { | |
f5b0af50 | 58 | // Without token |
400043b1 | 59 | const search = servers[1].url + '/videos/watch/' + videoServer2UUID |
af971e06 | 60 | const body = await command.searchVideos({ search }) |
1297eb5d | 61 | |
af971e06 C |
62 | expect(body.total).to.equal(0) |
63 | expect(body.data).to.be.an('array') | |
64 | expect(body.data).to.have.lengthOf(0) | |
1297eb5d C |
65 | } |
66 | }) | |
67 | ||
68 | it('Should search a local video', async function () { | |
400043b1 | 69 | const search = servers[0].url + '/videos/watch/' + videoServer1UUID |
2d1ad5b9 | 70 | const body = await command.searchVideos({ search }) |
1297eb5d | 71 | |
af971e06 C |
72 | expect(body.total).to.equal(1) |
73 | expect(body.data).to.be.an('array') | |
74 | expect(body.data).to.have.lengthOf(1) | |
75 | expect(body.data[0].name).to.equal('video 1 on server 1') | |
1297eb5d C |
76 | }) |
77 | ||
37a44fc9 | 78 | it('Should search a local video with an alternative URL', async function () { |
400043b1 | 79 | const search = servers[0].url + '/w/' + videoServer1UUID |
af971e06 C |
80 | const body1 = await command.searchVideos({ search }) |
81 | const body2 = await command.searchVideos({ search, token: servers[0].accessToken }) | |
82 | ||
83 | for (const body of [ body1, body2 ]) { | |
84 | expect(body.total).to.equal(1) | |
85 | expect(body.data).to.be.an('array') | |
86 | expect(body.data).to.have.lengthOf(1) | |
87 | expect(body.data[0].name).to.equal('video 1 on server 1') | |
37a44fc9 C |
88 | } |
89 | }) | |
90 | ||
400043b1 C |
91 | it('Should search a local video with a query in URL', async function () { |
92 | const searches = [ | |
93 | servers[0].url + '/w/' + videoServer1UUID, | |
94 | servers[0].url + '/videos/watch/' + videoServer1UUID | |
95 | ] | |
96 | ||
97 | for (const search of searches) { | |
98 | for (const token of [ undefined, servers[0].accessToken ]) { | |
99 | const body = await command.searchVideos({ search: search + '?startTime=4', token }) | |
100 | ||
101 | expect(body.total).to.equal(1) | |
102 | expect(body.data).to.be.an('array') | |
103 | expect(body.data).to.have.lengthOf(1) | |
104 | expect(body.data[0].name).to.equal('video 1 on server 1') | |
105 | } | |
106 | } | |
107 | }) | |
108 | ||
1297eb5d | 109 | it('Should search a remote video', async function () { |
37a44fc9 | 110 | const searches = [ |
400043b1 C |
111 | servers[1].url + '/w/' + videoServer2UUID, |
112 | servers[1].url + '/videos/watch/' + videoServer2UUID | |
37a44fc9 | 113 | ] |
1297eb5d | 114 | |
37a44fc9 | 115 | for (const search of searches) { |
af971e06 | 116 | const body = await command.searchVideos({ search, token: servers[0].accessToken }) |
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('video 1 on server 2') | |
37a44fc9 | 122 | } |
1297eb5d C |
123 | }) |
124 | ||
125 | it('Should not list this remote video', async function () { | |
89d241a7 | 126 | const { total, data } = await servers[0].videos.list() |
d23dd9fb C |
127 | expect(total).to.equal(1) |
128 | expect(data).to.have.lengthOf(1) | |
129 | expect(data[0].name).to.equal('video 1 on server 1') | |
1297eb5d C |
130 | }) |
131 | ||
132 | it('Should update video of server 2, and refresh it on server 1', async function () { | |
37a44fc9 | 133 | this.timeout(120000) |
1297eb5d C |
134 | |
135 | const channelAttributes = { | |
136 | name: 'super_channel', | |
137 | displayName: 'super channel' | |
138 | } | |
89d241a7 | 139 | const created = await servers[1].channels.create({ attributes: channelAttributes }) |
a5461888 | 140 | const videoChannelId = created.id |
1297eb5d C |
141 | |
142 | const attributes = { | |
143 | name: 'updated', | |
144 | tag: [ 'tag1', 'tag2' ], | |
145 | privacy: VideoPrivacy.UNLISTED, | |
146 | channelId: videoChannelId | |
147 | } | |
89d241a7 | 148 | await servers[1].videos.update({ id: videoServer2UUID, attributes }) |
1297eb5d C |
149 | |
150 | await waitJobs(servers) | |
151 | // Expire video | |
152 | await wait(10000) | |
153 | ||
154 | // Will run refresh async | |
400043b1 | 155 | const search = servers[1].url + '/videos/watch/' + videoServer2UUID |
af971e06 | 156 | await command.searchVideos({ search, token: servers[0].accessToken }) |
1297eb5d C |
157 | |
158 | // Wait refresh | |
159 | await wait(5000) | |
160 | ||
af971e06 C |
161 | const body = await command.searchVideos({ search, token: servers[0].accessToken }) |
162 | expect(body.total).to.equal(1) | |
163 | expect(body.data).to.have.lengthOf(1) | |
1297eb5d | 164 | |
af971e06 | 165 | const video = body.data[0] |
1297eb5d C |
166 | expect(video.name).to.equal('updated') |
167 | expect(video.channel.name).to.equal('super_channel') | |
168 | expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) | |
169 | }) | |
170 | ||
171 | it('Should delete video of server 2, and delete it on server 1', async function () { | |
37a44fc9 | 172 | this.timeout(120000) |
1297eb5d | 173 | |
89d241a7 | 174 | await servers[1].videos.remove({ id: videoServer2UUID }) |
1297eb5d C |
175 | |
176 | await waitJobs(servers) | |
177 | // Expire video | |
178 | await wait(10000) | |
179 | ||
180 | // Will run refresh async | |
400043b1 | 181 | const search = servers[1].url + '/videos/watch/' + videoServer2UUID |
af971e06 | 182 | await command.searchVideos({ search, token: servers[0].accessToken }) |
1297eb5d C |
183 | |
184 | // Wait refresh | |
185 | await wait(5000) | |
186 | ||
af971e06 C |
187 | const body = await command.searchVideos({ search, token: servers[0].accessToken }) |
188 | expect(body.total).to.equal(0) | |
189 | expect(body.data).to.have.lengthOf(0) | |
1297eb5d C |
190 | }) |
191 | ||
7c3b7976 C |
192 | after(async function () { |
193 | await cleanupTests(servers) | |
1297eb5d C |
194 | }) |
195 | }) |