Introduce services command

pull/4271/head
Chocobozzz 2021-07-08 10:23:21 +02:00
parent 4f2199144e
commit d897210c2d
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 35 additions and 30 deletions

View File

@ -6,7 +6,6 @@ import { Video, VideoPlaylistPrivacy } from '@shared/models'
import {
addVideoInPlaylist,
createVideoPlaylist,
getOEmbed,
getVideosList,
ServerInfo,
setAccessTokensToServers,
@ -70,7 +69,7 @@ describe('Test services', function () {
for (const basePath of [ '/videos/watch/', '/w/' ]) {
const oembedUrl = 'http://localhost:' + server.port + basePath + video.uuid
const res = await getOEmbed(server.url, oembedUrl)
const res = await server.servicesCommand.getOEmbed({ oembedUrl })
const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
`title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
'frameborder="0" allowfullscreen></iframe>'
@ -91,7 +90,7 @@ describe('Test services', function () {
for (const basePath of [ '/videos/watch/playlist/', '/w/p/' ]) {
const oembedUrl = 'http://localhost:' + server.port + basePath + playlistUUID
const res = await getOEmbed(server.url, oembedUrl)
const res = await server.servicesCommand.getOEmbed({ oembedUrl })
const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
`title="${playlistDisplayName}" src="http://localhost:${server.port}/video-playlists/embed/${playlistUUID}" ` +
'frameborder="0" allowfullscreen></iframe>'
@ -114,7 +113,7 @@ describe('Test services', function () {
const maxHeight = 50
const maxWidth = 50
const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
const res = await server.servicesCommand.getOEmbed({ oembedUrl, format, maxHeight, maxWidth })
const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' +
`title="${video.name}" src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
'frameborder="0" allowfullscreen></iframe>'

View File

@ -18,7 +18,7 @@ import { makeGetRequest } from '../requests/requests'
import { SearchCommand } from '../search'
import { SocketIOCommand } from '../socket'
import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users'
import { LiveCommand } from '../videos'
import { LiveCommand, ServicesCommand } from '../videos'
import { ConfigCommand } from './config-command'
import { ContactFormCommand } from './contact-form-command'
import { DebugCommand } from './debug-command'
@ -101,6 +101,7 @@ interface ServerInfo {
blocklistCommand?: BlocklistCommand
subscriptionsCommand?: SubscriptionsCommand
liveCommand?: LiveCommand
servicesCommand?: ServicesCommand
}
function parallelTests () {
@ -327,6 +328,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
server.blocklistCommand = new BlocklistCommand(server)
server.subscriptionsCommand = new SubscriptionsCommand(server)
server.liveCommand = new LiveCommand(server)
server.servicesCommand = new ServicesCommand(server)
res(server)
})

View File

@ -1,6 +1,6 @@
export * from './live-command'
export * from './live'
export * from './services'
export * from './services-command'
export * from './video-blacklist'
export * from './video-captions'
export * from './video-change-ownership'

View File

@ -0,0 +1,28 @@
import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
import { AbstractCommand, OverrideCommandOptions } from '../shared'
export class ServicesCommand extends AbstractCommand {
getOEmbed (options: OverrideCommandOptions & {
oembedUrl: string
format?: string
maxHeight?: number
maxWidth?: number
}) {
const path = '/services/oembed'
const query = {
url: options.oembedUrl,
format: options.format,
maxheight: options.maxHeight,
maxwidth: options.maxWidth
}
return this.getRequest({
...options,
path,
query,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
}

View File

@ -1,24 +0,0 @@
import * as request from 'supertest'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
function getOEmbed (url: string, oembedUrl: string, format?: string, maxHeight?: number, maxWidth?: number) {
const path = '/services/oembed'
const query = {
url: oembedUrl,
format,
maxheight: maxHeight,
maxwidth: maxWidth
}
return request(url)
.get(path)
.query(query)
.set('Accept', 'application/json')
.expect(HttpStatusCode.OK_200)
}
// ---------------------------------------------------------------------------
export {
getOEmbed
}