]>
Commit | Line | Data |
---|---|---|
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 { VideoPrivacy } 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 videos search', function () { | |
18 | let servers: PeerTubeServer[] | |
19 | let videoServer1UUID: string | |
20 | let videoServer2UUID: string | |
21 | ||
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 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1 on server 1' } }) | |
35 | videoServer1UUID = uuid | |
36 | } | |
37 | ||
38 | { | |
39 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 on server 2' } }) | |
40 | videoServer2UUID = uuid | |
41 | } | |
42 | ||
43 | await waitJobs(servers) | |
44 | ||
45 | command = servers[0].search | |
46 | }) | |
47 | ||
48 | it('Should not find a remote video', async function () { | |
49 | { | |
50 | const search = servers[1].url + '/videos/watch/43' | |
51 | const body = await command.searchVideos({ search, token: servers[0].accessToken }) | |
52 | ||
53 | expect(body.total).to.equal(0) | |
54 | expect(body.data).to.be.an('array') | |
55 | expect(body.data).to.have.lengthOf(0) | |
56 | } | |
57 | ||
58 | { | |
59 | // Without token | |
60 | const search = servers[1].url + '/videos/watch/' + videoServer2UUID | |
61 | const body = await command.searchVideos({ search }) | |
62 | ||
63 | expect(body.total).to.equal(0) | |
64 | expect(body.data).to.be.an('array') | |
65 | expect(body.data).to.have.lengthOf(0) | |
66 | } | |
67 | }) | |
68 | ||
69 | it('Should search a local video', async function () { | |
70 | const search = servers[0].url + '/videos/watch/' + videoServer1UUID | |
71 | const body = await command.searchVideos({ search }) | |
72 | ||
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') | |
77 | }) | |
78 | ||
79 | it('Should search a local video with an alternative URL', async function () { | |
80 | const search = servers[0].url + '/w/' + videoServer1UUID | |
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') | |
89 | } | |
90 | }) | |
91 | ||
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 | ||
110 | it('Should search a remote video', async function () { | |
111 | const searches = [ | |
112 | servers[1].url + '/w/' + videoServer2UUID, | |
113 | servers[1].url + '/videos/watch/' + videoServer2UUID | |
114 | ] | |
115 | ||
116 | for (const search of searches) { | |
117 | const body = await command.searchVideos({ search, token: servers[0].accessToken }) | |
118 | ||
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') | |
123 | } | |
124 | }) | |
125 | ||
126 | it('Should not list this remote video', async function () { | |
127 | const { total, data } = await servers[0].videos.list() | |
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') | |
131 | }) | |
132 | ||
133 | it('Should update video of server 2, and refresh it on server 1', async function () { | |
134 | this.timeout(120000) | |
135 | ||
136 | const channelAttributes = { | |
137 | name: 'super_channel', | |
138 | displayName: 'super channel' | |
139 | } | |
140 | const created = await servers[1].channels.create({ attributes: channelAttributes }) | |
141 | const videoChannelId = created.id | |
142 | ||
143 | const attributes = { | |
144 | name: 'updated', | |
145 | tag: [ 'tag1', 'tag2' ], | |
146 | privacy: VideoPrivacy.UNLISTED, | |
147 | channelId: videoChannelId | |
148 | } | |
149 | await servers[1].videos.update({ id: videoServer2UUID, attributes }) | |
150 | ||
151 | await waitJobs(servers) | |
152 | // Expire video | |
153 | await wait(10000) | |
154 | ||
155 | // Will run refresh async | |
156 | const search = servers[1].url + '/videos/watch/' + videoServer2UUID | |
157 | await command.searchVideos({ search, token: servers[0].accessToken }) | |
158 | ||
159 | // Wait refresh | |
160 | await wait(5000) | |
161 | ||
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) | |
165 | ||
166 | const video = body.data[0] | |
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 () { | |
173 | this.timeout(120000) | |
174 | ||
175 | await servers[1].videos.remove({ id: videoServer2UUID }) | |
176 | ||
177 | await waitJobs(servers) | |
178 | // Expire video | |
179 | await wait(10000) | |
180 | ||
181 | // Will run refresh async | |
182 | const search = servers[1].url + '/videos/watch/' + videoServer2UUID | |
183 | await command.searchVideos({ search, token: servers[0].accessToken }) | |
184 | ||
185 | // Wait refresh | |
186 | await wait(5000) | |
187 | ||
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) | |
191 | }) | |
192 | ||
193 | after(async function () { | |
194 | await cleanupTests(servers) | |
195 | }) | |
196 | }) |