Introduce overviews command
This commit is contained in:
parent
480d6ea679
commit
23a3a8827c
|
@ -1,8 +1,7 @@
|
||||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||||
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils'
|
import { cleanupTests, flushAndRunServer, ServerInfo } from '@shared/extra-utils'
|
||||||
import { getVideosOverview } from '@shared/extra-utils/overviews/overviews'
|
|
||||||
|
|
||||||
describe('Test videos overview', function () {
|
describe('Test videos overview', function () {
|
||||||
let server: ServerInfo
|
let server: ServerInfo
|
||||||
|
@ -18,12 +17,12 @@ describe('Test videos overview', function () {
|
||||||
describe('When getting videos overview', function () {
|
describe('When getting videos overview', function () {
|
||||||
|
|
||||||
it('Should fail with a bad pagination', async function () {
|
it('Should fail with a bad pagination', async function () {
|
||||||
await getVideosOverview(server.url, 0, 400)
|
await server.overviewsCommand.getVideos({ page: 0, expectedStatus: 400 })
|
||||||
await getVideosOverview(server.url, 100, 400)
|
await server.overviewsCommand.getVideos({ page: 100, expectedStatus: 400 })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should succeed with a good pagination', async function () {
|
it('Should succeed with a good pagination', async function () {
|
||||||
await getVideosOverview(server.url, 1)
|
await server.overviewsCommand.getVideos({ page: 1 })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,34 +1,33 @@
|
||||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||||
|
|
||||||
import * as chai from 'chai'
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import { cleanupTests, getVideosList, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils/index'
|
import * as chai from 'chai'
|
||||||
import { userLogin } from '../../../../shared/extra-utils/users/login'
|
|
||||||
import { createUser } from '../../../../shared/extra-utils/users/users'
|
|
||||||
import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
|
|
||||||
import {
|
import {
|
||||||
|
cleanupTests,
|
||||||
|
createUser,
|
||||||
flushAndRunServer,
|
flushAndRunServer,
|
||||||
getAccountVideos,
|
getAccountVideos,
|
||||||
getConfig,
|
getConfig,
|
||||||
getCustomConfig,
|
getCustomConfig,
|
||||||
getMyUserInformation,
|
getMyUserInformation,
|
||||||
|
getMyVideos,
|
||||||
getVideoChannelVideos,
|
getVideoChannelVideos,
|
||||||
|
getVideosList,
|
||||||
getVideosListWithToken,
|
getVideosListWithToken,
|
||||||
searchVideo,
|
searchVideo,
|
||||||
searchVideoWithToken,
|
searchVideoWithToken,
|
||||||
|
ServerInfo,
|
||||||
|
setAccessTokensToServers,
|
||||||
updateCustomConfig,
|
updateCustomConfig,
|
||||||
updateMyUser
|
updateMyUser,
|
||||||
} from '../../../../shared/extra-utils'
|
uploadVideo,
|
||||||
import { ServerConfig, VideosOverview } from '../../../../shared/models'
|
userLogin
|
||||||
import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
|
} from '@shared/extra-utils'
|
||||||
import { User } from '../../../../shared/models/users'
|
import { CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models'
|
||||||
import { getVideosOverview, getVideosOverviewWithToken } from '@shared/extra-utils/overviews/overviews'
|
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
function createOverviewRes (res: any) {
|
function createOverviewRes (overview: VideosOverview) {
|
||||||
const overview = res.body as VideosOverview
|
|
||||||
|
|
||||||
const videos = overview.categories[0].videos
|
const videos = overview.categories[0].videos
|
||||||
return { body: { data: videos, total: videos.length } }
|
return { body: { data: videos, total: videos.length } }
|
||||||
}
|
}
|
||||||
|
@ -57,7 +56,9 @@ describe('Test video NSFW policy', function () {
|
||||||
|
|
||||||
// Overviews do not support video filters
|
// Overviews do not support video filters
|
||||||
if (!hasQuery) {
|
if (!hasQuery) {
|
||||||
promises.push(getVideosOverviewWithToken(server.url, 1, token).then(res => createOverviewRes(res)))
|
const p = server.overviewsCommand.getVideos({ page: 1, token })
|
||||||
|
.then(res => createOverviewRes(res))
|
||||||
|
promises.push(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
|
@ -72,7 +73,9 @@ describe('Test video NSFW policy', function () {
|
||||||
|
|
||||||
// Overviews do not support video filters
|
// Overviews do not support video filters
|
||||||
if (!hasQuery) {
|
if (!hasQuery) {
|
||||||
promises.push(getVideosOverview(server.url, 1).then(res => createOverviewRes(res)))
|
const p = server.overviewsCommand.getVideos({ page: 1 })
|
||||||
|
.then(res => createOverviewRes(res))
|
||||||
|
promises.push(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
|
import { Response } from 'superagent'
|
||||||
import {
|
import {
|
||||||
|
addAccountToAccountBlocklist,
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
flushAndRunServer,
|
flushAndRunServer,
|
||||||
generateUserAccessToken,
|
generateUserAccessToken,
|
||||||
|
@ -11,20 +12,15 @@ import {
|
||||||
setAccessTokensToServers,
|
setAccessTokensToServers,
|
||||||
uploadVideo,
|
uploadVideo,
|
||||||
wait
|
wait
|
||||||
} from '../../../../shared/extra-utils'
|
} from '@shared/extra-utils'
|
||||||
import { getVideosOverview, getVideosOverviewWithToken } from '../../../../shared/extra-utils/overviews/overviews'
|
import { VideosOverview } from '@shared/models'
|
||||||
import { VideosOverview } from '../../../../shared/models/overviews'
|
|
||||||
import { addAccountToAccountBlocklist } from '@shared/extra-utils/users/blocklist'
|
|
||||||
import { Response } from 'superagent'
|
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
describe('Test a videos overview', function () {
|
describe('Test a videos overview', function () {
|
||||||
let server: ServerInfo = null
|
let server: ServerInfo = null
|
||||||
|
|
||||||
function testOverviewCount (res: Response, expected: number) {
|
function testOverviewCount (overview: VideosOverview, expected: number) {
|
||||||
const overview: VideosOverview = res.body
|
|
||||||
|
|
||||||
expect(overview.tags).to.have.lengthOf(expected)
|
expect(overview.tags).to.have.lengthOf(expected)
|
||||||
expect(overview.categories).to.have.lengthOf(expected)
|
expect(overview.categories).to.have.lengthOf(expected)
|
||||||
expect(overview.channels).to.have.lengthOf(expected)
|
expect(overview.channels).to.have.lengthOf(expected)
|
||||||
|
@ -39,9 +35,9 @@ describe('Test a videos overview', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should send empty overview', async function () {
|
it('Should send empty overview', async function () {
|
||||||
const res = await getVideosOverview(server.url, 1)
|
const body = await server.overviewsCommand.getVideos({ page: 1 })
|
||||||
|
|
||||||
testOverviewCount(res, 0)
|
testOverviewCount(body, 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
|
it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
|
||||||
|
@ -55,14 +51,15 @@ describe('Test a videos overview', function () {
|
||||||
tags: [ 'coucou1', 'coucou2' ]
|
tags: [ 'coucou1', 'coucou2' ]
|
||||||
})
|
})
|
||||||
|
|
||||||
const res = await getVideosOverview(server.url, 1)
|
const body = await server.overviewsCommand.getVideos({ page: 1 })
|
||||||
|
|
||||||
testOverviewCount(res, 0)
|
testOverviewCount(body, 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should upload another video and include all videos in the overview', async function () {
|
it('Should upload another video and include all videos in the overview', async function () {
|
||||||
this.timeout(30000)
|
this.timeout(30000)
|
||||||
|
|
||||||
|
{
|
||||||
for (let i = 1; i < 6; i++) {
|
for (let i = 1; i < 6; i++) {
|
||||||
await uploadVideo(server.url, server.accessToken, {
|
await uploadVideo(server.url, server.accessToken, {
|
||||||
name: 'video ' + i,
|
name: 'video ' + i,
|
||||||
|
@ -72,17 +69,17 @@ describe('Test a videos overview', function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
await wait(3000)
|
await wait(3000)
|
||||||
|
|
||||||
{
|
|
||||||
const res = await getVideosOverview(server.url, 1)
|
|
||||||
|
|
||||||
testOverviewCount(res, 1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const res = await getVideosOverview(server.url, 2)
|
const body = await server.overviewsCommand.getVideos({ page: 1 })
|
||||||
|
|
||||||
|
testOverviewCount(body, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const overview = await server.overviewsCommand.getVideos({ page: 2 })
|
||||||
|
|
||||||
const overview: VideosOverview = res.body
|
|
||||||
expect(overview.tags).to.have.lengthOf(1)
|
expect(overview.tags).to.have.lengthOf(1)
|
||||||
expect(overview.categories).to.have.lengthOf(0)
|
expect(overview.categories).to.have.lengthOf(0)
|
||||||
expect(overview.channels).to.have.lengthOf(0)
|
expect(overview.channels).to.have.lengthOf(0)
|
||||||
|
@ -90,20 +87,10 @@ describe('Test a videos overview', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have the correct overview', async function () {
|
it('Should have the correct overview', async function () {
|
||||||
const res1 = await getVideosOverview(server.url, 1)
|
const overview1 = await server.overviewsCommand.getVideos({ page: 1 })
|
||||||
const res2 = await getVideosOverview(server.url, 2)
|
const overview2 = await server.overviewsCommand.getVideos({ page: 2 })
|
||||||
|
|
||||||
const overview1: VideosOverview = res1.body
|
for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
|
||||||
const overview2: VideosOverview = res2.body
|
|
||||||
|
|
||||||
const tmp = [
|
|
||||||
overview1.tags,
|
|
||||||
overview1.categories,
|
|
||||||
overview1.channels,
|
|
||||||
overview2.tags
|
|
||||||
]
|
|
||||||
|
|
||||||
for (const arr of tmp) {
|
|
||||||
expect(arr).to.have.lengthOf(1)
|
expect(arr).to.have.lengthOf(1)
|
||||||
|
|
||||||
const obj = arr[0]
|
const obj = arr[0]
|
||||||
|
@ -132,15 +119,15 @@ describe('Test a videos overview', function () {
|
||||||
await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host)
|
await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host)
|
||||||
|
|
||||||
{
|
{
|
||||||
const res = await getVideosOverview(server.url, 1)
|
const body = await server.overviewsCommand.getVideos({ page: 1 })
|
||||||
|
|
||||||
testOverviewCount(res, 1)
|
testOverviewCount(body, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const res = await getVideosOverviewWithToken(server.url, 1, token)
|
const body = await server.overviewsCommand.getVideos({ page: 1, token })
|
||||||
|
|
||||||
testOverviewCount(res, 0)
|
testOverviewCount(body, 0)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ export * from './logs'
|
||||||
export * from './miscs'
|
export * from './miscs'
|
||||||
export * from './mock-servers'
|
export * from './mock-servers'
|
||||||
export * from './moderation'
|
export * from './moderation'
|
||||||
|
export * from './overviews'
|
||||||
|
|
||||||
export * from './requests/check-api-params'
|
export * from './requests/check-api-params'
|
||||||
export * from './requests/requests'
|
export * from './requests/requests'
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './overviews-command'
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { HttpStatusCode } from '@shared/core-utils'
|
||||||
|
import { VideosOverview } from '@shared/models'
|
||||||
|
import { AbstractCommand, OverrideCommandOptions } from '../shared'
|
||||||
|
|
||||||
|
export class OverviewsCommand extends AbstractCommand {
|
||||||
|
|
||||||
|
getVideos (options: OverrideCommandOptions & {
|
||||||
|
page: number
|
||||||
|
token?: string
|
||||||
|
}) {
|
||||||
|
const { token, page } = options
|
||||||
|
const path = '/api/v1/overviews/videos'
|
||||||
|
|
||||||
|
const query = { page }
|
||||||
|
|
||||||
|
return this.getRequestBody<VideosOverview>({
|
||||||
|
...options,
|
||||||
|
|
||||||
|
token: token || null,
|
||||||
|
path,
|
||||||
|
query,
|
||||||
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,34 +0,0 @@
|
||||||
import { makeGetRequest } from '../requests/requests'
|
|
||||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
|
||||||
|
|
||||||
function getVideosOverview (url: string, page: number, statusCodeExpected = HttpStatusCode.OK_200) {
|
|
||||||
const path = '/api/v1/overviews/videos'
|
|
||||||
|
|
||||||
const query = { page }
|
|
||||||
|
|
||||||
return makeGetRequest({
|
|
||||||
url,
|
|
||||||
path,
|
|
||||||
query,
|
|
||||||
statusCodeExpected
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function getVideosOverviewWithToken (url: string, page: number, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
|
|
||||||
const path = '/api/v1/overviews/videos'
|
|
||||||
|
|
||||||
const query = { page }
|
|
||||||
|
|
||||||
return makeGetRequest({
|
|
||||||
url,
|
|
||||||
path,
|
|
||||||
query,
|
|
||||||
token,
|
|
||||||
statusCodeExpected
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
getVideosOverview,
|
|
||||||
getVideosOverviewWithToken
|
|
||||||
}
|
|
|
@ -13,6 +13,7 @@ import { FeedCommand } from '../feeds'
|
||||||
import { LogsCommand } from '../logs'
|
import { LogsCommand } from '../logs'
|
||||||
import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs'
|
import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs'
|
||||||
import { AbusesCommand } from '../moderation'
|
import { AbusesCommand } from '../moderation'
|
||||||
|
import { OverviewsCommand } from '../overviews'
|
||||||
import { makeGetRequest } from '../requests/requests'
|
import { makeGetRequest } from '../requests/requests'
|
||||||
|
|
||||||
interface ServerInfo {
|
interface ServerInfo {
|
||||||
|
@ -73,6 +74,7 @@ interface ServerInfo {
|
||||||
feedCommand?: FeedCommand
|
feedCommand?: FeedCommand
|
||||||
logsCommand?: LogsCommand
|
logsCommand?: LogsCommand
|
||||||
abusesCommand?: AbusesCommand
|
abusesCommand?: AbusesCommand
|
||||||
|
overviewsCommand?: OverviewsCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
function parallelTests () {
|
function parallelTests () {
|
||||||
|
@ -284,6 +286,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
|
||||||
server.feedCommand = new FeedCommand(server)
|
server.feedCommand = new FeedCommand(server)
|
||||||
server.logsCommand = new LogsCommand(server)
|
server.logsCommand = new LogsCommand(server)
|
||||||
server.abusesCommand = new AbusesCommand(server)
|
server.abusesCommand = new AbusesCommand(server)
|
||||||
|
server.overviewsCommand = new OverviewsCommand(server)
|
||||||
|
|
||||||
res(server)
|
res(server)
|
||||||
})
|
})
|
||||||
|
|
|
@ -78,7 +78,10 @@ abstract class AbstractCommand {
|
||||||
return {
|
return {
|
||||||
url: this.server.url,
|
url: this.server.url,
|
||||||
path,
|
path,
|
||||||
token: token ?? this.server.accessToken,
|
|
||||||
|
// Token can be null if we don't want to add it
|
||||||
|
token: token !== undefined ? token : this.server.accessToken,
|
||||||
|
|
||||||
statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus
|
statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue