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