diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-06 15:22:51 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:17 +0200 |
commit | af971e06c620bd46a5aa64c8833364e7022b5e3d (patch) | |
tree | 4288b66b79fe4dd1ab9496e85a3abf7d747ad03a /server/tests/api/search/search-activitypub-videos.ts | |
parent | 23a3a8827cb8b862f5cc7ee2819f39918303beca (diff) | |
download | PeerTube-af971e06c620bd46a5aa64c8833364e7022b5e3d.tar.gz PeerTube-af971e06c620bd46a5aa64c8833364e7022b5e3d.tar.zst PeerTube-af971e06c620bd46a5aa64c8833364e7022b5e3d.zip |
Introduce search command
Diffstat (limited to 'server/tests/api/search/search-activitypub-videos.ts')
-rw-r--r-- | server/tests/api/search/search-activitypub-videos.ts | 81 |
1 files changed, 42 insertions, 39 deletions
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 | ||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | ||
5 | import { | 5 | import { |
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' |
19 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 18 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
20 | import { Video, VideoPrivacy } from '../../../../shared/models/videos' | 19 | import { VideoPrivacy } from '../../../../shared/models/videos' |
21 | 20 | ||
22 | const expect = chai.expect | 21 | const 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 () { |