]>
Commit | Line | Data |
---|---|---|
1297eb5d C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { | |
6 | addVideoChannel, | |
7 | flushAndRunMultipleServers, | |
8 | flushTests, | |
9 | getVideosList, | |
10 | killallServers, | |
11 | removeVideo, | |
12 | searchVideoWithToken, | |
13 | ServerInfo, | |
14 | setAccessTokensToServers, | |
15 | updateVideo, | |
16 | uploadVideo, | |
17 | wait, | |
18 | searchVideo | |
9639bd17 | 19 | } from '../../../../shared/utils' |
20 | import { waitJobs } from '../../../../shared/utils/server/jobs' | |
1297eb5d C |
21 | import { Video, VideoPrivacy } from '../../../../shared/models/videos' |
22 | ||
23 | const expect = chai.expect | |
24 | ||
25 | describe('Test a ActivityPub videos search', function () { | |
26 | let servers: ServerInfo[] | |
27 | let videoServer1UUID: string | |
28 | let videoServer2UUID: string | |
29 | ||
30 | before(async function () { | |
31 | this.timeout(120000) | |
32 | ||
33 | await flushTests() | |
34 | ||
35 | servers = await flushAndRunMultipleServers(2) | |
36 | ||
37 | await setAccessTokensToServers(servers) | |
38 | ||
39 | { | |
40 | const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video 1 on server 1' }) | |
41 | videoServer1UUID = res.body.video.uuid | |
42 | } | |
43 | ||
44 | { | |
45 | const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video 1 on server 2' }) | |
46 | videoServer2UUID = res.body.video.uuid | |
47 | } | |
48 | ||
49 | await waitJobs(servers) | |
50 | }) | |
51 | ||
52 | it('Should not find a remote video', async function () { | |
53 | { | |
54 | const res = await searchVideoWithToken(servers[ 0 ].url, 'http://localhost:9002/videos/watch/43', servers[ 0 ].accessToken) | |
55 | ||
56 | expect(res.body.total).to.equal(0) | |
57 | expect(res.body.data).to.be.an('array') | |
58 | expect(res.body.data).to.have.lengthOf(0) | |
59 | } | |
60 | ||
61 | { | |
f5b0af50 | 62 | // Without token |
1297eb5d C |
63 | const res = await searchVideo(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID) |
64 | ||
65 | expect(res.body.total).to.equal(0) | |
66 | expect(res.body.data).to.be.an('array') | |
67 | expect(res.body.data).to.have.lengthOf(0) | |
68 | } | |
69 | }) | |
70 | ||
71 | it('Should search a local video', async function () { | |
72 | const res = await searchVideo(servers[0].url, 'http://localhost:9001/videos/watch/' + videoServer1UUID) | |
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 () { | |
81 | const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken) | |
82 | ||
83 | expect(res.body.total).to.equal(1) | |
84 | expect(res.body.data).to.be.an('array') | |
85 | expect(res.body.data).to.have.lengthOf(1) | |
86 | expect(res.body.data[0].name).to.equal('video 1 on server 2') | |
87 | }) | |
88 | ||
89 | it('Should not list this remote video', async function () { | |
90 | const res = await getVideosList(servers[0].url) | |
91 | expect(res.body.total).to.equal(1) | |
92 | expect(res.body.data).to.have.lengthOf(1) | |
93 | expect(res.body.data[0].name).to.equal('video 1 on server 1') | |
94 | }) | |
95 | ||
96 | it('Should update video of server 2, and refresh it on server 1', async function () { | |
97 | this.timeout(60000) | |
98 | ||
99 | const channelAttributes = { | |
100 | name: 'super_channel', | |
101 | displayName: 'super channel' | |
102 | } | |
103 | const resChannel = await addVideoChannel(servers[1].url, servers[1].accessToken, channelAttributes) | |
104 | const videoChannelId = resChannel.body.videoChannel.id | |
105 | ||
106 | const attributes = { | |
107 | name: 'updated', | |
108 | tag: [ 'tag1', 'tag2' ], | |
109 | privacy: VideoPrivacy.UNLISTED, | |
110 | channelId: videoChannelId | |
111 | } | |
112 | await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes) | |
113 | ||
114 | await waitJobs(servers) | |
115 | // Expire video | |
116 | await wait(10000) | |
117 | ||
118 | // Will run refresh async | |
119 | await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken) | |
120 | ||
121 | // Wait refresh | |
122 | await wait(5000) | |
123 | ||
124 | const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken) | |
125 | expect(res.body.total).to.equal(1) | |
126 | expect(res.body.data).to.have.lengthOf(1) | |
127 | ||
128 | const video: Video = res.body.data[0] | |
129 | expect(video.name).to.equal('updated') | |
130 | expect(video.channel.name).to.equal('super_channel') | |
131 | expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) | |
132 | }) | |
133 | ||
134 | it('Should delete video of server 2, and delete it on server 1', async function () { | |
135 | this.timeout(60000) | |
136 | ||
137 | await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID) | |
138 | ||
139 | await waitJobs(servers) | |
140 | // Expire video | |
141 | await wait(10000) | |
142 | ||
143 | // Will run refresh async | |
144 | await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken) | |
145 | ||
146 | // Wait refresh | |
147 | await wait(5000) | |
148 | ||
149 | const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken) | |
150 | expect(res.body.total).to.equal(0) | |
151 | expect(res.body.data).to.have.lengthOf(0) | |
152 | }) | |
153 | ||
154 | after(async function () { | |
155 | killallServers(servers) | |
156 | ||
157 | // Keep the logs if the test failed | |
158 | if (this['ok']) { | |
159 | await flushTests() | |
160 | } | |
161 | }) | |
162 | }) |