test search for subscriptions and video-channels

pull/3023/head
Rigel Kent 2020-07-27 17:00:39 +02:00 committed by Rigel Kent
parent 225a7682e6
commit 7b3909644d
7 changed files with 77 additions and 10 deletions

View File

@ -53,6 +53,7 @@ export class UserNotificationsComponent implements OnInit {
ignoreLoadingBar: this.ignoreLoadingBar, ignoreLoadingBar: this.ignoreLoadingBar,
sort: { sort: {
field: this.sortField, 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 order: this.sortField === 'createdAt' ? -1 : 1
} }
}) })

View File

@ -22,7 +22,7 @@ import {
setDefaultPagination, setDefaultPagination,
setDefaultSearchSort, setDefaultSearchSort,
videoChannelsSearchSortValidator, videoChannelsSearchSortValidator,
videoChannelsSearchValidator, videoChannelsListSearchValidator,
videosSearchSortValidator, videosSearchSortValidator,
videosSearchValidator videosSearchValidator
} from '../../middlewares' } from '../../middlewares'
@ -49,7 +49,7 @@ searchRouter.get('/video-channels',
videoChannelsSearchSortValidator, videoChannelsSearchSortValidator,
setDefaultSearchSort, setDefaultSearchSort,
optionalAuthenticate, optionalAuthenticate,
videoChannelsSearchValidator, videoChannelsListSearchValidator,
asyncMiddleware(searchVideoChannels) asyncMiddleware(searchVideoChannels)
) )

View File

@ -28,7 +28,7 @@ const videosSearchValidator = [
} }
] ]
const videoChannelsSearchValidator = [ const videoChannelsListSearchValidator = [
query('search').not().isEmpty().withMessage('Should have a valid search'), query('search').not().isEmpty().withMessage('Should have a valid search'),
query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
@ -57,6 +57,6 @@ const videoChannelsOwnSearchValidator = [
export { export {
videosSearchValidator, videosSearchValidator,
videoChannelsSearchValidator, videoChannelsListSearchValidator,
videoChannelsOwnSearchValidator videoChannelsOwnSearchValidator
} }

View File

@ -96,14 +96,14 @@ describe('Test users subscriptions', function () {
it('Should list subscriptions', async 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.total).to.equal(0)
expect(res.body.data).to.be.an('array') expect(res.body.data).to.be.an('array')
expect(res.body.data).to.have.lengthOf(0) 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) expect(res.body.total).to.equal(2)
const subscriptions: VideoChannel[] = res.body.data 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 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 () { it('Should list subscription videos', async function () {
{ {
const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken)

View File

@ -421,6 +421,32 @@ describe('Test video channels', function () {
expect(totoChannel.videosCount).to.equal(0) 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 () { after(async function () {
await cleanupTests(servers) await cleanupTests(servers)
}) })

View File

@ -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' const path = '/api/v1/users/me/subscriptions'
return makeGetRequest({ return makeGetRequest({
@ -20,7 +27,10 @@ function listUserSubscriptions (url: string, token: string, sort = '-createdAt',
path, path,
token, token,
statusCodeExpected, statusCodeExpected,
query: { sort } query: {
sort,
search
}
}) })
} }

View File

@ -32,8 +32,9 @@ function getAccountVideoChannelsList (parameters: {
sort?: string sort?: string
specialStatus?: number specialStatus?: number
withStats?: boolean 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' const path = '/api/v1/accounts/' + accountName + '/video-channels'
@ -44,7 +45,8 @@ function getAccountVideoChannelsList (parameters: {
start, start,
count, count,
sort, sort,
withStats withStats,
search
}, },
statusCodeExpected: specialStatus statusCodeExpected: specialStatus
}) })