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