aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/search
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
committerChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
commita24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch)
treea54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/api/search
parent5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff)
parentc63830f15403ac4e750829f27d8bbbdc9a59282c (diff)
downloadPeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/api/search')
-rw-r--r--server/tests/api/search/search-activitypub-video-channels.ts171
-rw-r--r--server/tests/api/search/search-activitypub-video-playlists.ts150
-rw-r--r--server/tests/api/search/search-activitypub-videos.ts124
-rw-r--r--server/tests/api/search/search-channels.ts43
-rw-r--r--server/tests/api/search/search-index.ts206
-rw-r--r--server/tests/api/search/search-playlists.ts83
-rw-r--r--server/tests/api/search/search-videos.ts331
7 files changed, 546 insertions, 562 deletions
diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts
index e83eb7171..426cbc8e1 100644
--- a/server/tests/api/search/search-activitypub-video-channels.ts
+++ b/server/tests/api/search/search-activitypub-video-channels.ts
@@ -1,69 +1,63 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { 5import {
6 addVideoChannel,
7 cleanupTests, 6 cleanupTests,
8 createUser, 7 createMultipleServers,
9 deleteVideoChannel, 8 PeerTubeServer,
10 flushAndRunMultipleServers, 9 SearchCommand,
11 getVideoChannelsList,
12 getVideoChannelVideos,
13 ServerInfo,
14 setAccessTokensToServers, 10 setAccessTokensToServers,
15 updateMyUser, 11 wait,
16 updateVideo, 12 waitJobs
17 updateVideoChannel, 13} from '@shared/extra-utils'
18 uploadVideo, 14import { VideoChannel } from '@shared/models'
19 userLogin,
20 wait
21} from '../../../../shared/extra-utils'
22import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
23import { VideoChannel } from '../../../../shared/models/videos'
24import { searchVideoChannel } from '../../../../shared/extra-utils/search/video-channels'
25 15
26const expect = chai.expect 16const expect = chai.expect
27 17
28describe('Test ActivityPub video channels search', function () { 18describe('Test ActivityPub video channels search', function () {
29 let servers: ServerInfo[] 19 let servers: PeerTubeServer[]
30 let userServer2Token: string 20 let userServer2Token: string
31 let videoServer2UUID: string 21 let videoServer2UUID: string
32 let channelIdServer2: number 22 let channelIdServer2: number
23 let command: SearchCommand
33 24
34 before(async function () { 25 before(async function () {
35 this.timeout(120000) 26 this.timeout(120000)
36 27
37 servers = await flushAndRunMultipleServers(2) 28 servers = await createMultipleServers(2)
38 29
39 await setAccessTokensToServers(servers) 30 await setAccessTokensToServers(servers)
40 31
41 { 32 {
42 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user1_server1', password: 'password' }) 33 await servers[0].users.create({ username: 'user1_server1', password: 'password' })
43 const channel = { 34 const channel = {
44 name: 'channel1_server1', 35 name: 'channel1_server1',
45 displayName: 'Channel 1 server 1' 36 displayName: 'Channel 1 server 1'
46 } 37 }
47 await addVideoChannel(servers[0].url, servers[0].accessToken, channel) 38 await servers[0].channels.create({ attributes: channel })
48 } 39 }
49 40
50 { 41 {
51 const user = { username: 'user1_server2', password: 'password' } 42 const user = { username: 'user1_server2', password: 'password' }
52 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 43 await servers[1].users.create({ username: user.username, password: user.password })
53 userServer2Token = await userLogin(servers[1], user) 44 userServer2Token = await servers[1].login.getAccessToken(user)
54 45
55 const channel = { 46 const channel = {
56 name: 'channel1_server2', 47 name: 'channel1_server2',
57 displayName: 'Channel 1 server 2' 48 displayName: 'Channel 1 server 2'
58 } 49 }
59 const resChannel = await addVideoChannel(servers[1].url, userServer2Token, channel) 50 const created = await servers[1].channels.create({ token: userServer2Token, attributes: channel })
60 channelIdServer2 = resChannel.body.videoChannel.id 51 channelIdServer2 = created.id
61 52
62 const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 }) 53 const attributes = { name: 'video 1 server 2', channelId: channelIdServer2 }
63 videoServer2UUID = res.body.video.uuid 54 const { uuid } = await servers[1].videos.upload({ token: userServer2Token, attributes })
55 videoServer2UUID = uuid
64 } 56 }
65 57
66 await waitJobs(servers) 58 await waitJobs(servers)
59
60 command = servers[0].search
67 }) 61 })
68 62
69 it('Should not find a remote video channel', async function () { 63 it('Should not find a remote video channel', async function () {
@@ -71,21 +65,21 @@ describe('Test ActivityPub video channels search', function () {
71 65
72 { 66 {
73 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3' 67 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3'
74 const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) 68 const body = await command.searchChannels({ search, token: servers[0].accessToken })
75 69
76 expect(res.body.total).to.equal(0) 70 expect(body.total).to.equal(0)
77 expect(res.body.data).to.be.an('array') 71 expect(body.data).to.be.an('array')
78 expect(res.body.data).to.have.lengthOf(0) 72 expect(body.data).to.have.lengthOf(0)
79 } 73 }
80 74
81 { 75 {
82 // Without token 76 // Without token
83 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' 77 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
84 const res = await searchVideoChannel(servers[0].url, search) 78 const body = await command.searchChannels({ search })
85 79
86 expect(res.body.total).to.equal(0) 80 expect(body.total).to.equal(0)
87 expect(res.body.data).to.be.an('array') 81 expect(body.data).to.be.an('array')
88 expect(res.body.data).to.have.lengthOf(0) 82 expect(body.data).to.have.lengthOf(0)
89 } 83 }
90 }) 84 })
91 85
@@ -96,13 +90,13 @@ describe('Test ActivityPub video channels search', function () {
96 ] 90 ]
97 91
98 for (const search of searches) { 92 for (const search of searches) {
99 const res = await searchVideoChannel(servers[0].url, search) 93 const body = await command.searchChannels({ search })
100 94
101 expect(res.body.total).to.equal(1) 95 expect(body.total).to.equal(1)
102 expect(res.body.data).to.be.an('array') 96 expect(body.data).to.be.an('array')
103 expect(res.body.data).to.have.lengthOf(1) 97 expect(body.data).to.have.lengthOf(1)
104 expect(res.body.data[0].name).to.equal('channel1_server1') 98 expect(body.data[0].name).to.equal('channel1_server1')
105 expect(res.body.data[0].displayName).to.equal('Channel 1 server 1') 99 expect(body.data[0].displayName).to.equal('Channel 1 server 1')
106 } 100 }
107 }) 101 })
108 102
@@ -110,13 +104,13 @@ describe('Test ActivityPub video channels search', function () {
110 const search = 'http://localhost:' + servers[0].port + '/c/channel1_server1' 104 const search = 'http://localhost:' + servers[0].port + '/c/channel1_server1'
111 105
112 for (const token of [ undefined, servers[0].accessToken ]) { 106 for (const token of [ undefined, servers[0].accessToken ]) {
113 const res = await searchVideoChannel(servers[0].url, search, token) 107 const body = await command.searchChannels({ search, token })
114 108
115 expect(res.body.total).to.equal(1) 109 expect(body.total).to.equal(1)
116 expect(res.body.data).to.be.an('array') 110 expect(body.data).to.be.an('array')
117 expect(res.body.data).to.have.lengthOf(1) 111 expect(body.data).to.have.lengthOf(1)
118 expect(res.body.data[0].name).to.equal('channel1_server1') 112 expect(body.data[0].name).to.equal('channel1_server1')
119 expect(res.body.data[0].displayName).to.equal('Channel 1 server 1') 113 expect(body.data[0].displayName).to.equal('Channel 1 server 1')
120 } 114 }
121 }) 115 })
122 116
@@ -129,23 +123,23 @@ describe('Test ActivityPub video channels search', function () {
129 ] 123 ]
130 124
131 for (const search of searches) { 125 for (const search of searches) {
132 const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) 126 const body = await command.searchChannels({ search, token: servers[0].accessToken })
133 127
134 expect(res.body.total).to.equal(1) 128 expect(body.total).to.equal(1)
135 expect(res.body.data).to.be.an('array') 129 expect(body.data).to.be.an('array')
136 expect(res.body.data).to.have.lengthOf(1) 130 expect(body.data).to.have.lengthOf(1)
137 expect(res.body.data[0].name).to.equal('channel1_server2') 131 expect(body.data[0].name).to.equal('channel1_server2')
138 expect(res.body.data[0].displayName).to.equal('Channel 1 server 2') 132 expect(body.data[0].displayName).to.equal('Channel 1 server 2')
139 } 133 }
140 }) 134 })
141 135
142 it('Should not list this remote video channel', async function () { 136 it('Should not list this remote video channel', async function () {
143 const res = await getVideoChannelsList(servers[0].url, 0, 5) 137 const body = await servers[0].channels.list()
144 expect(res.body.total).to.equal(3) 138 expect(body.total).to.equal(3)
145 expect(res.body.data).to.have.lengthOf(3) 139 expect(body.data).to.have.lengthOf(3)
146 expect(res.body.data[0].name).to.equal('channel1_server1') 140 expect(body.data[0].name).to.equal('channel1_server1')
147 expect(res.body.data[1].name).to.equal('user1_server1_channel') 141 expect(body.data[1].name).to.equal('user1_server1_channel')
148 expect(res.body.data[2].name).to.equal('root_channel') 142 expect(body.data[2].name).to.equal('root_channel')
149 }) 143 })
150 144
151 it('Should list video channel videos of server 2 without token', async function () { 145 it('Should list video channel videos of server 2 without token', async function () {
@@ -153,34 +147,43 @@ describe('Test ActivityPub video channels search', function () {
153 147
154 await waitJobs(servers) 148 await waitJobs(servers)
155 149
156 const res = await getVideoChannelVideos(servers[0].url, null, 'channel1_server2@localhost:' + servers[1].port, 0, 5) 150 const { total, data } = await servers[0].videos.listByChannel({
157 expect(res.body.total).to.equal(0) 151 token: null,
158 expect(res.body.data).to.have.lengthOf(0) 152 handle: 'channel1_server2@localhost:' + servers[1].port
153 })
154 expect(total).to.equal(0)
155 expect(data).to.have.lengthOf(0)
159 }) 156 })
160 157
161 it('Should list video channel videos of server 2 with token', async function () { 158 it('Should list video channel videos of server 2 with token', async function () {
162 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:' + servers[1].port, 0, 5) 159 const { total, data } = await servers[0].videos.listByChannel({
160 handle: 'channel1_server2@localhost:' + servers[1].port
161 })
163 162
164 expect(res.body.total).to.equal(1) 163 expect(total).to.equal(1)
165 expect(res.body.data[0].name).to.equal('video 1 server 2') 164 expect(data[0].name).to.equal('video 1 server 2')
166 }) 165 })
167 166
168 it('Should update video channel of server 2, and refresh it on server 1', async function () { 167 it('Should update video channel of server 2, and refresh it on server 1', async function () {
169 this.timeout(60000) 168 this.timeout(60000)
170 169
171 await updateVideoChannel(servers[1].url, userServer2Token, 'channel1_server2', { displayName: 'channel updated' }) 170 await servers[1].channels.update({
172 await updateMyUser({ url: servers[1].url, accessToken: userServer2Token, displayName: 'user updated' }) 171 token: userServer2Token,
172 channelName: 'channel1_server2',
173 attributes: { displayName: 'channel updated' }
174 })
175 await servers[1].users.updateMe({ token: userServer2Token, displayName: 'user updated' })
173 176
174 await waitJobs(servers) 177 await waitJobs(servers)
175 // Expire video channel 178 // Expire video channel
176 await wait(10000) 179 await wait(10000)
177 180
178 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' 181 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
179 const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) 182 const body = await command.searchChannels({ search, token: servers[0].accessToken })
180 expect(res.body.total).to.equal(1) 183 expect(body.total).to.equal(1)
181 expect(res.body.data).to.have.lengthOf(1) 184 expect(body.data).to.have.lengthOf(1)
182 185
183 const videoChannel: VideoChannel = res.body.data[0] 186 const videoChannel: VideoChannel = body.data[0]
184 expect(videoChannel.displayName).to.equal('channel updated') 187 expect(videoChannel.displayName).to.equal('channel updated')
185 188
186 // We don't return the owner account for now 189 // We don't return the owner account for now
@@ -190,8 +193,8 @@ describe('Test ActivityPub video channels search', function () {
190 it('Should update and add a video on server 2, and update it on server 1 after a search', async function () { 193 it('Should update and add a video on server 2, and update it on server 1 after a search', async function () {
191 this.timeout(60000) 194 this.timeout(60000)
192 195
193 await updateVideo(servers[1].url, userServer2Token, videoServer2UUID, { name: 'video 1 updated' }) 196 await servers[1].videos.update({ token: userServer2Token, id: videoServer2UUID, attributes: { name: 'video 1 updated' } })
194 await uploadVideo(servers[1].url, userServer2Token, { name: 'video 2 server 2', channelId: channelIdServer2 }) 197 await servers[1].videos.upload({ token: userServer2Token, attributes: { name: 'video 2 server 2', channelId: channelIdServer2 } })
195 198
196 await waitJobs(servers) 199 await waitJobs(servers)
197 200
@@ -199,31 +202,31 @@ describe('Test ActivityPub video channels search', function () {
199 await wait(10000) 202 await wait(10000)
200 203
201 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' 204 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
202 await searchVideoChannel(servers[0].url, search, servers[0].accessToken) 205 await command.searchChannels({ search, token: servers[0].accessToken })
203 206
204 await waitJobs(servers) 207 await waitJobs(servers)
205 208
206 const videoChannelName = 'channel1_server2@localhost:' + servers[1].port 209 const handle = 'channel1_server2@localhost:' + servers[1].port
207 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, videoChannelName, 0, 5, '-createdAt') 210 const { total, data } = await servers[0].videos.listByChannel({ handle, sort: '-createdAt' })
208 211
209 expect(res.body.total).to.equal(2) 212 expect(total).to.equal(2)
210 expect(res.body.data[0].name).to.equal('video 2 server 2') 213 expect(data[0].name).to.equal('video 2 server 2')
211 expect(res.body.data[1].name).to.equal('video 1 updated') 214 expect(data[1].name).to.equal('video 1 updated')
212 }) 215 })
213 216
214 it('Should delete video channel of server 2, and delete it on server 1', async function () { 217 it('Should delete video channel of server 2, and delete it on server 1', async function () {
215 this.timeout(60000) 218 this.timeout(60000)
216 219
217 await deleteVideoChannel(servers[1].url, userServer2Token, 'channel1_server2') 220 await servers[1].channels.delete({ token: userServer2Token, channelName: 'channel1_server2' })
218 221
219 await waitJobs(servers) 222 await waitJobs(servers)
220 // Expire video 223 // Expire video
221 await wait(10000) 224 await wait(10000)
222 225
223 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' 226 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2'
224 const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) 227 const body = await command.searchChannels({ search, token: servers[0].accessToken })
225 expect(res.body.total).to.equal(0) 228 expect(body.total).to.equal(0)
226 expect(res.body.data).to.have.lengthOf(0) 229 expect(body.data).to.have.lengthOf(0)
227 }) 230 })
228 231
229 after(async function () { 232 after(async function () {
diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts
index 4c08e9548..33ca7be12 100644
--- a/server/tests/api/search/search-activitypub-video-playlists.ts
+++ b/server/tests/api/search/search-activitypub-video-playlists.ts
@@ -3,113 +3,102 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 addVideoInPlaylist,
7 cleanupTests, 6 cleanupTests,
8 createVideoPlaylist, 7 createMultipleServers,
9 deleteVideoPlaylist, 8 PeerTubeServer,
10 flushAndRunMultipleServers, 9 SearchCommand,
11 getVideoPlaylistsList,
12 searchVideoPlaylists,
13 ServerInfo,
14 setAccessTokensToServers, 10 setAccessTokensToServers,
15 setDefaultVideoChannel, 11 setDefaultVideoChannel,
16 uploadVideoAndGetId, 12 wait,
17 wait 13 waitJobs
18} from '../../../../shared/extra-utils' 14} from '@shared/extra-utils'
19import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 15import { VideoPlaylistPrivacy } from '@shared/models'
20import { VideoPlaylist, VideoPlaylistPrivacy } from '../../../../shared/models/videos'
21 16
22const expect = chai.expect 17const expect = chai.expect
23 18
24describe('Test ActivityPub playlists search', function () { 19describe('Test ActivityPub playlists search', function () {
25 let servers: ServerInfo[] 20 let servers: PeerTubeServer[]
26 let playlistServer1UUID: string 21 let playlistServer1UUID: string
27 let playlistServer2UUID: string 22 let playlistServer2UUID: string
28 let video2Server2: string 23 let video2Server2: string
29 24
25 let command: SearchCommand
26
30 before(async function () { 27 before(async function () {
31 this.timeout(120000) 28 this.timeout(120000)
32 29
33 servers = await flushAndRunMultipleServers(2) 30 servers = await createMultipleServers(2)
34 31
35 await setAccessTokensToServers(servers) 32 await setAccessTokensToServers(servers)
36 await setDefaultVideoChannel(servers) 33 await setDefaultVideoChannel(servers)
37 34
38 { 35 {
39 const video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid 36 const video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).uuid
40 const video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid 37 const video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).uuid
41 38
42 const attributes = { 39 const attributes = {
43 displayName: 'playlist 1 on server 1', 40 displayName: 'playlist 1 on server 1',
44 privacy: VideoPlaylistPrivacy.PUBLIC, 41 privacy: VideoPlaylistPrivacy.PUBLIC,
45 videoChannelId: servers[0].videoChannel.id 42 videoChannelId: servers[0].store.channel.id
46 } 43 }
47 const res = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs: attributes }) 44 const created = await servers[0].playlists.create({ attributes })
48 playlistServer1UUID = res.body.videoPlaylist.uuid 45 playlistServer1UUID = created.uuid
49 46
50 for (const videoId of [ video1, video2 ]) { 47 for (const videoId of [ video1, video2 ]) {
51 await addVideoInPlaylist({ 48 await servers[0].playlists.addElement({ playlistId: playlistServer1UUID, attributes: { videoId } })
52 url: servers[0].url,
53 token: servers[0].accessToken,
54 playlistId: playlistServer1UUID,
55 elementAttrs: { videoId }
56 })
57 } 49 }
58 } 50 }
59 51
60 { 52 {
61 const videoId = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 1' })).uuid 53 const videoId = (await servers[1].videos.quickUpload({ name: 'video 1' })).uuid
62 video2Server2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2' })).uuid 54 video2Server2 = (await servers[1].videos.quickUpload({ name: 'video 2' })).uuid
63 55
64 const attributes = { 56 const attributes = {
65 displayName: 'playlist 1 on server 2', 57 displayName: 'playlist 1 on server 2',
66 privacy: VideoPlaylistPrivacy.PUBLIC, 58 privacy: VideoPlaylistPrivacy.PUBLIC,
67 videoChannelId: servers[1].videoChannel.id 59 videoChannelId: servers[1].store.channel.id
68 } 60 }
69 const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs: attributes }) 61 const created = await servers[1].playlists.create({ attributes })
70 playlistServer2UUID = res.body.videoPlaylist.uuid 62 playlistServer2UUID = created.uuid
71 63
72 await addVideoInPlaylist({ 64 await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId } })
73 url: servers[1].url,
74 token: servers[1].accessToken,
75 playlistId: playlistServer2UUID,
76 elementAttrs: { videoId }
77 })
78 } 65 }
79 66
80 await waitJobs(servers) 67 await waitJobs(servers)
68
69 command = servers[0].search
81 }) 70 })
82 71
83 it('Should not find a remote playlist', async function () { 72 it('Should not find a remote playlist', async function () {
84 { 73 {
85 const search = 'http://localhost:' + servers[1].port + '/video-playlists/43' 74 const search = 'http://localhost:' + servers[1].port + '/video-playlists/43'
86 const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) 75 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
87 76
88 expect(res.body.total).to.equal(0) 77 expect(body.total).to.equal(0)
89 expect(res.body.data).to.be.an('array') 78 expect(body.data).to.be.an('array')
90 expect(res.body.data).to.have.lengthOf(0) 79 expect(body.data).to.have.lengthOf(0)
91 } 80 }
92 81
93 { 82 {
94 // Without token 83 // Without token
95 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID 84 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID
96 const res = await searchVideoPlaylists(servers[0].url, search) 85 const body = await command.searchPlaylists({ search })
97 86
98 expect(res.body.total).to.equal(0) 87 expect(body.total).to.equal(0)
99 expect(res.body.data).to.be.an('array') 88 expect(body.data).to.be.an('array')
100 expect(res.body.data).to.have.lengthOf(0) 89 expect(body.data).to.have.lengthOf(0)
101 } 90 }
102 }) 91 })
103 92
104 it('Should search a local playlist', async function () { 93 it('Should search a local playlist', async function () {
105 const search = 'http://localhost:' + servers[0].port + '/video-playlists/' + playlistServer1UUID 94 const search = 'http://localhost:' + servers[0].port + '/video-playlists/' + playlistServer1UUID
106 const res = await searchVideoPlaylists(servers[0].url, search) 95 const body = await command.searchPlaylists({ search })
107 96
108 expect(res.body.total).to.equal(1) 97 expect(body.total).to.equal(1)
109 expect(res.body.data).to.be.an('array') 98 expect(body.data).to.be.an('array')
110 expect(res.body.data).to.have.lengthOf(1) 99 expect(body.data).to.have.lengthOf(1)
111 expect(res.body.data[0].displayName).to.equal('playlist 1 on server 1') 100 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
112 expect(res.body.data[0].videosLength).to.equal(2) 101 expect(body.data[0].videosLength).to.equal(2)
113 }) 102 })
114 103
115 it('Should search a local playlist with an alternative URL', async function () { 104 it('Should search a local playlist with an alternative URL', async function () {
@@ -120,13 +109,13 @@ describe('Test ActivityPub playlists search', function () {
120 109
121 for (const search of searches) { 110 for (const search of searches) {
122 for (const token of [ undefined, servers[0].accessToken ]) { 111 for (const token of [ undefined, servers[0].accessToken ]) {
123 const res = await searchVideoPlaylists(servers[0].url, search, token) 112 const body = await command.searchPlaylists({ search, token })
124 113
125 expect(res.body.total).to.equal(1) 114 expect(body.total).to.equal(1)
126 expect(res.body.data).to.be.an('array') 115 expect(body.data).to.be.an('array')
127 expect(res.body.data).to.have.lengthOf(1) 116 expect(body.data).to.have.lengthOf(1)
128 expect(res.body.data[0].displayName).to.equal('playlist 1 on server 1') 117 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
129 expect(res.body.data[0].videosLength).to.equal(2) 118 expect(body.data[0].videosLength).to.equal(2)
130 } 119 }
131 } 120 }
132 }) 121 })
@@ -139,32 +128,27 @@ describe('Test ActivityPub playlists search', function () {
139 ] 128 ]
140 129
141 for (const search of searches) { 130 for (const search of searches) {
142 const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) 131 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
143 132
144 expect(res.body.total).to.equal(1) 133 expect(body.total).to.equal(1)
145 expect(res.body.data).to.be.an('array') 134 expect(body.data).to.be.an('array')
146 expect(res.body.data).to.have.lengthOf(1) 135 expect(body.data).to.have.lengthOf(1)
147 expect(res.body.data[0].displayName).to.equal('playlist 1 on server 2') 136 expect(body.data[0].displayName).to.equal('playlist 1 on server 2')
148 expect(res.body.data[0].videosLength).to.equal(1) 137 expect(body.data[0].videosLength).to.equal(1)
149 } 138 }
150 }) 139 })
151 140
152 it('Should not list this remote playlist', async function () { 141 it('Should not list this remote playlist', async function () {
153 const res = await getVideoPlaylistsList(servers[0].url, 0, 10) 142 const body = await servers[0].playlists.list({ start: 0, count: 10 })
154 expect(res.body.total).to.equal(1) 143 expect(body.total).to.equal(1)
155 expect(res.body.data).to.have.lengthOf(1) 144 expect(body.data).to.have.lengthOf(1)
156 expect(res.body.data[0].displayName).to.equal('playlist 1 on server 1') 145 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
157 }) 146 })
158 147
159 it('Should update the playlist of server 2, and refresh it on server 1', async function () { 148 it('Should update the playlist of server 2, and refresh it on server 1', async function () {
160 this.timeout(60000) 149 this.timeout(60000)
161 150
162 await addVideoInPlaylist({ 151 await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId: video2Server2 } })
163 url: servers[1].url,
164 token: servers[1].accessToken,
165 playlistId: playlistServer2UUID,
166 elementAttrs: { videoId: video2Server2 }
167 })
168 152
169 await waitJobs(servers) 153 await waitJobs(servers)
170 // Expire playlist 154 // Expire playlist
@@ -172,23 +156,23 @@ describe('Test ActivityPub playlists search', function () {
172 156
173 // Will run refresh async 157 // Will run refresh async
174 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID 158 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID
175 await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) 159 await command.searchPlaylists({ search, token: servers[0].accessToken })
176 160
177 // Wait refresh 161 // Wait refresh
178 await wait(5000) 162 await wait(5000)
179 163
180 const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) 164 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
181 expect(res.body.total).to.equal(1) 165 expect(body.total).to.equal(1)
182 expect(res.body.data).to.have.lengthOf(1) 166 expect(body.data).to.have.lengthOf(1)
183 167
184 const playlist: VideoPlaylist = res.body.data[0] 168 const playlist = body.data[0]
185 expect(playlist.videosLength).to.equal(2) 169 expect(playlist.videosLength).to.equal(2)
186 }) 170 })
187 171
188 it('Should delete playlist of server 2, and delete it on server 1', async function () { 172 it('Should delete playlist of server 2, and delete it on server 1', async function () {
189 this.timeout(60000) 173 this.timeout(60000)
190 174
191 await deleteVideoPlaylist(servers[1].url, servers[1].accessToken, playlistServer2UUID) 175 await servers[1].playlists.delete({ playlistId: playlistServer2UUID })
192 176
193 await waitJobs(servers) 177 await waitJobs(servers)
194 // Expiration 178 // Expiration
@@ -196,14 +180,14 @@ describe('Test ActivityPub playlists search', function () {
196 180
197 // Will run refresh async 181 // Will run refresh async
198 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID 182 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID
199 await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) 183 await command.searchPlaylists({ search, token: servers[0].accessToken })
200 184
201 // Wait refresh 185 // Wait refresh
202 await wait(5000) 186 await wait(5000)
203 187
204 const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) 188 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
205 expect(res.body.total).to.equal(0) 189 expect(body.total).to.equal(0)
206 expect(res.body.data).to.have.lengthOf(0) 190 expect(body.data).to.have.lengthOf(0)
207 }) 191 })
208 192
209 after(async function () { 193 after(async function () {
diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts
index e9b4978da..b3cfcacca 100644
--- a/server/tests/api/search/search-activitypub-videos.ts
+++ b/server/tests/api/search/search-activitypub-videos.ts
@@ -1,92 +1,90 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { 5import {
6 addVideoChannel,
7 cleanupTests, 6 cleanupTests,
8 flushAndRunMultipleServers, 7 createMultipleServers,
9 getVideosList, 8 PeerTubeServer,
10 removeVideo, 9 SearchCommand,
11 searchVideo,
12 searchVideoWithToken,
13 ServerInfo,
14 setAccessTokensToServers, 10 setAccessTokensToServers,
15 updateVideo, 11 wait,
16 uploadVideo, 12 waitJobs
17 wait 13} from '@shared/extra-utils'
18} from '../../../../shared/extra-utils' 14import { VideoPrivacy } from '@shared/models'
19import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
20import { Video, VideoPrivacy } from '../../../../shared/models/videos'
21 15
22const expect = chai.expect 16const expect = chai.expect
23 17
24describe('Test ActivityPub videos search', function () { 18describe('Test ActivityPub videos search', function () {
25 let servers: ServerInfo[] 19 let servers: PeerTubeServer[]
26 let videoServer1UUID: string 20 let videoServer1UUID: string
27 let videoServer2UUID: string 21 let videoServer2UUID: string
28 22
23 let command: SearchCommand
24
29 before(async function () { 25 before(async function () {
30 this.timeout(120000) 26 this.timeout(120000)
31 27
32 servers = await flushAndRunMultipleServers(2) 28 servers = await createMultipleServers(2)
33 29
34 await setAccessTokensToServers(servers) 30 await setAccessTokensToServers(servers)
35 31
36 { 32 {
37 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 on server 1' }) 33 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1 on server 1' } })
38 videoServer1UUID = res.body.video.uuid 34 videoServer1UUID = uuid
39 } 35 }
40 36
41 { 37 {
42 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 on server 2' }) 38 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 on server 2' } })
43 videoServer2UUID = res.body.video.uuid 39 videoServer2UUID = uuid
44 } 40 }
45 41
46 await waitJobs(servers) 42 await waitJobs(servers)
43
44 command = servers[0].search
47 }) 45 })
48 46
49 it('Should not find a remote video', async function () { 47 it('Should not find a remote video', async function () {
50 { 48 {
51 const search = 'http://localhost:' + servers[1].port + '/videos/watch/43' 49 const search = 'http://localhost:' + servers[1].port + '/videos/watch/43'
52 const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) 50 const body = await command.searchVideos({ search, token: servers[0].accessToken })
53 51
54 expect(res.body.total).to.equal(0) 52 expect(body.total).to.equal(0)
55 expect(res.body.data).to.be.an('array') 53 expect(body.data).to.be.an('array')
56 expect(res.body.data).to.have.lengthOf(0) 54 expect(body.data).to.have.lengthOf(0)
57 } 55 }
58 56
59 { 57 {
60 // Without token 58 // Without token
61 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID 59 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
62 const res = await searchVideo(servers[0].url, search) 60 const body = await command.searchVideos({ search })
63 61
64 expect(res.body.total).to.equal(0) 62 expect(body.total).to.equal(0)
65 expect(res.body.data).to.be.an('array') 63 expect(body.data).to.be.an('array')
66 expect(res.body.data).to.have.lengthOf(0) 64 expect(body.data).to.have.lengthOf(0)
67 } 65 }
68 }) 66 })
69 67
70 it('Should search a local video', async function () { 68 it('Should search a local video', async function () {
71 const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID 69 const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID
72 const res = await searchVideo(servers[0].url, search) 70 const body = await command.searchVideos({ search })
73 71
74 expect(res.body.total).to.equal(1) 72 expect(body.total).to.equal(1)
75 expect(res.body.data).to.be.an('array') 73 expect(body.data).to.be.an('array')
76 expect(res.body.data).to.have.lengthOf(1) 74 expect(body.data).to.have.lengthOf(1)
77 expect(res.body.data[0].name).to.equal('video 1 on server 1') 75 expect(body.data[0].name).to.equal('video 1 on server 1')
78 }) 76 })
79 77
80 it('Should search a local video with an alternative URL', async function () { 78 it('Should search a local video with an alternative URL', async function () {
81 const search = 'http://localhost:' + servers[0].port + '/w/' + videoServer1UUID 79 const search = 'http://localhost:' + servers[0].port + '/w/' + videoServer1UUID
82 const res1 = await searchVideo(servers[0].url, search) 80 const body1 = await command.searchVideos({ search })
83 const res2 = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) 81 const body2 = await command.searchVideos({ search, token: servers[0].accessToken })
84 82
85 for (const res of [ res1, res2 ]) { 83 for (const body of [ body1, body2 ]) {
86 expect(res.body.total).to.equal(1) 84 expect(body.total).to.equal(1)
87 expect(res.body.data).to.be.an('array') 85 expect(body.data).to.be.an('array')
88 expect(res.body.data).to.have.lengthOf(1) 86 expect(body.data).to.have.lengthOf(1)
89 expect(res.body.data[0].name).to.equal('video 1 on server 1') 87 expect(body.data[0].name).to.equal('video 1 on server 1')
90 } 88 }
91 }) 89 })
92 90
@@ -97,20 +95,20 @@ describe('Test ActivityPub videos search', function () {
97 ] 95 ]
98 96
99 for (const search of searches) { 97 for (const search of searches) {
100 const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) 98 const body = await command.searchVideos({ search, token: servers[0].accessToken })
101 99
102 expect(res.body.total).to.equal(1) 100 expect(body.total).to.equal(1)
103 expect(res.body.data).to.be.an('array') 101 expect(body.data).to.be.an('array')
104 expect(res.body.data).to.have.lengthOf(1) 102 expect(body.data).to.have.lengthOf(1)
105 expect(res.body.data[0].name).to.equal('video 1 on server 2') 103 expect(body.data[0].name).to.equal('video 1 on server 2')
106 } 104 }
107 }) 105 })
108 106
109 it('Should not list this remote video', async function () { 107 it('Should not list this remote video', async function () {
110 const res = await getVideosList(servers[0].url) 108 const { total, data } = await servers[0].videos.list()
111 expect(res.body.total).to.equal(1) 109 expect(total).to.equal(1)
112 expect(res.body.data).to.have.lengthOf(1) 110 expect(data).to.have.lengthOf(1)
113 expect(res.body.data[0].name).to.equal('video 1 on server 1') 111 expect(data[0].name).to.equal('video 1 on server 1')
114 }) 112 })
115 113
116 it('Should update video of server 2, and refresh it on server 1', async function () { 114 it('Should update video of server 2, and refresh it on server 1', async function () {
@@ -120,8 +118,8 @@ describe('Test ActivityPub videos search', function () {
120 name: 'super_channel', 118 name: 'super_channel',
121 displayName: 'super channel' 119 displayName: 'super channel'
122 } 120 }
123 const resChannel = await addVideoChannel(servers[1].url, servers[1].accessToken, channelAttributes) 121 const created = await servers[1].channels.create({ attributes: channelAttributes })
124 const videoChannelId = resChannel.body.videoChannel.id 122 const videoChannelId = created.id
125 123
126 const attributes = { 124 const attributes = {
127 name: 'updated', 125 name: 'updated',
@@ -129,7 +127,7 @@ describe('Test ActivityPub videos search', function () {
129 privacy: VideoPrivacy.UNLISTED, 127 privacy: VideoPrivacy.UNLISTED,
130 channelId: videoChannelId 128 channelId: videoChannelId
131 } 129 }
132 await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes) 130 await servers[1].videos.update({ id: videoServer2UUID, attributes })
133 131
134 await waitJobs(servers) 132 await waitJobs(servers)
135 // Expire video 133 // Expire video
@@ -137,16 +135,16 @@ describe('Test ActivityPub videos search', function () {
137 135
138 // Will run refresh async 136 // Will run refresh async
139 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID 137 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
140 await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) 138 await command.searchVideos({ search, token: servers[0].accessToken })
141 139
142 // Wait refresh 140 // Wait refresh
143 await wait(5000) 141 await wait(5000)
144 142
145 const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) 143 const body = await command.searchVideos({ search, token: servers[0].accessToken })
146 expect(res.body.total).to.equal(1) 144 expect(body.total).to.equal(1)
147 expect(res.body.data).to.have.lengthOf(1) 145 expect(body.data).to.have.lengthOf(1)
148 146
149 const video: Video = res.body.data[0] 147 const video = body.data[0]
150 expect(video.name).to.equal('updated') 148 expect(video.name).to.equal('updated')
151 expect(video.channel.name).to.equal('super_channel') 149 expect(video.channel.name).to.equal('super_channel')
152 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) 150 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
@@ -155,7 +153,7 @@ describe('Test ActivityPub videos search', function () {
155 it('Should delete video of server 2, and delete it on server 1', async function () { 153 it('Should delete video of server 2, and delete it on server 1', async function () {
156 this.timeout(120000) 154 this.timeout(120000)
157 155
158 await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID) 156 await servers[1].videos.remove({ id: videoServer2UUID })
159 157
160 await waitJobs(servers) 158 await waitJobs(servers)
161 // Expire video 159 // Expire video
@@ -163,14 +161,14 @@ describe('Test ActivityPub videos search', function () {
163 161
164 // Will run refresh async 162 // Will run refresh async
165 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID 163 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID
166 await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) 164 await command.searchVideos({ search, token: servers[0].accessToken })
167 165
168 // Wait refresh 166 // Wait refresh
169 await wait(5000) 167 await wait(5000)
170 168
171 const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) 169 const body = await command.searchVideos({ search, token: servers[0].accessToken })
172 expect(res.body.total).to.equal(0) 170 expect(body.total).to.equal(0)
173 expect(res.body.data).to.have.lengthOf(0) 171 expect(body.data).to.have.lengthOf(0)
174 }) 172 })
175 173
176 after(async function () { 174 after(async function () {
diff --git a/server/tests/api/search/search-channels.ts b/server/tests/api/search/search-channels.ts
index daca2aebe..4da2d0ece 100644
--- a/server/tests/api/search/search-channels.ts
+++ b/server/tests/api/search/search-channels.ts
@@ -2,44 +2,39 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { searchVideoChannel, advancedVideoChannelSearch } from '@shared/extra-utils/search/video-channels' 5import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils'
6import {
7 addVideoChannel,
8 cleanupTests,
9 createUser,
10 flushAndRunServer,
11 ServerInfo,
12 setAccessTokensToServers
13} from '../../../../shared/extra-utils'
14import { VideoChannel } from '@shared/models' 6import { VideoChannel } from '@shared/models'
15 7
16const expect = chai.expect 8const expect = chai.expect
17 9
18describe('Test channels search', function () { 10describe('Test channels search', function () {
19 let server: ServerInfo = null 11 let server: PeerTubeServer = null
12 let command: SearchCommand
20 13
21 before(async function () { 14 before(async function () {
22 this.timeout(30000) 15 this.timeout(30000)
23 16
24 server = await flushAndRunServer(1) 17 server = await createSingleServer(1)
25 18
26 await setAccessTokensToServers([ server ]) 19 await setAccessTokensToServers([ server ])
27 20
28 { 21 {
29 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' }) 22 await server.users.create({ username: 'user1', password: 'password' })
30 const channel = { 23 const channel = {
31 name: 'squall_channel', 24 name: 'squall_channel',
32 displayName: 'Squall channel' 25 displayName: 'Squall channel'
33 } 26 }
34 await addVideoChannel(server.url, server.accessToken, channel) 27 await server.channels.create({ attributes: channel })
35 } 28 }
29
30 command = server.search
36 }) 31 })
37 32
38 it('Should make a simple search and not have results', async function () { 33 it('Should make a simple search and not have results', async function () {
39 const res = await searchVideoChannel(server.url, 'abc') 34 const body = await command.searchChannels({ search: 'abc' })
40 35
41 expect(res.body.total).to.equal(0) 36 expect(body.total).to.equal(0)
42 expect(res.body.data).to.have.lengthOf(0) 37 expect(body.data).to.have.lengthOf(0)
43 }) 38 })
44 39
45 it('Should make a search and have results', async function () { 40 it('Should make a search and have results', async function () {
@@ -49,11 +44,11 @@ describe('Test channels search', function () {
49 start: 0, 44 start: 0,
50 count: 1 45 count: 1
51 } 46 }
52 const res = await advancedVideoChannelSearch(server.url, search) 47 const body = await command.advancedChannelSearch({ search })
53 expect(res.body.total).to.equal(1) 48 expect(body.total).to.equal(1)
54 expect(res.body.data).to.have.lengthOf(1) 49 expect(body.data).to.have.lengthOf(1)
55 50
56 const channel: VideoChannel = res.body.data[0] 51 const channel: VideoChannel = body.data[0]
57 expect(channel.name).to.equal('squall_channel') 52 expect(channel.name).to.equal('squall_channel')
58 expect(channel.displayName).to.equal('Squall channel') 53 expect(channel.displayName).to.equal('Squall channel')
59 } 54 }
@@ -65,11 +60,9 @@ describe('Test channels search', function () {
65 count: 1 60 count: 1
66 } 61 }
67 62
68 const res = await advancedVideoChannelSearch(server.url, search) 63 const body = await command.advancedChannelSearch({ search })
69 64 expect(body.total).to.equal(1)
70 expect(res.body.total).to.equal(1) 65 expect(body.data).to.have.lengthOf(0)
71
72 expect(res.body.data).to.have.lengthOf(0)
73 } 66 }
74 }) 67 })
75 68
diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts
index 00f79232a..feb35411f 100644
--- a/server/tests/api/search/search-index.ts
+++ b/server/tests/api/search/search-index.ts
@@ -2,36 +2,27 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { advancedVideoChannelSearch, searchVideoChannel } from '@shared/extra-utils/search/video-channels' 5import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils'
6import { Video, VideoChannel, VideoPlaylist, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' 6import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models'
7import {
8 advancedVideoPlaylistSearch,
9 advancedVideosSearch,
10 cleanupTests,
11 flushAndRunServer,
12 immutableAssign,
13 searchVideo,
14 searchVideoPlaylists,
15 ServerInfo,
16 setAccessTokensToServers,
17 updateCustomSubConfig,
18 uploadVideo
19} from '../../../../shared/extra-utils'
20 7
21const expect = chai.expect 8const expect = chai.expect
22 9
23describe('Test videos search', function () { 10describe('Test videos search', function () {
24 let server: ServerInfo = null
25 const localVideoName = 'local video' + new Date().toISOString() 11 const localVideoName = 'local video' + new Date().toISOString()
26 12
13 let server: PeerTubeServer = null
14 let command: SearchCommand
15
27 before(async function () { 16 before(async function () {
28 this.timeout(30000) 17 this.timeout(30000)
29 18
30 server = await flushAndRunServer(1) 19 server = await createSingleServer(1)
31 20
32 await setAccessTokensToServers([ server ]) 21 await setAccessTokensToServers([ server ])
33 22
34 await uploadVideo(server.url, server.accessToken, { name: localVideoName }) 23 await server.videos.upload({ attributes: { name: localVideoName } })
24
25 command = server.search
35 }) 26 })
36 27
37 describe('Default search', async function () { 28 describe('Default search', async function () {
@@ -39,101 +30,107 @@ describe('Test videos search', function () {
39 it('Should make a local videos search by default', async function () { 30 it('Should make a local videos search by default', async function () {
40 this.timeout(10000) 31 this.timeout(10000)
41 32
42 await updateCustomSubConfig(server.url, server.accessToken, { 33 await server.config.updateCustomSubConfig({
43 search: { 34 newConfig: {
44 searchIndex: { 35 search: {
45 enabled: true, 36 searchIndex: {
46 isDefaultSearch: false, 37 enabled: true,
47 disableLocalSearch: false 38 isDefaultSearch: false,
39 disableLocalSearch: false
40 }
48 } 41 }
49 } 42 }
50 }) 43 })
51 44
52 const res = await searchVideo(server.url, 'local video') 45 const body = await command.searchVideos({ search: 'local video' })
53 46
54 expect(res.body.total).to.equal(1) 47 expect(body.total).to.equal(1)
55 expect(res.body.data[0].name).to.equal(localVideoName) 48 expect(body.data[0].name).to.equal(localVideoName)
56 }) 49 })
57 50
58 it('Should make a local channels search by default', async function () { 51 it('Should make a local channels search by default', async function () {
59 const res = await searchVideoChannel(server.url, 'root') 52 const body = await command.searchChannels({ search: 'root' })
60 53
61 expect(res.body.total).to.equal(1) 54 expect(body.total).to.equal(1)
62 expect(res.body.data[0].name).to.equal('root_channel') 55 expect(body.data[0].name).to.equal('root_channel')
63 expect(res.body.data[0].host).to.equal('localhost:' + server.port) 56 expect(body.data[0].host).to.equal('localhost:' + server.port)
64 }) 57 })
65 58
66 it('Should make an index videos search by default', async function () { 59 it('Should make an index videos search by default', async function () {
67 await updateCustomSubConfig(server.url, server.accessToken, { 60 await server.config.updateCustomSubConfig({
68 search: { 61 newConfig: {
69 searchIndex: { 62 search: {
70 enabled: true, 63 searchIndex: {
71 isDefaultSearch: true, 64 enabled: true,
72 disableLocalSearch: false 65 isDefaultSearch: true,
66 disableLocalSearch: false
67 }
73 } 68 }
74 } 69 }
75 }) 70 })
76 71
77 const res = await searchVideo(server.url, 'local video') 72 const body = await command.searchVideos({ search: 'local video' })
78 expect(res.body.total).to.be.greaterThan(2) 73 expect(body.total).to.be.greaterThan(2)
79 }) 74 })
80 75
81 it('Should make an index channels search by default', async function () { 76 it('Should make an index channels search by default', async function () {
82 const res = await searchVideoChannel(server.url, 'root') 77 const body = await command.searchChannels({ search: 'root' })
83 expect(res.body.total).to.be.greaterThan(2) 78 expect(body.total).to.be.greaterThan(2)
84 }) 79 })
85 80
86 it('Should make an index videos search if local search is disabled', async function () { 81 it('Should make an index videos search if local search is disabled', async function () {
87 await updateCustomSubConfig(server.url, server.accessToken, { 82 await server.config.updateCustomSubConfig({
88 search: { 83 newConfig: {
89 searchIndex: { 84 search: {
90 enabled: true, 85 searchIndex: {
91 isDefaultSearch: false, 86 enabled: true,
92 disableLocalSearch: true 87 isDefaultSearch: false,
88 disableLocalSearch: true
89 }
93 } 90 }
94 } 91 }
95 }) 92 })
96 93
97 const res = await searchVideo(server.url, 'local video') 94 const body = await command.searchVideos({ search: 'local video' })
98 expect(res.body.total).to.be.greaterThan(2) 95 expect(body.total).to.be.greaterThan(2)
99 }) 96 })
100 97
101 it('Should make an index channels search if local search is disabled', async function () { 98 it('Should make an index channels search if local search is disabled', async function () {
102 const res = await searchVideoChannel(server.url, 'root') 99 const body = await command.searchChannels({ search: 'root' })
103 expect(res.body.total).to.be.greaterThan(2) 100 expect(body.total).to.be.greaterThan(2)
104 }) 101 })
105 }) 102 })
106 103
107 describe('Videos search', async function () { 104 describe('Videos search', async function () {
108 105
109 it('Should make a simple search and not have results', async function () { 106 it('Should make a simple search and not have results', async function () {
110 const res = await searchVideo(server.url, 'djidane'.repeat(50)) 107 const body = await command.searchVideos({ search: 'djidane'.repeat(50) })
111 108
112 expect(res.body.total).to.equal(0) 109 expect(body.total).to.equal(0)
113 expect(res.body.data).to.have.lengthOf(0) 110 expect(body.data).to.have.lengthOf(0)
114 }) 111 })
115 112
116 it('Should make a simple search and have results', async function () { 113 it('Should make a simple search and have results', async function () {
117 const res = await searchVideo(server.url, 'What is PeerTube') 114 const body = await command.searchVideos({ search: 'What is PeerTube' })
118 115
119 expect(res.body.total).to.be.greaterThan(1) 116 expect(body.total).to.be.greaterThan(1)
120 }) 117 })
121 118
122 it('Should make a complex search', async function () { 119 it('Should make a complex search', async function () {
123 120
124 async function check (search: VideosSearchQuery, exists = true) { 121 async function check (search: VideosSearchQuery, exists = true) {
125 const res = await advancedVideosSearch(server.url, search) 122 const body = await command.advancedVideoSearch({ search })
126 123
127 if (exists === false) { 124 if (exists === false) {
128 expect(res.body.total).to.equal(0) 125 expect(body.total).to.equal(0)
129 expect(res.body.data).to.have.lengthOf(0) 126 expect(body.data).to.have.lengthOf(0)
130 return 127 return
131 } 128 }
132 129
133 expect(res.body.total).to.equal(1) 130 expect(body.total).to.equal(1)
134 expect(res.body.data).to.have.lengthOf(1) 131 expect(body.data).to.have.lengthOf(1)
135 132
136 const video: Video = res.body.data[0] 133 const video = body.data[0]
137 134
138 expect(video.name).to.equal('What is PeerTube?') 135 expect(video.name).to.equal('What is PeerTube?')
139 expect(video.category.label).to.equal('Science & Technology') 136 expect(video.category.label).to.equal('Science & Technology')
@@ -169,32 +166,32 @@ describe('Test videos search', function () {
169 } 166 }
170 167
171 { 168 {
172 const search = immutableAssign(baseSearch, { startDate: '2018-10-01T10:54:46.396Z' }) 169 const search = { ...baseSearch, startDate: '2018-10-01T10:54:46.396Z' }
173 await check(search, false) 170 await check(search, false)
174 } 171 }
175 172
176 { 173 {
177 const search = immutableAssign(baseSearch, { tagsAllOf: [ 'toto', 'framasoft' ] }) 174 const search = { ...baseSearch, tagsAllOf: [ 'toto', 'framasoft' ] }
178 await check(search, false) 175 await check(search, false)
179 } 176 }
180 177
181 { 178 {
182 const search = immutableAssign(baseSearch, { durationMin: 2000 }) 179 const search = { ...baseSearch, durationMin: 2000 }
183 await check(search, false) 180 await check(search, false)
184 } 181 }
185 182
186 { 183 {
187 const search = immutableAssign(baseSearch, { nsfw: 'true' }) 184 const search = { ...baseSearch, nsfw: 'true' as BooleanBothQuery }
188 await check(search, false) 185 await check(search, false)
189 } 186 }
190 187
191 { 188 {
192 const search = immutableAssign(baseSearch, { nsfw: 'false' }) 189 const search = { ...baseSearch, nsfw: 'false' as BooleanBothQuery }
193 await check(search, true) 190 await check(search, true)
194 } 191 }
195 192
196 { 193 {
197 const search = immutableAssign(baseSearch, { nsfw: 'both' }) 194 const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery }
198 await check(search, true) 195 await check(search, true)
199 } 196 }
200 }) 197 })
@@ -206,37 +203,44 @@ describe('Test videos search', function () {
206 count: 5 203 count: 5
207 } 204 }
208 205
209 const res = await advancedVideosSearch(server.url, search) 206 const body = await command.advancedVideoSearch({ search })
210 207
211 expect(res.body.total).to.be.greaterThan(5) 208 expect(body.total).to.be.greaterThan(5)
212 expect(res.body.data).to.have.lengthOf(5) 209 expect(body.data).to.have.lengthOf(5)
213 }) 210 })
214 211
215 it('Should use the nsfw instance policy as default', async function () { 212 it('Should use the nsfw instance policy as default', async function () {
216 let nsfwUUID: string 213 let nsfwUUID: string
217 214
218 { 215 {
219 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'display' } }) 216 await server.config.updateCustomSubConfig({
217 newConfig: {
218 instance: { defaultNSFWPolicy: 'display' }
219 }
220 })
220 221
221 const res = await searchVideo(server.url, 'NSFW search index', '-match') 222 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
222 const video = res.body.data[0] as Video 223 expect(body.data).to.have.length.greaterThan(0)
223 224
224 expect(res.body.data).to.have.length.greaterThan(0) 225 const video = body.data[0]
225 expect(video.nsfw).to.be.true 226 expect(video.nsfw).to.be.true
226 227
227 nsfwUUID = video.uuid 228 nsfwUUID = video.uuid
228 } 229 }
229 230
230 { 231 {
231 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'do_not_list' } }) 232 await server.config.updateCustomSubConfig({
233 newConfig: {
234 instance: { defaultNSFWPolicy: 'do_not_list' }
235 }
236 })
232 237
233 const res = await searchVideo(server.url, 'NSFW search index', '-match') 238 const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' })
234 239
235 try { 240 try {
236 expect(res.body.data).to.have.lengthOf(0) 241 expect(body.data).to.have.lengthOf(0)
237 } catch (err) { 242 } catch {
238 // 243 const video = body.data[0]
239 const video = res.body.data[0] as Video
240 244
241 expect(video.uuid).not.equal(nsfwUUID) 245 expect(video.uuid).not.equal(nsfwUUID)
242 } 246 }
@@ -247,19 +251,19 @@ describe('Test videos search', function () {
247 describe('Channels search', async function () { 251 describe('Channels search', async function () {
248 252
249 it('Should make a simple search and not have results', async function () { 253 it('Should make a simple search and not have results', async function () {
250 const res = await searchVideoChannel(server.url, 'a'.repeat(500)) 254 const body = await command.searchChannels({ search: 'a'.repeat(500) })
251 255
252 expect(res.body.total).to.equal(0) 256 expect(body.total).to.equal(0)
253 expect(res.body.data).to.have.lengthOf(0) 257 expect(body.data).to.have.lengthOf(0)
254 }) 258 })
255 259
256 it('Should make a search and have results', async function () { 260 it('Should make a search and have results', async function () {
257 const res = await advancedVideoChannelSearch(server.url, { search: 'Framasoft', sort: 'createdAt' }) 261 const body = await command.advancedChannelSearch({ search: { search: 'Framasoft', sort: 'createdAt' } })
258 262
259 expect(res.body.total).to.be.greaterThan(0) 263 expect(body.total).to.be.greaterThan(0)
260 expect(res.body.data).to.have.length.greaterThan(0) 264 expect(body.data).to.have.length.greaterThan(0)
261 265
262 const videoChannel: VideoChannel = res.body.data[0] 266 const videoChannel = body.data[0]
263 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') 267 expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8')
264 expect(videoChannel.host).to.equal('framatube.org') 268 expect(videoChannel.host).to.equal('framatube.org')
265 expect(videoChannel.avatar).to.exist 269 expect(videoChannel.avatar).to.exist
@@ -272,29 +276,29 @@ describe('Test videos search', function () {
272 }) 276 })
273 277
274 it('Should have a correct pagination', async function () { 278 it('Should have a correct pagination', async function () {
275 const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 }) 279 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
276 280
277 expect(res.body.total).to.be.greaterThan(2) 281 expect(body.total).to.be.greaterThan(2)
278 expect(res.body.data).to.have.lengthOf(2) 282 expect(body.data).to.have.lengthOf(2)
279 }) 283 })
280 }) 284 })
281 285
282 describe('Playlists search', async function () { 286 describe('Playlists search', async function () {
283 287
284 it('Should make a simple search and not have results', async function () { 288 it('Should make a simple search and not have results', async function () {
285 const res = await searchVideoPlaylists(server.url, 'a'.repeat(500)) 289 const body = await command.searchPlaylists({ search: 'a'.repeat(500) })
286 290
287 expect(res.body.total).to.equal(0) 291 expect(body.total).to.equal(0)
288 expect(res.body.data).to.have.lengthOf(0) 292 expect(body.data).to.have.lengthOf(0)
289 }) 293 })
290 294
291 it('Should make a search and have results', async function () { 295 it('Should make a search and have results', async function () {
292 const res = await advancedVideoPlaylistSearch(server.url, { search: 'E2E playlist', sort: '-match' }) 296 const body = await command.advancedPlaylistSearch({ search: { search: 'E2E playlist', sort: '-match' } })
293 297
294 expect(res.body.total).to.be.greaterThan(0) 298 expect(body.total).to.be.greaterThan(0)
295 expect(res.body.data).to.have.length.greaterThan(0) 299 expect(body.data).to.have.length.greaterThan(0)
296 300
297 const videoPlaylist: VideoPlaylist = res.body.data[0] 301 const videoPlaylist = body.data[0]
298 302
299 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') 303 expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a')
300 expect(videoPlaylist.thumbnailUrl).to.exist 304 expect(videoPlaylist.thumbnailUrl).to.exist
@@ -322,10 +326,10 @@ describe('Test videos search', function () {
322 }) 326 })
323 327
324 it('Should have a correct pagination', async function () { 328 it('Should have a correct pagination', async function () {
325 const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 }) 329 const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } })
326 330
327 expect(res.body.total).to.be.greaterThan(2) 331 expect(body.total).to.be.greaterThan(2)
328 expect(res.body.data).to.have.lengthOf(2) 332 expect(body.data).to.have.lengthOf(2)
329 }) 333 })
330 }) 334 })
331 335
diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts
index ab17d55e9..22e9b8fca 100644
--- a/server/tests/api/search/search-playlists.ts
+++ b/server/tests/api/search/search-playlists.ts
@@ -2,82 +2,71 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoPlaylist, VideoPlaylistPrivacy } from '@shared/models'
6import { 5import {
7 addVideoInPlaylist,
8 advancedVideoPlaylistSearch,
9 cleanupTests, 6 cleanupTests,
10 createVideoPlaylist, 7 createSingleServer,
11 flushAndRunServer, 8 PeerTubeServer,
12 searchVideoPlaylists, 9 SearchCommand,
13 ServerInfo,
14 setAccessTokensToServers, 10 setAccessTokensToServers,
15 setDefaultVideoChannel, 11 setDefaultVideoChannel
16 uploadVideoAndGetId 12} from '@shared/extra-utils'
17} from '../../../../shared/extra-utils' 13import { VideoPlaylistPrivacy } from '@shared/models'
18 14
19const expect = chai.expect 15const expect = chai.expect
20 16
21describe('Test playlists search', function () { 17describe('Test playlists search', function () {
22 let server: ServerInfo = null 18 let server: PeerTubeServer = null
19 let command: SearchCommand
23 20
24 before(async function () { 21 before(async function () {
25 this.timeout(30000) 22 this.timeout(30000)
26 23
27 server = await flushAndRunServer(1) 24 server = await createSingleServer(1)
28 25
29 await setAccessTokensToServers([ server ]) 26 await setAccessTokensToServers([ server ])
30 await setDefaultVideoChannel([ server ]) 27 await setDefaultVideoChannel([ server ])
31 28
32 const videoId = (await uploadVideoAndGetId({ server: server, videoName: 'video' })).uuid 29 const videoId = (await server.videos.quickUpload({ name: 'video' })).uuid
33 30
34 { 31 {
35 const attributes = { 32 const attributes = {
36 displayName: 'Dr. Kenzo Tenma hospital videos', 33 displayName: 'Dr. Kenzo Tenma hospital videos',
37 privacy: VideoPlaylistPrivacy.PUBLIC, 34 privacy: VideoPlaylistPrivacy.PUBLIC,
38 videoChannelId: server.videoChannel.id 35 videoChannelId: server.store.channel.id
39 } 36 }
40 const res = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) 37 const created = await server.playlists.create({ attributes })
41 38
42 await addVideoInPlaylist({ 39 await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
43 url: server.url,
44 token: server.accessToken,
45 playlistId: res.body.videoPlaylist.id,
46 elementAttrs: { videoId }
47 })
48 } 40 }
49 41
50 { 42 {
51 const attributes = { 43 const attributes = {
52 displayName: 'Johan & Anna Libert musics', 44 displayName: 'Johan & Anna Libert musics',
53 privacy: VideoPlaylistPrivacy.PUBLIC, 45 privacy: VideoPlaylistPrivacy.PUBLIC,
54 videoChannelId: server.videoChannel.id 46 videoChannelId: server.store.channel.id
55 } 47 }
56 const res = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) 48 const created = await server.playlists.create({ attributes })
57 49
58 await addVideoInPlaylist({ 50 await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } })
59 url: server.url,
60 token: server.accessToken,
61 playlistId: res.body.videoPlaylist.id,
62 elementAttrs: { videoId }
63 })
64 } 51 }
65 52
66 { 53 {
67 const attributes = { 54 const attributes = {
68 displayName: 'Inspector Lunge playlist', 55 displayName: 'Inspector Lunge playlist',
69 privacy: VideoPlaylistPrivacy.PUBLIC, 56 privacy: VideoPlaylistPrivacy.PUBLIC,
70 videoChannelId: server.videoChannel.id 57 videoChannelId: server.store.channel.id
71 } 58 }
72 await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) 59 await server.playlists.create({ attributes })
73 } 60 }
61
62 command = server.search
74 }) 63 })
75 64
76 it('Should make a simple search and not have results', async function () { 65 it('Should make a simple search and not have results', async function () {
77 const res = await searchVideoPlaylists(server.url, 'abc') 66 const body = await command.searchPlaylists({ search: 'abc' })
78 67
79 expect(res.body.total).to.equal(0) 68 expect(body.total).to.equal(0)
80 expect(res.body.data).to.have.lengthOf(0) 69 expect(body.data).to.have.lengthOf(0)
81 }) 70 })
82 71
83 it('Should make a search and have results', async function () { 72 it('Should make a search and have results', async function () {
@@ -87,11 +76,11 @@ describe('Test playlists search', function () {
87 start: 0, 76 start: 0,
88 count: 1 77 count: 1
89 } 78 }
90 const res = await advancedVideoPlaylistSearch(server.url, search) 79 const body = await command.advancedPlaylistSearch({ search })
91 expect(res.body.total).to.equal(1) 80 expect(body.total).to.equal(1)
92 expect(res.body.data).to.have.lengthOf(1) 81 expect(body.data).to.have.lengthOf(1)
93 82
94 const playlist: VideoPlaylist = res.body.data[0] 83 const playlist = body.data[0]
95 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos') 84 expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos')
96 expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid) 85 expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid)
97 } 86 }
@@ -102,11 +91,11 @@ describe('Test playlists search', function () {
102 start: 0, 91 start: 0,
103 count: 1 92 count: 1
104 } 93 }
105 const res = await advancedVideoPlaylistSearch(server.url, search) 94 const body = await command.advancedPlaylistSearch({ search })
106 expect(res.body.total).to.equal(1) 95 expect(body.total).to.equal(1)
107 expect(res.body.data).to.have.lengthOf(1) 96 expect(body.data).to.have.lengthOf(1)
108 97
109 const playlist: VideoPlaylist = res.body.data[0] 98 const playlist = body.data[0]
110 expect(playlist.displayName).to.equal('Johan & Anna Libert musics') 99 expect(playlist.displayName).to.equal('Johan & Anna Libert musics')
111 } 100 }
112 }) 101 })
@@ -117,9 +106,9 @@ describe('Test playlists search', function () {
117 start: 0, 106 start: 0,
118 count: 1 107 count: 1
119 } 108 }
120 const res = await advancedVideoPlaylistSearch(server.url, search) 109 const body = await command.advancedPlaylistSearch({ search })
121 expect(res.body.total).to.equal(0) 110 expect(body.total).to.equal(0)
122 expect(res.body.data).to.have.lengthOf(0) 111 expect(body.data).to.have.lengthOf(0)
123 }) 112 })
124 113
125 after(async function () { 114 after(async function () {
diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts
index 5b8907961..965766742 100644
--- a/server/tests/api/search/search-videos.ts
+++ b/server/tests/api/search/search-videos.ts
@@ -2,37 +2,31 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoPrivacy } from '@shared/models'
6import { 5import {
7 advancedVideosSearch,
8 cleanupTests, 6 cleanupTests,
9 createLive, 7 createSingleServer,
10 flushAndRunServer, 8 PeerTubeServer,
11 immutableAssign, 9 SearchCommand,
12 searchVideo,
13 sendRTMPStreamInVideo,
14 ServerInfo,
15 setAccessTokensToServers, 10 setAccessTokensToServers,
16 setDefaultVideoChannel, 11 setDefaultVideoChannel,
17 stopFfmpeg, 12 stopFfmpeg,
18 updateCustomSubConfig, 13 wait
19 uploadVideo, 14} from '@shared/extra-utils'
20 wait, 15import { VideoPrivacy } from '@shared/models'
21 waitUntilLivePublished
22} from '../../../../shared/extra-utils'
23import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
24 16
25const expect = chai.expect 17const expect = chai.expect
26 18
27describe('Test videos search', function () { 19describe('Test videos search', function () {
28 let server: ServerInfo = null 20 let server: PeerTubeServer = null
29 let startDate: string 21 let startDate: string
30 let videoUUID: string 22 let videoUUID: string
31 23
24 let command: SearchCommand
25
32 before(async function () { 26 before(async function () {
33 this.timeout(60000) 27 this.timeout(60000)
34 28
35 server = await flushAndRunServer(1) 29 server = await createSingleServer(1)
36 30
37 await setAccessTokensToServers([ server ]) 31 await setAccessTokensToServers([ server ])
38 await setDefaultVideoChannel([ server ]) 32 await setDefaultVideoChannel([ server ])
@@ -46,57 +40,49 @@ describe('Test videos search', function () {
46 nsfw: false, 40 nsfw: false,
47 language: 'fr' 41 language: 'fr'
48 } 42 }
49 await uploadVideo(server.url, server.accessToken, attributes1) 43 await server.videos.upload({ attributes: attributes1 })
50 44
51 const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }) 45 const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }
52 await uploadVideo(server.url, server.accessToken, attributes2) 46 await server.videos.upload({ attributes: attributes2 })
53 47
54 { 48 {
55 const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: undefined }) 49 const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined }
56 const res = await uploadVideo(server.url, server.accessToken, attributes3) 50 const { id, uuid } = await server.videos.upload({ attributes: attributes3 })
57 const videoId = res.body.video.id 51 videoUUID = uuid
58 videoUUID = res.body.video.uuid 52
59 53 await server.captions.add({
60 await createVideoCaption({
61 url: server.url,
62 accessToken: server.accessToken,
63 language: 'en', 54 language: 'en',
64 videoId, 55 videoId: id,
65 fixture: 'subtitle-good2.vtt', 56 fixture: 'subtitle-good2.vtt',
66 mimeType: 'application/octet-stream' 57 mimeType: 'application/octet-stream'
67 }) 58 })
68 59
69 await createVideoCaption({ 60 await server.captions.add({
70 url: server.url,
71 accessToken: server.accessToken,
72 language: 'aa', 61 language: 'aa',
73 videoId, 62 videoId: id,
74 fixture: 'subtitle-good2.vtt', 63 fixture: 'subtitle-good2.vtt',
75 mimeType: 'application/octet-stream' 64 mimeType: 'application/octet-stream'
76 }) 65 })
77 } 66 }
78 67
79 const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true }) 68 const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true }
80 await uploadVideo(server.url, server.accessToken, attributes4) 69 await server.videos.upload({ attributes: attributes4 })
81 70
82 await wait(1000) 71 await wait(1000)
83 72
84 startDate = new Date().toISOString() 73 startDate = new Date().toISOString()
85 74
86 const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2, language: undefined }) 75 const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined }
87 await uploadVideo(server.url, server.accessToken, attributes5) 76 await server.videos.upload({ attributes: attributes5 })
88 77
89 const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }) 78 const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }
90 await uploadVideo(server.url, server.accessToken, attributes6) 79 await server.videos.upload({ attributes: attributes6 })
91 80
92 const attributes7 = immutableAssign(attributes1, { 81 const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' }
93 name: attributes1.name + ' - 7', 82 await server.videos.upload({ attributes: attributes7 })
94 originallyPublishedAt: '2019-02-12T09:58:08.286Z'
95 })
96 await uploadVideo(server.url, server.accessToken, attributes7)
97 83
98 const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 }) 84 const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 }
99 await uploadVideo(server.url, server.accessToken, attributes8) 85 await server.videos.upload({ attributes: attributes8 })
100 } 86 }
101 87
102 { 88 {
@@ -107,9 +93,9 @@ describe('Test videos search', function () {
107 licence: 2, 93 licence: 2,
108 language: 'en' 94 language: 'en'
109 } 95 }
110 await uploadVideo(server.url, server.accessToken, attributes) 96 await server.videos.upload({ attributes: attributes })
111 97
112 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' })) 98 await server.videos.upload({ attributes: { ...attributes, name: attributes.name + ' duplicate' } })
113 } 99 }
114 100
115 { 101 {
@@ -120,7 +106,7 @@ describe('Test videos search', function () {
120 licence: 3, 106 licence: 3,
121 language: 'pl' 107 language: 'pl'
122 } 108 }
123 await uploadVideo(server.url, server.accessToken, attributes) 109 await server.videos.upload({ attributes: attributes })
124 } 110 }
125 111
126 { 112 {
@@ -129,11 +115,11 @@ describe('Test videos search', function () {
129 tags: [ 'aaaa', 'bbbb', 'cccc' ], 115 tags: [ 'aaaa', 'bbbb', 'cccc' ],
130 category: 1 116 category: 1
131 } 117 }
132 await uploadVideo(server.url, server.accessToken, attributes1) 118 await server.videos.upload({ attributes: attributes1 })
133 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) 119 await server.videos.upload({ attributes: { ...attributes1, category: 2 } })
134 120
135 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] })) 121 await server.videos.upload({ attributes: { ...attributes1, tags: [ 'cccc', 'dddd' ] } })
136 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] })) 122 await server.videos.upload({ attributes: { ...attributes1, tags: [ 'eeee', 'ffff' ] } })
137 } 123 }
138 124
139 { 125 {
@@ -141,24 +127,26 @@ describe('Test videos search', function () {
141 name: 'aaaa 2', 127 name: 'aaaa 2',
142 category: 1 128 category: 1
143 } 129 }
144 await uploadVideo(server.url, server.accessToken, attributes1) 130 await server.videos.upload({ attributes: attributes1 })
145 await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) 131 await server.videos.upload({ attributes: { ...attributes1, category: 2 } })
146 } 132 }
133
134 command = server.search
147 }) 135 })
148 136
149 it('Should make a simple search and not have results', async function () { 137 it('Should make a simple search and not have results', async function () {
150 const res = await searchVideo(server.url, 'abc') 138 const body = await command.searchVideos({ search: 'abc' })
151 139
152 expect(res.body.total).to.equal(0) 140 expect(body.total).to.equal(0)
153 expect(res.body.data).to.have.lengthOf(0) 141 expect(body.data).to.have.lengthOf(0)
154 }) 142 })
155 143
156 it('Should make a simple search and have results', async function () { 144 it('Should make a simple search and have results', async function () {
157 const res = await searchVideo(server.url, '4444 5555 duplicate') 145 const body = await command.searchVideos({ search: '4444 5555 duplicate' })
158 146
159 expect(res.body.total).to.equal(2) 147 expect(body.total).to.equal(2)
160 148
161 const videos = res.body.data 149 const videos = body.data
162 expect(videos).to.have.lengthOf(2) 150 expect(videos).to.have.lengthOf(2)
163 151
164 // bestmatch 152 // bestmatch
@@ -167,15 +155,15 @@ describe('Test videos search', function () {
167 }) 155 })
168 156
169 it('Should make a search on tags too, and have results', async function () { 157 it('Should make a search on tags too, and have results', async function () {
170 const query = { 158 const search = {
171 search: 'aaaa', 159 search: 'aaaa',
172 categoryOneOf: [ 1 ] 160 categoryOneOf: [ 1 ]
173 } 161 }
174 const res = await advancedVideosSearch(server.url, query) 162 const body = await command.advancedVideoSearch({ search })
175 163
176 expect(res.body.total).to.equal(2) 164 expect(body.total).to.equal(2)
177 165
178 const videos = res.body.data 166 const videos = body.data
179 expect(videos).to.have.lengthOf(2) 167 expect(videos).to.have.lengthOf(2)
180 168
181 // bestmatch 169 // bestmatch
@@ -184,14 +172,14 @@ describe('Test videos search', function () {
184 }) 172 })
185 173
186 it('Should filter on tags without a search', async function () { 174 it('Should filter on tags without a search', async function () {
187 const query = { 175 const search = {
188 tagsAllOf: [ 'bbbb' ] 176 tagsAllOf: [ 'bbbb' ]
189 } 177 }
190 const res = await advancedVideosSearch(server.url, query) 178 const body = await command.advancedVideoSearch({ search })
191 179
192 expect(res.body.total).to.equal(2) 180 expect(body.total).to.equal(2)
193 181
194 const videos = res.body.data 182 const videos = body.data
195 expect(videos).to.have.lengthOf(2) 183 expect(videos).to.have.lengthOf(2)
196 184
197 expect(videos[0].name).to.equal('9999') 185 expect(videos[0].name).to.equal('9999')
@@ -199,14 +187,14 @@ describe('Test videos search', function () {
199 }) 187 })
200 188
201 it('Should filter on category without a search', async function () { 189 it('Should filter on category without a search', async function () {
202 const query = { 190 const search = {
203 categoryOneOf: [ 3 ] 191 categoryOneOf: [ 3 ]
204 } 192 }
205 const res = await advancedVideosSearch(server.url, query) 193 const body = await command.advancedVideoSearch({ search: search })
206 194
207 expect(res.body.total).to.equal(1) 195 expect(body.total).to.equal(1)
208 196
209 const videos = res.body.data 197 const videos = body.data
210 expect(videos).to.have.lengthOf(1) 198 expect(videos).to.have.lengthOf(1)
211 199
212 expect(videos[0].name).to.equal('6666 7777 8888') 200 expect(videos[0].name).to.equal('6666 7777 8888')
@@ -218,11 +206,16 @@ describe('Test videos search', function () {
218 categoryOneOf: [ 1 ], 206 categoryOneOf: [ 1 ],
219 tagsOneOf: [ 'aAaa', 'ffff' ] 207 tagsOneOf: [ 'aAaa', 'ffff' ]
220 } 208 }
221 const res1 = await advancedVideosSearch(server.url, query)
222 expect(res1.body.total).to.equal(2)
223 209
224 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] })) 210 {
225 expect(res2.body.total).to.equal(0) 211 const body = await command.advancedVideoSearch({ search: query })
212 expect(body.total).to.equal(2)
213 }
214
215 {
216 const body = await command.advancedVideoSearch({ search: { ...query, tagsOneOf: [ 'blabla' ] } })
217 expect(body.total).to.equal(0)
218 }
226 }) 219 })
227 220
228 it('Should search by tags (all of)', async function () { 221 it('Should search by tags (all of)', async function () {
@@ -231,14 +224,21 @@ describe('Test videos search', function () {
231 categoryOneOf: [ 1 ], 224 categoryOneOf: [ 1 ],
232 tagsAllOf: [ 'CCcc' ] 225 tagsAllOf: [ 'CCcc' ]
233 } 226 }
234 const res1 = await advancedVideosSearch(server.url, query)
235 expect(res1.body.total).to.equal(2)
236 227
237 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blAbla' ] })) 228 {
238 expect(res2.body.total).to.equal(0) 229 const body = await command.advancedVideoSearch({ search: query })
230 expect(body.total).to.equal(2)
231 }
239 232
240 const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'CCCC' ] })) 233 {
241 expect(res3.body.total).to.equal(1) 234 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'blAbla' ] } })
235 expect(body.total).to.equal(0)
236 }
237
238 {
239 const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'bbbb', 'CCCC' ] } })
240 expect(body.total).to.equal(1)
241 }
242 }) 242 })
243 243
244 it('Should search by category', async function () { 244 it('Should search by category', async function () {
@@ -246,12 +246,17 @@ describe('Test videos search', function () {
246 search: '6666', 246 search: '6666',
247 categoryOneOf: [ 3 ] 247 categoryOneOf: [ 3 ]
248 } 248 }
249 const res1 = await advancedVideosSearch(server.url, query)
250 expect(res1.body.total).to.equal(1)
251 expect(res1.body.data[0].name).to.equal('6666 7777 8888')
252 249
253 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] })) 250 {
254 expect(res2.body.total).to.equal(0) 251 const body = await command.advancedVideoSearch({ search: query })
252 expect(body.total).to.equal(1)
253 expect(body.data[0].name).to.equal('6666 7777 8888')
254 }
255
256 {
257 const body = await command.advancedVideoSearch({ search: { ...query, categoryOneOf: [ 2 ] } })
258 expect(body.total).to.equal(0)
259 }
255 }) 260 })
256 261
257 it('Should search by licence', async function () { 262 it('Should search by licence', async function () {
@@ -259,13 +264,18 @@ describe('Test videos search', function () {
259 search: '4444 5555', 264 search: '4444 5555',
260 licenceOneOf: [ 2 ] 265 licenceOneOf: [ 2 ]
261 } 266 }
262 const res1 = await advancedVideosSearch(server.url, query)
263 expect(res1.body.total).to.equal(2)
264 expect(res1.body.data[0].name).to.equal('3333 4444 5555')
265 expect(res1.body.data[1].name).to.equal('3333 4444 5555 duplicate')
266 267
267 const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] })) 268 {
268 expect(res2.body.total).to.equal(0) 269 const body = await command.advancedVideoSearch({ search: query })
270 expect(body.total).to.equal(2)
271 expect(body.data[0].name).to.equal('3333 4444 5555')
272 expect(body.data[1].name).to.equal('3333 4444 5555 duplicate')
273 }
274
275 {
276 const body = await command.advancedVideoSearch({ search: { ...query, licenceOneOf: [ 3 ] } })
277 expect(body.total).to.equal(0)
278 }
269 }) 279 })
270 280
271 it('Should search by languages', async function () { 281 it('Should search by languages', async function () {
@@ -275,23 +285,23 @@ describe('Test videos search', function () {
275 } 285 }
276 286
277 { 287 {
278 const res = await advancedVideosSearch(server.url, query) 288 const body = await command.advancedVideoSearch({ search: query })
279 expect(res.body.total).to.equal(2) 289 expect(body.total).to.equal(2)
280 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') 290 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
281 expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4') 291 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
282 } 292 }
283 293
284 { 294 {
285 const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'pl', 'en', '_unknown' ] })) 295 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'pl', 'en', '_unknown' ] } })
286 expect(res.body.total).to.equal(3) 296 expect(body.total).to.equal(3)
287 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') 297 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
288 expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4') 298 expect(body.data[1].name).to.equal('1111 2222 3333 - 4')
289 expect(res.body.data[2].name).to.equal('1111 2222 3333 - 5') 299 expect(body.data[2].name).to.equal('1111 2222 3333 - 5')
290 } 300 }
291 301
292 { 302 {
293 const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] })) 303 const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'eo' ] } })
294 expect(res.body.total).to.equal(0) 304 expect(body.total).to.equal(0)
295 } 305 }
296 }) 306 })
297 307
@@ -301,10 +311,10 @@ describe('Test videos search', function () {
301 startDate 311 startDate
302 } 312 }
303 313
304 const res = await advancedVideosSearch(server.url, query) 314 const body = await command.advancedVideoSearch({ search: query })
305 expect(res.body.total).to.equal(4) 315 expect(body.total).to.equal(4)
306 316
307 const videos = res.body.data 317 const videos = body.data
308 expect(videos[0].name).to.equal('1111 2222 3333 - 5') 318 expect(videos[0].name).to.equal('1111 2222 3333 - 5')
309 expect(videos[1].name).to.equal('1111 2222 3333 - 6') 319 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
310 expect(videos[2].name).to.equal('1111 2222 3333 - 7') 320 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
@@ -320,10 +330,10 @@ describe('Test videos search', function () {
320 licenceOneOf: [ 1, 4 ] 330 licenceOneOf: [ 1, 4 ]
321 } 331 }
322 332
323 const res = await advancedVideosSearch(server.url, query) 333 const body = await command.advancedVideoSearch({ search: query })
324 expect(res.body.total).to.equal(4) 334 expect(body.total).to.equal(4)
325 335
326 const videos = res.body.data 336 const videos = body.data
327 expect(videos[0].name).to.equal('1111 2222 3333') 337 expect(videos[0].name).to.equal('1111 2222 3333')
328 expect(videos[1].name).to.equal('1111 2222 3333 - 6') 338 expect(videos[1].name).to.equal('1111 2222 3333 - 6')
329 expect(videos[2].name).to.equal('1111 2222 3333 - 7') 339 expect(videos[2].name).to.equal('1111 2222 3333 - 7')
@@ -340,10 +350,10 @@ describe('Test videos search', function () {
340 sort: '-name' 350 sort: '-name'
341 } 351 }
342 352
343 const res = await advancedVideosSearch(server.url, query) 353 const body = await command.advancedVideoSearch({ search: query })
344 expect(res.body.total).to.equal(4) 354 expect(body.total).to.equal(4)
345 355
346 const videos = res.body.data 356 const videos = body.data
347 expect(videos[0].name).to.equal('1111 2222 3333 - 8') 357 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
348 expect(videos[1].name).to.equal('1111 2222 3333 - 7') 358 expect(videos[1].name).to.equal('1111 2222 3333 - 7')
349 expect(videos[2].name).to.equal('1111 2222 3333 - 6') 359 expect(videos[2].name).to.equal('1111 2222 3333 - 6')
@@ -362,10 +372,10 @@ describe('Test videos search', function () {
362 count: 1 372 count: 1
363 } 373 }
364 374
365 const res = await advancedVideosSearch(server.url, query) 375 const body = await command.advancedVideoSearch({ search: query })
366 expect(res.body.total).to.equal(4) 376 expect(body.total).to.equal(4)
367 377
368 const videos = res.body.data 378 const videos = body.data
369 expect(videos[0].name).to.equal('1111 2222 3333 - 8') 379 expect(videos[0].name).to.equal('1111 2222 3333 - 8')
370 }) 380 })
371 381
@@ -381,10 +391,10 @@ describe('Test videos search', function () {
381 count: 1 391 count: 1
382 } 392 }
383 393
384 const res = await advancedVideosSearch(server.url, query) 394 const body = await command.advancedVideoSearch({ search: query })
385 expect(res.body.total).to.equal(4) 395 expect(body.total).to.equal(4)
386 396
387 const videos = res.body.data 397 const videos = body.data
388 expect(videos[0].name).to.equal('1111 2222 3333') 398 expect(videos[0].name).to.equal('1111 2222 3333')
389 }) 399 })
390 400
@@ -398,99 +408,102 @@ describe('Test videos search', function () {
398 } 408 }
399 409
400 { 410 {
401 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }) 411 const query = { ...baseQuery, originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }
402 const res = await advancedVideosSearch(server.url, query) 412 const body = await command.advancedVideoSearch({ search: query })
403 413
404 expect(res.body.total).to.equal(1) 414 expect(body.total).to.equal(1)
405 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') 415 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
406 } 416 }
407 417
408 { 418 {
409 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }) 419 const query = { ...baseQuery, originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }
410 const res = await advancedVideosSearch(server.url, query) 420 const body = await command.advancedVideoSearch({ search: query })
411 421
412 expect(res.body.total).to.equal(1) 422 expect(body.total).to.equal(1)
413 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') 423 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
414 } 424 }
415 425
416 { 426 {
417 const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }) 427 const query = { ...baseQuery, originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }
418 const res = await advancedVideosSearch(server.url, query) 428 const body = await command.advancedVideoSearch({ search: query })
419 429
420 expect(res.body.total).to.equal(0) 430 expect(body.total).to.equal(0)
421 } 431 }
422 432
423 { 433 {
424 const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }) 434 const query = { ...baseQuery, originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }
425 const res = await advancedVideosSearch(server.url, query) 435 const body = await command.advancedVideoSearch({ search: query })
426 436
427 expect(res.body.total).to.equal(0) 437 expect(body.total).to.equal(0)
428 } 438 }
429 439
430 { 440 {
431 const query = immutableAssign(baseQuery, { 441 const query = {
442 ...baseQuery,
432 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', 443 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
433 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z' 444 originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
434 }) 445 }
435 const res = await advancedVideosSearch(server.url, query) 446 const body = await command.advancedVideoSearch({ search: query })
436 447
437 expect(res.body.total).to.equal(0) 448 expect(body.total).to.equal(0)
438 } 449 }
439 450
440 { 451 {
441 const query = immutableAssign(baseQuery, { 452 const query = {
453 ...baseQuery,
442 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', 454 originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
443 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z' 455 originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
444 }) 456 }
445 const res = await advancedVideosSearch(server.url, query) 457 const body = await command.advancedVideoSearch({ search: query })
446 458
447 expect(res.body.total).to.equal(1) 459 expect(body.total).to.equal(1)
448 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') 460 expect(body.data[0].name).to.equal('1111 2222 3333 - 7')
449 } 461 }
450 }) 462 })
451 463
452 it('Should search by UUID', async function () { 464 it('Should search by UUID', async function () {
453 const search = videoUUID 465 const search = videoUUID
454 const res = await advancedVideosSearch(server.url, { search }) 466 const body = await command.advancedVideoSearch({ search: { search } })
455 467
456 expect(res.body.total).to.equal(1) 468 expect(body.total).to.equal(1)
457 expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') 469 expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
458 }) 470 })
459 471
460 it('Should search by live', async function () { 472 it('Should search by live', async function () {
461 this.timeout(30000) 473 this.timeout(30000)
462 474
463 { 475 {
464 const options = { 476 const newConfig = {
465 search: { 477 search: {
466 searchIndex: { enabled: false } 478 searchIndex: { enabled: false }
467 }, 479 },
468 live: { enabled: true } 480 live: { enabled: true }
469 } 481 }
470 await updateCustomSubConfig(server.url, server.accessToken, options) 482 await server.config.updateCustomSubConfig({ newConfig })
471 } 483 }
472 484
473 { 485 {
474 const res = await advancedVideosSearch(server.url, { isLive: true }) 486 const body = await command.advancedVideoSearch({ search: { isLive: true } })
475 487
476 expect(res.body.total).to.equal(0) 488 expect(body.total).to.equal(0)
477 expect(res.body.data).to.have.lengthOf(0) 489 expect(body.data).to.have.lengthOf(0)
478 } 490 }
479 491
480 { 492 {
481 const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.videoChannel.id } 493 const liveCommand = server.live
482 const resLive = await createLive(server.url, server.accessToken, liveOptions) 494
483 const liveVideoId = resLive.body.video.uuid 495 const liveAttributes = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.store.channel.id }
496 const live = await liveCommand.create({ fields: liveAttributes })
484 497
485 const command = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId) 498 const ffmpegCommand = await liveCommand.sendRTMPStreamInVideo({ videoId: live.id })
486 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) 499 await liveCommand.waitUntilPublished({ videoId: live.id })
487 500
488 const res = await advancedVideosSearch(server.url, { isLive: true }) 501 const body = await command.advancedVideoSearch({ search: { isLive: true } })
489 502
490 expect(res.body.total).to.equal(1) 503 expect(body.total).to.equal(1)
491 expect(res.body.data[0].name).to.equal('live') 504 expect(body.data[0].name).to.equal('live')
492 505
493 await stopFfmpeg(command) 506 await stopFfmpeg(ffmpegCommand)
494 } 507 }
495 }) 508 })
496 509