aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/search
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/search')
-rw-r--r--server/tests/api/search/index.ts2
-rw-r--r--server/tests/api/search/search-activitypub-videos.ts161
2 files changed, 163 insertions, 0 deletions
diff --git a/server/tests/api/search/index.ts b/server/tests/api/search/index.ts
new file mode 100644
index 000000000..64b3d0910
--- /dev/null
+++ b/server/tests/api/search/index.ts
@@ -0,0 +1,2 @@
1import './search-activitypub-videos'
2import './search-videos'
diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts
new file mode 100644
index 000000000..6dc792696
--- /dev/null
+++ b/server/tests/api/search/search-activitypub-videos.ts
@@ -0,0 +1,161 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
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
19} from '../../utils'
20import { waitJobs } from '../../utils/server/jobs'
21import { Video, VideoPrivacy } from '../../../../shared/models/videos'
22
23const expect = chai.expect
24
25describe('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 {
62 const res = await searchVideo(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID)
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 () {
71 const res = await searchVideo(servers[0].url, 'http://localhost:9001/videos/watch/' + videoServer1UUID)
72
73 expect(res.body.total).to.equal(1)
74 expect(res.body.data).to.be.an('array')
75 expect(res.body.data).to.have.lengthOf(1)
76 expect(res.body.data[0].name).to.equal('video 1 on server 1')
77 })
78
79 it('Should search a remote video', async function () {
80 const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
81
82 expect(res.body.total).to.equal(1)
83 expect(res.body.data).to.be.an('array')
84 expect(res.body.data).to.have.lengthOf(1)
85 expect(res.body.data[0].name).to.equal('video 1 on server 2')
86 })
87
88 it('Should not list this remote video', async function () {
89 const res = await getVideosList(servers[0].url)
90 expect(res.body.total).to.equal(1)
91 expect(res.body.data).to.have.lengthOf(1)
92 expect(res.body.data[0].name).to.equal('video 1 on server 1')
93 })
94
95 it('Should update video of server 2, and refresh it on server 1', async function () {
96 this.timeout(60000)
97
98 const channelAttributes = {
99 name: 'super_channel',
100 displayName: 'super channel'
101 }
102 const resChannel = await addVideoChannel(servers[1].url, servers[1].accessToken, channelAttributes)
103 const videoChannelId = resChannel.body.videoChannel.id
104
105 const attributes = {
106 name: 'updated',
107 tag: [ 'tag1', 'tag2' ],
108 privacy: VideoPrivacy.UNLISTED,
109 channelId: videoChannelId
110 }
111 await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes)
112
113 await waitJobs(servers)
114 // Expire video
115 await wait(10000)
116
117 // Will run refresh async
118 await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
119
120 // Wait refresh
121 await wait(5000)
122
123 const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
124 expect(res.body.total).to.equal(1)
125 expect(res.body.data).to.have.lengthOf(1)
126
127 const video: Video = res.body.data[0]
128 expect(video.name).to.equal('updated')
129 expect(video.channel.name).to.equal('super_channel')
130 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
131 })
132
133 it('Should delete video of server 2, and delete it on server 1', async function () {
134 this.timeout(60000)
135
136 await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID)
137
138 await waitJobs(servers)
139 // Expire video
140 await wait(10000)
141
142 // Will run refresh async
143 await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
144
145 // Wait refresh
146 await wait(5000)
147
148 const res = await searchVideoWithToken(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID, servers[0].accessToken)
149 expect(res.body.total).to.equal(0)
150 expect(res.body.data).to.have.lengthOf(0)
151 })
152
153 after(async function () {
154 killallServers(servers)
155
156 // Keep the logs if the test failed
157 if (this['ok']) {
158 await flushTests()
159 }
160 })
161})