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.ts1
-rw-r--r--server/tests/api/search/search-activitypub-video-channels.ts176
-rw-r--r--server/tests/api/search/search-activitypub-videos.ts1
3 files changed, 178 insertions, 0 deletions
diff --git a/server/tests/api/search/index.ts b/server/tests/api/search/index.ts
index 64b3d0910..d573c8a9e 100644
--- a/server/tests/api/search/index.ts
+++ b/server/tests/api/search/index.ts
@@ -1,2 +1,3 @@
1import './search-activitypub-video-channels'
1import './search-activitypub-videos' 2import './search-activitypub-videos'
2import './search-videos' 3import './search-videos'
diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts
new file mode 100644
index 000000000..512cb32fd
--- /dev/null
+++ b/server/tests/api/search/search-activitypub-video-channels.ts
@@ -0,0 +1,176 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 addVideoChannel,
7 createUser,
8 deleteVideoChannel,
9 flushAndRunMultipleServers,
10 flushTests,
11 getVideoChannelsList,
12 killallServers,
13 ServerInfo,
14 setAccessTokensToServers,
15 updateMyUser,
16 updateVideoChannel,
17 uploadVideo,
18 userLogin,
19 wait
20} from '../../utils'
21import { waitJobs } from '../../utils/server/jobs'
22import { VideoChannel } from '../../../../shared/models/videos'
23import { searchVideoChannel } from '../../utils/search/video-channels'
24
25const expect = chai.expect
26
27describe('Test a ActivityPub video channels search', function () {
28 let servers: ServerInfo[]
29 let userServer2Token: string
30
31 before(async function () {
32 this.timeout(120000)
33
34 await flushTests()
35
36 servers = await flushAndRunMultipleServers(2)
37
38 await setAccessTokensToServers(servers)
39
40 {
41 await createUser(servers[0].url, servers[0].accessToken, 'user1_server1', 'password')
42 const channel = {
43 name: 'channel1_server1',
44 displayName: 'Channel 1 server 1'
45 }
46 await addVideoChannel(servers[0].url, servers[0].accessToken, channel)
47 }
48
49 {
50 const user = { username: 'user1_server2', password: 'password' }
51 await createUser(servers[1].url, servers[1].accessToken, user.username, user.password)
52 userServer2Token = await userLogin(servers[1], user)
53
54 const channel = {
55 name: 'channel1_server2',
56 displayName: 'Channel 1 server 2'
57 }
58 const resChannel = await addVideoChannel(servers[1].url, userServer2Token, channel)
59 const channelId = resChannel.body.videoChannel.id
60
61 await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId })
62 await uploadVideo(servers[1].url, userServer2Token, { name: 'video 2 server 2', channelId })
63 }
64
65 await waitJobs(servers)
66 })
67
68 it('Should not find a remote video channel', async function () {
69 {
70 const search = 'http://localhost:9002/video-channels/channel1_server3'
71 const res = await searchVideoChannel(servers[ 0 ].url, search, servers[ 0 ].accessToken)
72
73 expect(res.body.total).to.equal(0)
74 expect(res.body.data).to.be.an('array')
75 expect(res.body.data).to.have.lengthOf(0)
76 }
77
78 {
79 // Without token
80 const search = 'http://localhost:9002/video-channels/channel1_server2'
81 const res = await searchVideoChannel(servers[0].url, search)
82
83 expect(res.body.total).to.equal(0)
84 expect(res.body.data).to.be.an('array')
85 expect(res.body.data).to.have.lengthOf(0)
86 }
87 })
88
89 it('Should search a local video channel', async function () {
90 const searches = [
91 'http://localhost:9001/video-channels/channel1_server1',
92 'channel1_server1@localhost:9001'
93 ]
94
95 for (const search of searches) {
96 const res = await searchVideoChannel(servers[ 0 ].url, search)
97
98 expect(res.body.total).to.equal(1)
99 expect(res.body.data).to.be.an('array')
100 expect(res.body.data).to.have.lengthOf(1)
101 expect(res.body.data[ 0 ].name).to.equal('channel1_server1')
102 expect(res.body.data[ 0 ].displayName).to.equal('Channel 1 server 1')
103 }
104 })
105
106 it('Should search a remote video channel with URL or handle', async function () {
107 const searches = [
108 'http://localhost:9002/video-channels/channel1_server2',
109 'channel1_server2@localhost:9002'
110 ]
111
112 for (const search of searches) {
113 const res = await searchVideoChannel(servers[ 0 ].url, search, servers[ 0 ].accessToken)
114
115 expect(res.body.total).to.equal(1)
116 expect(res.body.data).to.be.an('array')
117 expect(res.body.data).to.have.lengthOf(1)
118 expect(res.body.data[ 0 ].name).to.equal('channel1_server2')
119 expect(res.body.data[ 0 ].displayName).to.equal('Channel 1 server 2')
120 }
121 })
122
123 it('Should not list this remote video channel', async function () {
124 const res = await getVideoChannelsList(servers[0].url, 0, 5)
125 expect(res.body.total).to.equal(3)
126 expect(res.body.data).to.have.lengthOf(3)
127 expect(res.body.data[0].name).to.equal('channel1_server1')
128 expect(res.body.data[1].name).to.equal('user1_server1_channel')
129 expect(res.body.data[2].name).to.equal('root_channel')
130 })
131
132 it('Should update video channel of server 2, and refresh it on server 1', async function () {
133 this.timeout(60000)
134
135 await updateVideoChannel(servers[1].url, userServer2Token, 'channel1_server2', { displayName: 'channel updated' })
136 await updateMyUser({ url: servers[1].url, accessToken: userServer2Token, displayName: 'user updated' })
137
138 await waitJobs(servers)
139 // Expire video channel
140 await wait(10000)
141
142 const search = 'http://localhost:9002/video-channels/channel1_server2'
143 const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken)
144 expect(res.body.total).to.equal(1)
145 expect(res.body.data).to.have.lengthOf(1)
146
147 const videoChannel: VideoChannel = res.body.data[0]
148 expect(videoChannel.displayName).to.equal('channel updated')
149
150 // We don't return the owner account for now
151 // expect(videoChannel.ownerAccount.displayName).to.equal('user updated')
152 })
153
154 it('Should delete video channel of server 2, and delete it on server 1', async function () {
155 this.timeout(60000)
156
157 await deleteVideoChannel(servers[1].url, userServer2Token, 'channel1_server2')
158
159 await waitJobs(servers)
160 // Expire video
161 await wait(10000)
162
163 const res = await searchVideoChannel(servers[0].url, 'http://localhost:9002/video-channels/channel1_server2', servers[0].accessToken)
164 expect(res.body.total).to.equal(0)
165 expect(res.body.data).to.have.lengthOf(0)
166 })
167
168 after(async function () {
169 killallServers(servers)
170
171 // Keep the logs if the test failed
172 if (this['ok']) {
173 await flushTests()
174 }
175 })
176})
diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts
index 6dc792696..28f4fac50 100644
--- a/server/tests/api/search/search-activitypub-videos.ts
+++ b/server/tests/api/search/search-activitypub-videos.ts
@@ -59,6 +59,7 @@ describe('Test a ActivityPub videos search', function () {
59 } 59 }
60 60
61 { 61 {
62 // Without token
62 const res = await searchVideo(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID) 63 const res = await searchVideo(servers[0].url, 'http://localhost:9002/videos/watch/' + videoServer2UUID)
63 64
64 expect(res.body.total).to.equal(0) 65 expect(res.body.total).to.equal(0)