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 { ignoreLoadingBar: this.ignoreLoadingBar, sort: { field: this.sortField, + // if we order by creation date, we want DESC. all other fields are ASC (like unread). order: this.sortField === 'createdAt' ? -1 : 1 } }) 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 { setDefaultPagination, setDefaultSearchSort, videoChannelsSearchSortValidator, - videoChannelsSearchValidator, + videoChannelsListSearchValidator, videosSearchSortValidator, videosSearchValidator } from '../../middlewares' @@ -49,7 +49,7 @@ searchRouter.get('/video-channels', videoChannelsSearchSortValidator, setDefaultSearchSort, optionalAuthenticate, - videoChannelsSearchValidator, + videoChannelsListSearchValidator, asyncMiddleware(searchVideoChannels) ) 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 = [ } ] -const videoChannelsSearchValidator = [ +const videoChannelsListSearchValidator = [ query('search').not().isEmpty().withMessage('Should have a valid search'), query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), @@ -57,6 +57,6 @@ const videoChannelsOwnSearchValidator = [ export { videosSearchValidator, - videoChannelsSearchValidator, + videoChannelsListSearchValidator, videoChannelsOwnSearchValidator } 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 () { it('Should list subscriptions', async function () { { - const res = await listUserSubscriptions(servers[0].url, servers[0].accessToken) + const res = await listUserSubscriptions({ url: servers[0].url, token: servers[0].accessToken }) expect(res.body.total).to.equal(0) expect(res.body.data).to.be.an('array') expect(res.body.data).to.have.lengthOf(0) } { - const res = await listUserSubscriptions(servers[0].url, users[0].accessToken, 'createdAt') + const res = await listUserSubscriptions({ url: servers[0].url, token: users[0].accessToken, sort: 'createdAt' }) expect(res.body.total).to.equal(2) const subscriptions: VideoChannel[] = res.body.data @@ -156,6 +156,34 @@ describe('Test users subscriptions', function () { expect(body['user3_channel@localhost:' + servers[0].port]).to.be.false }) + it('Should search among subscriptions', async function () { + { + const res = await listUserSubscriptions({ + url: servers[0].url, + token: users[0].accessToken, + sort: '-createdAt', + search: 'user3_channel' + }) + expect(res.body.total).to.equal(1) + + const subscriptions = res.body.data + expect(subscriptions).to.have.lengthOf(1) + } + + { + const res = await listUserSubscriptions({ + url: servers[0].url, + token: users[0].accessToken, + sort: '-createdAt', + search: 'toto' + }) + expect(res.body.total).to.equal(0) + + const subscriptions = res.body.data + expect(subscriptions).to.have.lengthOf(0) + } + }) + it('Should list subscription videos', async function () { { 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 () { expect(totoChannel.videosCount).to.equal(0) }) + it('Should search among account video channels', async function () { + { + const res = await getAccountVideoChannelsList({ + url: servers[0].url, + accountName: userInfo.account.name + '@' + userInfo.account.host, + search: 'root' + }) + expect(res.body.total).to.equal(1) + + const channels = res.body.data + expect(channels).to.have.lengthOf(1) + } + + { + const res = await getAccountVideoChannelsList({ + url: servers[0].url, + accountName: userInfo.account.name + '@' + userInfo.account.host, + search: 'does not exist' + }) + expect(res.body.total).to.equal(0) + + const channels = res.body.data + expect(channels).to.have.lengthOf(0) + } + }) + after(async function () { await cleanupTests(servers) }) 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 }) } -function listUserSubscriptions (url: string, token: string, sort = '-createdAt', statusCodeExpected = 200) { +function listUserSubscriptions (parameters: { + url: string + token: string + sort?: string + search?: string + statusCodeExpected?: number +}) { + const { url, token, sort = '-createdAt', search, statusCodeExpected = 200 } = parameters const path = '/api/v1/users/me/subscriptions' return makeGetRequest({ @@ -20,7 +27,10 @@ function listUserSubscriptions (url: string, token: string, sort = '-createdAt', path, token, statusCodeExpected, - query: { sort } + query: { + sort, + search + } }) } 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: { sort?: string specialStatus?: number withStats?: boolean + search?: string }) { - const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200, withStats = false } = parameters + const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200, withStats = false, search } = parameters const path = '/api/v1/accounts/' + accountName + '/video-channels' @@ -44,7 +45,8 @@ function getAccountVideoChannelsList (parameters: { start, count, sort, - withStats + withStats, + search }, statusCodeExpected: specialStatus })