diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params/user-subscriptions.ts | 40 | ||||
-rw-r--r-- | server/tests/api/users/user-subscriptions.ts | 19 | ||||
-rw-r--r-- | server/tests/utils/users/user-subscriptions.ts | 13 |
3 files changed, 71 insertions, 1 deletions
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts index 6a6dd9a6f..9fba99ac8 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts | |||
@@ -202,6 +202,46 @@ describe('Test user subscriptions API validators', function () { | |||
202 | }) | 202 | }) |
203 | }) | 203 | }) |
204 | 204 | ||
205 | describe('When checking if subscriptions exist', async function () { | ||
206 | const existPath = path + '/exist' | ||
207 | |||
208 | it('Should fail with a non authenticated user', async function () { | ||
209 | await makeGetRequest({ | ||
210 | url: server.url, | ||
211 | path: existPath, | ||
212 | statusCodeExpected: 401 | ||
213 | }) | ||
214 | }) | ||
215 | |||
216 | it('Should fail with bad URIs', async function () { | ||
217 | await makeGetRequest({ | ||
218 | url: server.url, | ||
219 | path: existPath, | ||
220 | query: { uris: 'toto' }, | ||
221 | token: server.accessToken, | ||
222 | statusCodeExpected: 400 | ||
223 | }) | ||
224 | |||
225 | await makeGetRequest({ | ||
226 | url: server.url, | ||
227 | path: existPath, | ||
228 | query: { 'uris[]': 1 }, | ||
229 | token: server.accessToken, | ||
230 | statusCodeExpected: 400 | ||
231 | }) | ||
232 | }) | ||
233 | |||
234 | it('Should succeed with the correct parameters', async function () { | ||
235 | await makeGetRequest({ | ||
236 | url: server.url, | ||
237 | path: existPath, | ||
238 | query: { 'uris[]': 'coucou@localhost:9001' }, | ||
239 | token: server.accessToken, | ||
240 | statusCodeExpected: 200 | ||
241 | }) | ||
242 | }) | ||
243 | }) | ||
244 | |||
205 | describe('When removing a subscription', function () { | 245 | describe('When removing a subscription', function () { |
206 | it('Should fail with a non authenticated user', async function () { | 246 | it('Should fail with a non authenticated user', async function () { |
207 | await makeDeleteRequest({ | 247 | await makeDeleteRequest({ |
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index cb7d94b0b..65b80540c 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts | |||
@@ -12,7 +12,7 @@ import { | |||
12 | listUserSubscriptions, | 12 | listUserSubscriptions, |
13 | listUserSubscriptionVideos, | 13 | listUserSubscriptionVideos, |
14 | removeUserSubscription, | 14 | removeUserSubscription, |
15 | getUserSubscription | 15 | getUserSubscription, areSubscriptionsExist |
16 | } from '../../utils/users/user-subscriptions' | 16 | } from '../../utils/users/user-subscriptions' |
17 | 17 | ||
18 | const expect = chai.expect | 18 | const expect = chai.expect |
@@ -128,6 +128,23 @@ describe('Test users subscriptions', function () { | |||
128 | } | 128 | } |
129 | }) | 129 | }) |
130 | 130 | ||
131 | it('Should return the existing subscriptions', async function () { | ||
132 | const uris = [ | ||
133 | 'user3_channel@localhost:9003', | ||
134 | 'root2_channel@localhost:9001', | ||
135 | 'root_channel@localhost:9001', | ||
136 | 'user3_channel@localhost:9001' | ||
137 | ] | ||
138 | |||
139 | const res = await areSubscriptionsExist(servers[ 0 ].url, users[ 0 ].accessToken, uris) | ||
140 | const body = res.body | ||
141 | |||
142 | expect(body['user3_channel@localhost:9003']).to.be.true | ||
143 | expect(body['root2_channel@localhost:9001']).to.be.false | ||
144 | expect(body['root_channel@localhost:9001']).to.be.true | ||
145 | expect(body['user3_channel@localhost:9001']).to.be.false | ||
146 | }) | ||
147 | |||
131 | it('Should list subscription videos', async function () { | 148 | it('Should list subscription videos', async function () { |
132 | { | 149 | { |
133 | const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) | 150 | const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) |
diff --git a/server/tests/utils/users/user-subscriptions.ts b/server/tests/utils/users/user-subscriptions.ts index 852f590cf..b0e7da7cc 100644 --- a/server/tests/utils/users/user-subscriptions.ts +++ b/server/tests/utils/users/user-subscriptions.ts | |||
@@ -58,9 +58,22 @@ function removeUserSubscription (url: string, token: string, uri: string, status | |||
58 | }) | 58 | }) |
59 | } | 59 | } |
60 | 60 | ||
61 | function areSubscriptionsExist (url: string, token: string, uris: string[], statusCodeExpected = 200) { | ||
62 | const path = '/api/v1/users/me/subscriptions/exist' | ||
63 | |||
64 | return makeGetRequest({ | ||
65 | url, | ||
66 | path, | ||
67 | query: { 'uris[]': uris }, | ||
68 | token, | ||
69 | statusCodeExpected | ||
70 | }) | ||
71 | } | ||
72 | |||
61 | // --------------------------------------------------------------------------- | 73 | // --------------------------------------------------------------------------- |
62 | 74 | ||
63 | export { | 75 | export { |
76 | areSubscriptionsExist, | ||
64 | addUserSubscription, | 77 | addUserSubscription, |
65 | listUserSubscriptions, | 78 | listUserSubscriptions, |
66 | getUserSubscription, | 79 | getUserSubscription, |