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