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