diff options
Diffstat (limited to 'server/tests/api')
-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 |
4 files changed, 204 insertions, 1 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) |