]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { | |
6 | addVideoChannel, | |
7 | cleanupTests, | |
8 | flushAndRunMultipleServers, | |
9 | getVideosList, | |
10 | removeVideo, | |
11 | SearchCommand, | |
12 | ServerInfo, | |
13 | setAccessTokensToServers, | |
14 | updateVideo, | |
15 | uploadVideo, | |
16 | wait | |
17 | } from '../../../../shared/extra-utils' | |
18 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
19 | import { VideoPrivacy } from '../../../../shared/models/videos' | |
20 | ||
21 | const expect = chai.expect | |
22 | ||
23 | describe('Test ActivityPub videos search', function () { | |
24 | let servers: ServerInfo[] | |
25 | let videoServer1UUID: string | |
26 | let videoServer2UUID: string | |
27 | ||
28 | let command: SearchCommand | |
29 | ||
30 | before(async function () { | |
31 | this.timeout(120000) | |
32 | ||
33 | servers = await flushAndRunMultipleServers(2) | |
34 | ||
35 | await setAccessTokensToServers(servers) | |
36 | ||
37 | { | |
38 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 on server 1' }) | |
39 | videoServer1UUID = res.body.video.uuid | |
40 | } | |
41 | ||
42 | { | |
43 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 on server 2' }) | |
44 | videoServer2UUID = res.body.video.uuid | |
45 | } | |
46 | ||
47 | await waitJobs(servers) | |
48 | ||
49 | command = servers[0].searchCommand | |
50 | }) | |
51 | ||
52 | it('Should not find a remote video', async function () { | |
53 | { | |
54 | const search = 'http://localhost:' + servers[1].port + '/videos/watch/43' | |
55 | const body = await command.searchVideos({ search, token: servers[0].accessToken }) | |
56 | ||
57 | expect(body.total).to.equal(0) | |
58 | expect(body.data).to.be.an('array') | |
59 | expect(body.data).to.have.lengthOf(0) | |
60 | } | |
61 | ||
62 | { | |
63 | // Without token | |
64 | const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID | |
65 | const body = await command.searchVideos({ search }) | |
66 | ||
67 | expect(body.total).to.equal(0) | |
68 | expect(body.data).to.be.an('array') | |
69 | expect(body.data).to.have.lengthOf(0) | |
70 | } | |
71 | }) | |
72 | ||
73 | it('Should search a local video', async function () { | |
74 | const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID | |
75 | const body = await command.searchVideos({ search }) | |
76 | ||
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') | |
81 | }) | |
82 | ||
83 | it('Should search a local video with an alternative URL', async function () { | |
84 | const search = 'http://localhost:' + servers[0].port + '/w/' + videoServer1UUID | |
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') | |
93 | } | |
94 | }) | |
95 | ||
96 | it('Should search a remote video', async function () { | |
97 | const searches = [ | |
98 | 'http://localhost:' + servers[1].port + '/w/' + videoServer2UUID, | |
99 | 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID | |
100 | ] | |
101 | ||
102 | for (const search of searches) { | |
103 | const body = await command.searchVideos({ search, token: servers[0].accessToken }) | |
104 | ||
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') | |
109 | } | |
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 () { | |
120 | this.timeout(120000) | |
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 | |
142 | const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID | |
143 | await command.searchVideos({ search, token: servers[0].accessToken }) | |
144 | ||
145 | // Wait refresh | |
146 | await wait(5000) | |
147 | ||
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) | |
151 | ||
152 | const video = body.data[0] | |
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 () { | |
159 | this.timeout(120000) | |
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 | |
168 | const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID | |
169 | await command.searchVideos({ search, token: servers[0].accessToken }) | |
170 | ||
171 | // Wait refresh | |
172 | await wait(5000) | |
173 | ||
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) | |
177 | }) | |
178 | ||
179 | after(async function () { | |
180 | await cleanupTests(servers) | |
181 | }) | |
182 | }) |