1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
import * as chai from 'chai'
import {
cleanupTests,
flushAndRunServer,
searchVideo,
ServerInfo,
setAccessTokensToServers,
updateCustomSubConfig,
uploadVideo,
advancedVideosSearch,
immutableAssign
} from '../../../../shared/extra-utils'
import { searchVideoChannel, advancedVideoChannelSearch } from '@shared/extra-utils/search/video-channels'
import { VideosSearchQuery, Video, VideoChannel } from '@shared/models'
const expect = chai.expect
describe('Test videos search', function () {
let server: ServerInfo = null
const localVideoName = 'local video' + new Date().toISOString()
before(async function () {
this.timeout(30000)
server = await flushAndRunServer(1)
await setAccessTokensToServers([ server ])
await uploadVideo(server.url, server.accessToken, { name: localVideoName })
})
describe('Default search', async function () {
it('Should make a local videos search by default', async function () {
this.timeout(10000)
await updateCustomSubConfig(server.url, server.accessToken, {
search: {
searchIndex: {
enabled: true,
isDefaultSearch: false,
disableLocalSearch: false
}
}
})
const res = await searchVideo(server.url, 'local video')
expect(res.body.total).to.equal(1)
expect(res.body.data[0].name).to.equal(localVideoName)
})
it('Should make a local channels search by default', async function () {
const res = await searchVideoChannel(server.url, 'root')
expect(res.body.total).to.equal(1)
expect(res.body.data[0].name).to.equal('root_channel')
expect(res.body.data[0].host).to.equal('localhost:' + server.port)
})
it('Should make an index videos search by default', async function () {
await updateCustomSubConfig(server.url, server.accessToken, {
search: {
searchIndex: {
enabled: true,
isDefaultSearch: true,
disableLocalSearch: false
}
}
})
const res = await searchVideo(server.url, 'local video')
expect(res.body.total).to.be.greaterThan(2)
})
it('Should make an index channels search by default', async function () {
const res = await searchVideoChannel(server.url, 'root')
expect(res.body.total).to.be.greaterThan(2)
})
it('Should make an index videos search if local search is disabled', async function () {
await updateCustomSubConfig(server.url, server.accessToken, {
search: {
searchIndex: {
enabled: true,
isDefaultSearch: false,
disableLocalSearch: true
}
}
})
const res = await searchVideo(server.url, 'local video')
expect(res.body.total).to.be.greaterThan(2)
})
it('Should make an index channels search if local search is disabled', async function () {
const res = await searchVideoChannel(server.url, 'root')
expect(res.body.total).to.be.greaterThan(2)
})
})
describe('Videos search', async function () {
it('Should make a simple search and not have results', async function () {
const res = await searchVideo(server.url, 'a'.repeat(500))
expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0)
})
it('Should make a simple search and have results', async function () {
const res = await searchVideo(server.url, 'What is PeerTube')
expect(res.body.total).to.be.greaterThan(1)
})
it('Should make a complex search', async function () {
async function check (search: VideosSearchQuery, exists = true) {
const res = await advancedVideosSearch(server.url, search)
if (exists === false) {
expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0)
return
}
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
const video: Video = res.body.data[0]
expect(video.name).to.equal('What is PeerTube?')
expect(video.category.label).to.equal('Science & Technology')
expect(video.licence.label).to.equal('Attribution - Share Alike')
expect(video.privacy.label).to.equal('Public')
expect(video.duration).to.equal(113)
expect(video.thumbnailUrl.startsWith('https://framatube.org/static/thumbnails')).to.be.true
expect(video.account.host).to.equal('framatube.org')
expect(video.account.name).to.equal('framasoft')
expect(video.account.url).to.equal('https://framatube.org/accounts/framasoft')
expect(video.account.avatar).to.exist
expect(video.channel.host).to.equal('framatube.org')
expect(video.channel.name).to.equal('bf54d359-cfad-4935-9d45-9d6be93f63e8')
expect(video.channel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
expect(video.channel.avatar).to.exist
}
const baseSearch: VideosSearchQuery = {
search: 'what is peertube',
start: 0,
count: 2,
categoryOneOf: [ 15 ],
licenceOneOf: [ 2 ],
tagsAllOf: [ 'framasoft', 'peertube' ],
startDate: '2018-10-01T10:50:46.396Z',
endDate: '2018-10-01T10:55:46.396Z'
}
{
await check(baseSearch)
}
{
const search = immutableAssign(baseSearch, { startDate: '2018-10-01T10:54:46.396Z' })
await check(search, false)
}
{
const search = immutableAssign(baseSearch, { tagsAllOf: [ 'toto', 'framasoft' ] })
await check(search, false)
}
{
const search = immutableAssign(baseSearch, { durationMin: 2000 })
await check(search, false)
}
{
const search = immutableAssign(baseSearch, { nsfw: 'true' })
await check(search, false)
}
{
const search = immutableAssign(baseSearch, { nsfw: 'false' })
await check(search, true)
}
{
const search = immutableAssign(baseSearch, { nsfw: 'both' })
await check(search, true)
}
})
it('Should have a correct pagination', async function () {
const search = {
search: 'video',
start: 0,
count: 5
}
const res = await advancedVideosSearch(server.url, search)
expect(res.body.total).to.be.greaterThan(5)
expect(res.body.data).to.have.lengthOf(5)
})
})
describe('Channels search', async function () {
it('Should make a simple search and not have results', async function () {
const res = await searchVideoChannel(server.url, 'a'.repeat(500))
expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0)
})
it('Should make a search and have results', async function () {
const res = await advancedVideoChannelSearch(server.url, { search: 'Framasoft', sort: 'createdAt' })
expect(res.body.total).to.be.greaterThan(0)
expect(res.body.data).to.have.length.greaterThan(0)
const videoChannel: VideoChannel = res.body.data[0]
expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
expect(videoChannel.host).to.equal('framatube.org')
expect(videoChannel.avatar).to.exist
expect(videoChannel.displayName).to.exist
expect(videoChannel.ownerAccount.url).to.equal('https://framatube.org/accounts/framasoft')
expect(videoChannel.ownerAccount.name).to.equal('framasoft')
expect(videoChannel.ownerAccount.host).to.equal('framatube.org')
expect(videoChannel.ownerAccount.avatar).to.exist
})
it('Should have a correct pagination', async function () {
const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 })
expect(res.body.total).to.be.greaterThan(2)
expect(res.body.data).to.have.lengthOf(2)
})
})
after(async function () {
await cleanupTests([ server ])
})
})
|