diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-07-27 17:00:39 +0200 |
---|---|---|
committer | Rigel Kent <par@rigelk.eu> | 2020-07-29 18:15:53 +0200 |
commit | 7b3909644dd7cb8be1caad537bb40605e5f059d4 (patch) | |
tree | 499d23362c0532cd689624a35b98d8f51ba73ed4 | |
parent | 225a7682e68d81c3c90ff50e704db4ab5f81a341 (diff) | |
download | PeerTube-7b3909644dd7cb8be1caad537bb40605e5f059d4.tar.gz PeerTube-7b3909644dd7cb8be1caad537bb40605e5f059d4.tar.zst PeerTube-7b3909644dd7cb8be1caad537bb40605e5f059d4.zip |
test search for subscriptions and video-channels
-rw-r--r-- | client/src/app/shared/shared-main/users/user-notifications.component.ts | 1 | ||||
-rw-r--r-- | server/controllers/api/search.ts | 4 | ||||
-rw-r--r-- | server/middlewares/validators/search.ts | 4 | ||||
-rw-r--r-- | server/tests/api/users/user-subscriptions.ts | 32 | ||||
-rw-r--r-- | server/tests/api/videos/video-channels.ts | 26 | ||||
-rw-r--r-- | shared/extra-utils/users/user-subscriptions.ts | 14 | ||||
-rw-r--r-- | shared/extra-utils/videos/video-channels.ts | 6 |
7 files changed, 77 insertions, 10 deletions
diff --git a/client/src/app/shared/shared-main/users/user-notifications.component.ts b/client/src/app/shared/shared-main/users/user-notifications.component.ts index 48be80e3f..7518dbdd0 100644 --- a/client/src/app/shared/shared-main/users/user-notifications.component.ts +++ b/client/src/app/shared/shared-main/users/user-notifications.component.ts | |||
@@ -53,6 +53,7 @@ export class UserNotificationsComponent implements OnInit { | |||
53 | ignoreLoadingBar: this.ignoreLoadingBar, | 53 | ignoreLoadingBar: this.ignoreLoadingBar, |
54 | sort: { | 54 | sort: { |
55 | field: this.sortField, | 55 | field: this.sortField, |
56 | // if we order by creation date, we want DESC. all other fields are ASC (like unread). | ||
56 | order: this.sortField === 'createdAt' ? -1 : 1 | 57 | order: this.sortField === 'createdAt' ? -1 : 1 |
57 | } | 58 | } |
58 | }) | 59 | }) |
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts index 2d98b5d34..6e2d11d93 100644 --- a/server/controllers/api/search.ts +++ b/server/controllers/api/search.ts | |||
@@ -22,7 +22,7 @@ import { | |||
22 | setDefaultPagination, | 22 | setDefaultPagination, |
23 | setDefaultSearchSort, | 23 | setDefaultSearchSort, |
24 | videoChannelsSearchSortValidator, | 24 | videoChannelsSearchSortValidator, |
25 | videoChannelsSearchValidator, | 25 | videoChannelsListSearchValidator, |
26 | videosSearchSortValidator, | 26 | videosSearchSortValidator, |
27 | videosSearchValidator | 27 | videosSearchValidator |
28 | } from '../../middlewares' | 28 | } from '../../middlewares' |
@@ -49,7 +49,7 @@ searchRouter.get('/video-channels', | |||
49 | videoChannelsSearchSortValidator, | 49 | videoChannelsSearchSortValidator, |
50 | setDefaultSearchSort, | 50 | setDefaultSearchSort, |
51 | optionalAuthenticate, | 51 | optionalAuthenticate, |
52 | videoChannelsSearchValidator, | 52 | videoChannelsListSearchValidator, |
53 | asyncMiddleware(searchVideoChannels) | 53 | asyncMiddleware(searchVideoChannels) |
54 | ) | 54 | ) |
55 | 55 | ||
diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts index 7313bc055..78213c70d 100644 --- a/server/middlewares/validators/search.ts +++ b/server/middlewares/validators/search.ts | |||
@@ -28,7 +28,7 @@ const videosSearchValidator = [ | |||
28 | } | 28 | } |
29 | ] | 29 | ] |
30 | 30 | ||
31 | const videoChannelsSearchValidator = [ | 31 | const videoChannelsListSearchValidator = [ |
32 | query('search').not().isEmpty().withMessage('Should have a valid search'), | 32 | query('search').not().isEmpty().withMessage('Should have a valid search'), |
33 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), | 33 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), |
34 | 34 | ||
@@ -57,6 +57,6 @@ const videoChannelsOwnSearchValidator = [ | |||
57 | 57 | ||
58 | export { | 58 | export { |
59 | videosSearchValidator, | 59 | videosSearchValidator, |
60 | videoChannelsSearchValidator, | 60 | videoChannelsListSearchValidator, |
61 | videoChannelsOwnSearchValidator | 61 | videoChannelsOwnSearchValidator |
62 | } | 62 | } |
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 7d6b0c6a9..60676a37b 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts | |||
@@ -96,14 +96,14 @@ describe('Test users subscriptions', function () { | |||
96 | 96 | ||
97 | it('Should list subscriptions', async function () { | 97 | it('Should list subscriptions', async function () { |
98 | { | 98 | { |
99 | const res = await listUserSubscriptions(servers[0].url, servers[0].accessToken) | 99 | const res = await listUserSubscriptions({ url: servers[0].url, token: servers[0].accessToken }) |
100 | expect(res.body.total).to.equal(0) | 100 | expect(res.body.total).to.equal(0) |
101 | expect(res.body.data).to.be.an('array') | 101 | expect(res.body.data).to.be.an('array') |
102 | expect(res.body.data).to.have.lengthOf(0) | 102 | expect(res.body.data).to.have.lengthOf(0) |
103 | } | 103 | } |
104 | 104 | ||
105 | { | 105 | { |
106 | const res = await listUserSubscriptions(servers[0].url, users[0].accessToken, 'createdAt') | 106 | const res = await listUserSubscriptions({ url: servers[0].url, token: users[0].accessToken, sort: 'createdAt' }) |
107 | expect(res.body.total).to.equal(2) | 107 | expect(res.body.total).to.equal(2) |
108 | 108 | ||
109 | const subscriptions: VideoChannel[] = res.body.data | 109 | const subscriptions: VideoChannel[] = res.body.data |
@@ -156,6 +156,34 @@ describe('Test users subscriptions', function () { | |||
156 | expect(body['user3_channel@localhost:' + servers[0].port]).to.be.false | 156 | expect(body['user3_channel@localhost:' + servers[0].port]).to.be.false |
157 | }) | 157 | }) |
158 | 158 | ||
159 | it('Should search among subscriptions', async function () { | ||
160 | { | ||
161 | const res = await listUserSubscriptions({ | ||
162 | url: servers[0].url, | ||
163 | token: users[0].accessToken, | ||
164 | sort: '-createdAt', | ||
165 | search: 'user3_channel' | ||
166 | }) | ||
167 | expect(res.body.total).to.equal(1) | ||
168 | |||
169 | const subscriptions = res.body.data | ||
170 | expect(subscriptions).to.have.lengthOf(1) | ||
171 | } | ||
172 | |||
173 | { | ||
174 | const res = await listUserSubscriptions({ | ||
175 | url: servers[0].url, | ||
176 | token: users[0].accessToken, | ||
177 | sort: '-createdAt', | ||
178 | search: 'toto' | ||
179 | }) | ||
180 | expect(res.body.total).to.equal(0) | ||
181 | |||
182 | const subscriptions = res.body.data | ||
183 | expect(subscriptions).to.have.lengthOf(0) | ||
184 | } | ||
185 | }) | ||
186 | |||
159 | it('Should list subscription videos', async function () { | 187 | it('Should list subscription videos', async function () { |
160 | { | 188 | { |
161 | const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) | 189 | const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) |
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 3493a723d..367f99fdd 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts | |||
@@ -421,6 +421,32 @@ describe('Test video channels', function () { | |||
421 | expect(totoChannel.videosCount).to.equal(0) | 421 | expect(totoChannel.videosCount).to.equal(0) |
422 | }) | 422 | }) |
423 | 423 | ||
424 | it('Should search among account video channels', async function () { | ||
425 | { | ||
426 | const res = await getAccountVideoChannelsList({ | ||
427 | url: servers[0].url, | ||
428 | accountName: userInfo.account.name + '@' + userInfo.account.host, | ||
429 | search: 'root' | ||
430 | }) | ||
431 | expect(res.body.total).to.equal(1) | ||
432 | |||
433 | const channels = res.body.data | ||
434 | expect(channels).to.have.lengthOf(1) | ||
435 | } | ||
436 | |||
437 | { | ||
438 | const res = await getAccountVideoChannelsList({ | ||
439 | url: servers[0].url, | ||
440 | accountName: userInfo.account.name + '@' + userInfo.account.host, | ||
441 | search: 'does not exist' | ||
442 | }) | ||
443 | expect(res.body.total).to.equal(0) | ||
444 | |||
445 | const channels = res.body.data | ||
446 | expect(channels).to.have.lengthOf(0) | ||
447 | } | ||
448 | }) | ||
449 | |||
424 | after(async function () { | 450 | after(async function () { |
425 | await cleanupTests(servers) | 451 | await cleanupTests(servers) |
426 | }) | 452 | }) |
diff --git a/shared/extra-utils/users/user-subscriptions.ts b/shared/extra-utils/users/user-subscriptions.ts index 7148fbfca..6d402c073 100644 --- a/shared/extra-utils/users/user-subscriptions.ts +++ b/shared/extra-utils/users/user-subscriptions.ts | |||
@@ -12,7 +12,14 @@ function addUserSubscription (url: string, token: string, targetUri: string, sta | |||
12 | }) | 12 | }) |
13 | } | 13 | } |
14 | 14 | ||
15 | function listUserSubscriptions (url: string, token: string, sort = '-createdAt', statusCodeExpected = 200) { | 15 | function listUserSubscriptions (parameters: { |
16 | url: string | ||
17 | token: string | ||
18 | sort?: string | ||
19 | search?: string | ||
20 | statusCodeExpected?: number | ||
21 | }) { | ||
22 | const { url, token, sort = '-createdAt', search, statusCodeExpected = 200 } = parameters | ||
16 | const path = '/api/v1/users/me/subscriptions' | 23 | const path = '/api/v1/users/me/subscriptions' |
17 | 24 | ||
18 | return makeGetRequest({ | 25 | return makeGetRequest({ |
@@ -20,7 +27,10 @@ function listUserSubscriptions (url: string, token: string, sort = '-createdAt', | |||
20 | path, | 27 | path, |
21 | token, | 28 | token, |
22 | statusCodeExpected, | 29 | statusCodeExpected, |
23 | query: { sort } | 30 | query: { |
31 | sort, | ||
32 | search | ||
33 | } | ||
24 | }) | 34 | }) |
25 | } | 35 | } |
26 | 36 | ||
diff --git a/shared/extra-utils/videos/video-channels.ts b/shared/extra-utils/videos/video-channels.ts index 55f08b996..97b68178f 100644 --- a/shared/extra-utils/videos/video-channels.ts +++ b/shared/extra-utils/videos/video-channels.ts | |||
@@ -32,8 +32,9 @@ function getAccountVideoChannelsList (parameters: { | |||
32 | sort?: string | 32 | sort?: string |
33 | specialStatus?: number | 33 | specialStatus?: number |
34 | withStats?: boolean | 34 | withStats?: boolean |
35 | search?: string | ||
35 | }) { | 36 | }) { |
36 | const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200, withStats = false } = parameters | 37 | const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200, withStats = false, search } = parameters |
37 | 38 | ||
38 | const path = '/api/v1/accounts/' + accountName + '/video-channels' | 39 | const path = '/api/v1/accounts/' + accountName + '/video-channels' |
39 | 40 | ||
@@ -44,7 +45,8 @@ function getAccountVideoChannelsList (parameters: { | |||
44 | start, | 45 | start, |
45 | count, | 46 | count, |
46 | sort, | 47 | sort, |
47 | withStats | 48 | withStats, |
49 | search | ||
48 | }, | 50 | }, |
49 | statusCodeExpected: specialStatus | 51 | statusCodeExpected: specialStatus |
50 | }) | 52 | }) |