]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Introduce services command
authorChocobozzz <me@florianbigard.com>
Thu, 8 Jul 2021 08:23:21 +0000 (10:23 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 20 Jul 2021 13:27:17 +0000 (15:27 +0200)
server/tests/api/server/services.ts
shared/extra-utils/server/servers.ts
shared/extra-utils/videos/index.ts
shared/extra-utils/videos/services-command.ts [new file with mode: 0644]
shared/extra-utils/videos/services.ts [deleted file]

index ea64e4040b79693b6c36319e3344e05b217d5e77..0adf6b6671d25e711e90f02176541b466085f29e 100644 (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>'
index eca0689aa0966622a318ecaa36396aa4aadde821..cb2a8814b777a57bb18f410758292bedef9f3654 100644 (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)
     })
index c9c8842852a706d908023f6276edc7339925d099..fe5dc6655e1ffdef8ff93c6c6843146953ccf730 100644 (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'
diff --git a/shared/extra-utils/videos/services-command.ts b/shared/extra-utils/videos/services-command.ts
new file mode 100644 (file)
index 0000000..3b618ef
--- /dev/null
@@ -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
+    })
+  }
+}
diff --git a/shared/extra-utils/videos/services.ts b/shared/extra-utils/videos/services.ts
deleted file mode 100644 (file)
index e13a788..0000000
+++ /dev/null
@@ -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
-}