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