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