]>
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 | ||
80 | it('Should search a remote video', async function () { | |
7243f84d C |
81 | const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID |
82 | const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) | |
1297eb5d C |
83 | |
84 | expect(res.body.total).to.equal(1) | |
85 | expect(res.body.data).to.be.an('array') | |
86 | expect(res.body.data).to.have.lengthOf(1) | |
87 | expect(res.body.data[0].name).to.equal('video 1 on server 2') | |
88 | }) | |
89 | ||
90 | it('Should not list this remote video', async function () { | |
91 | const res = await getVideosList(servers[0].url) | |
92 | expect(res.body.total).to.equal(1) | |
93 | expect(res.body.data).to.have.lengthOf(1) | |
94 | expect(res.body.data[0].name).to.equal('video 1 on server 1') | |
95 | }) | |
96 | ||
97 | it('Should update video of server 2, and refresh it on server 1', async function () { | |
98 | this.timeout(60000) | |
99 | ||
100 | const channelAttributes = { | |
101 | name: 'super_channel', | |
102 | displayName: 'super channel' | |
103 | } | |
104 | const resChannel = await addVideoChannel(servers[1].url, servers[1].accessToken, channelAttributes) | |
105 | const videoChannelId = resChannel.body.videoChannel.id | |
106 | ||
107 | const attributes = { | |
108 | name: 'updated', | |
109 | tag: [ 'tag1', 'tag2' ], | |
110 | privacy: VideoPrivacy.UNLISTED, | |
111 | channelId: videoChannelId | |
112 | } | |
113 | await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes) | |
114 | ||
115 | await waitJobs(servers) | |
116 | // Expire video | |
117 | await wait(10000) | |
118 | ||
119 | // Will run refresh async | |
7243f84d C |
120 | const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID |
121 | await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) | |
1297eb5d C |
122 | |
123 | // Wait refresh | |
124 | await wait(5000) | |
125 | ||
7243f84d | 126 | const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) |
1297eb5d C |
127 | expect(res.body.total).to.equal(1) |
128 | expect(res.body.data).to.have.lengthOf(1) | |
129 | ||
130 | const video: Video = res.body.data[0] | |
131 | expect(video.name).to.equal('updated') | |
132 | expect(video.channel.name).to.equal('super_channel') | |
133 | expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) | |
134 | }) | |
135 | ||
136 | it('Should delete video of server 2, and delete it on server 1', async function () { | |
137 | this.timeout(60000) | |
138 | ||
139 | await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID) | |
140 | ||
141 | await waitJobs(servers) | |
142 | // Expire video | |
143 | await wait(10000) | |
144 | ||
145 | // Will run refresh async | |
7243f84d C |
146 | const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID |
147 | await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) | |
1297eb5d C |
148 | |
149 | // Wait refresh | |
150 | await wait(5000) | |
151 | ||
7243f84d | 152 | const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) |
1297eb5d C |
153 | expect(res.body.total).to.equal(0) |
154 | expect(res.body.data).to.have.lengthOf(0) | |
155 | }) | |
156 | ||
7c3b7976 C |
157 | after(async function () { |
158 | await cleanupTests(servers) | |
1297eb5d C |
159 | }) |
160 | }) |