From d8755eed1e452d2efbfc983af0e9d228d152bf6b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 16 Oct 2017 10:05:49 +0200 Subject: Add oembed endpoint --- server/tests/api/check-params/index.ts | 1 + server/tests/api/check-params/services.ts | 159 ++++++++++++++++++++++++++++++ server/tests/api/index.ts | 1 + server/tests/api/services.ts | 85 ++++++++++++++++ server/tests/client.ts | 17 +++- server/tests/utils/index.ts | 1 + server/tests/utils/servers.ts | 2 + server/tests/utils/services.ts | 23 +++++ 8 files changed, 287 insertions(+), 2 deletions(-) create mode 100644 server/tests/api/check-params/services.ts create mode 100644 server/tests/api/services.ts create mode 100644 server/tests/utils/services.ts (limited to 'server/tests') diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index 399a05bc3..954b206e9 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts @@ -3,6 +3,7 @@ import './pods' import './remotes' import './users' import './request-schedulers' +import './services' import './videos' import './video-abuses' import './video-blacklist' diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts new file mode 100644 index 000000000..780254df5 --- /dev/null +++ b/server/tests/api/check-params/services.ts @@ -0,0 +1,159 @@ +/* tslint:disable:no-unused-expression */ + +import * as request from 'supertest' +import 'mocha' + +import { + flushTests, + runServer, + setAccessTokensToServers, + killallServers +} from '../../utils' +import { getVideosList, uploadVideo } from '../../utils/videos' + +describe('Test services API validators', function () { + let server + + // --------------------------------------------------------------- + + before(async function () { + this.timeout(60000) + + await flushTests() + + server = await runServer(1) + await setAccessTokensToServers([ server ]) + + const videoAttributes = { + name: 'my super name' + } + await uploadVideo(server.url, server.accessToken, videoAttributes) + + const res = await getVideosList(server.url) + server.video = res.body.data[0] + }) + + describe('Test oEmbed API validators', function () { + const path = '/services/oembed' + + it('Should fail with an invalid url', async function () { + const embedUrl = 'hello.com' + + await request(server.url) + .get(path) + .query({ url: embedUrl }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400) + }) + + it('Should fail with an invalid host', async function () { + const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid + + await request(server.url) + .get(path) + .query({ url: embedUrl }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400) + }) + + it('Should fail with an invalid video id', async function () { + const embedUrl = 'http://localhost:9001/videos/watch/blabla' + + await request(server.url) + .get(path) + .query({ url: embedUrl }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400) + }) + + it('Should fail with an unknown video', async function () { + const embedUrl = 'http://localhost:9001/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c' + + await request(server.url) + .get(path) + .query({ url: embedUrl }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(404) + }) + + it('Should fail with an invalid path', async function () { + const embedUrl = 'http://localhost:9001/videos/watchs/' + server.video.uuid + + await request(server.url) + .get(path) + .query({ url: embedUrl }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400) + }) + + it('Should fail with an invalid max height', async function () { + const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid + + await request(server.url) + .get(path) + .query({ + url: embedUrl, + maxheight: 'hello' + }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400) + }) + + it('Should fail with an invalid max width', async function () { + const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid + + await request(server.url) + .get(path) + .query({ + url: embedUrl, + maxwidth: 'hello' + }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400) + }) + + it('Should fail with an invalid format', async function () { + const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid + + await request(server.url) + .get(path) + .query({ + url: embedUrl, + format: 'blabla' + }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(400) + }) + + it('Should fail with a non supported format', async function () { + const embedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid + + await request(server.url) + .get(path) + .query({ + url: embedUrl, + format: 'xml' + }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + server.accessToken) + .expect(501) + }) + }) + + after(async function () { + killallServers([ server ]) + + // Keep the logs if the test failed + if (this['ok']) { + await flushTests() + } + }) +}) diff --git a/server/tests/api/index.ts b/server/tests/api/index.ts index 03711e68a..e50e65049 100644 --- a/server/tests/api/index.ts +++ b/server/tests/api/index.ts @@ -8,6 +8,7 @@ import './video-abuse' import './video-blacklist' import './video-blacklist-management' import './multiple-pods' +import './services' import './request-schedulers' import './friends-advanced' import './video-transcoder' diff --git a/server/tests/api/services.ts b/server/tests/api/services.ts new file mode 100644 index 000000000..b396ea582 --- /dev/null +++ b/server/tests/api/services.ts @@ -0,0 +1,85 @@ +/* tslint:disable:no-unused-expression */ + +import 'mocha' +import * as chai from 'chai' +const expect = chai.expect + +import { + ServerInfo, + flushTests, + uploadVideo, + getVideosList, + setAccessTokensToServers, + killallServers, + getOEmbed +} from '../utils' +import { runServer } from '../utils/servers' + +describe('Test services', function () { + let server: ServerInfo = null + + before(async function () { + this.timeout(120000) + + await flushTests() + + server = await runServer(1) + + await setAccessTokensToServers([ server ]) + + const videoAttributes = { + name: 'my super name' + } + await uploadVideo(server.url, server.accessToken, videoAttributes) + + const res = await getVideosList(server.url) + server.video = res.body.data[0] + }) + + it('Should have a valid oEmbed response', async function () { + const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid + + const res = await getOEmbed(server.url, oembedUrl) + const expectedHtml = `' + const expectedThumbnailUrl = 'http://localhost:9001/static/thumbnails/' + server.video.uuid + '.jpg' + + expect(res.body.html).to.equal(expectedHtml) + expect(res.body.title).to.equal(server.video.name) + expect(res.body.author_name).to.equal(server.video.author) + expect(res.body.height).to.equal(315) + expect(res.body.width).to.equal(560) + expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl) + expect(res.body.thumbnail_width).to.equal(200) + expect(res.body.thumbnail_height).to.equal(110) + }) + + it('Should have a valid oEmbed response with small max height query', async function () { + const oembedUrl = 'http://localhost:9001/videos/watch/' + server.video.uuid + const format = 'json' + const maxHeight = 50 + const maxWidth = 50 + + const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth) + const expectedHtml = `' + + expect(res.body.html).to.equal(expectedHtml) + expect(res.body.title).to.equal(server.video.name) + expect(res.body.author_name).to.equal(server.video.author) + expect(res.body.height).to.equal(50) + expect(res.body.width).to.equal(50) + expect(res.body).to.not.have.property('thumbnail_url') + expect(res.body).to.not.have.property('thumbnail_width') + expect(res.body).to.not.have.property('thumbnail_height') + }) + + after(async function () { + killallServers([ server ]) + + // Keep the logs if the test failed + if (this['ok']) { + await flushTests() + } + }) +}) diff --git a/server/tests/client.ts b/server/tests/client.ts index 5e5abba5a..5f947ed2b 100644 --- a/server/tests/client.ts +++ b/server/tests/client.ts @@ -39,7 +39,7 @@ describe('Test a client controllers', function () { server.video = videos[0] }) - it('It should have valid Open Graph tags on the watch page with video id', async function () { + it('Should have valid Open Graph tags on the watch page with video id', async function () { const res = await request(server.url) .get('/videos/watch/' + server.video.id) .expect(200) @@ -48,7 +48,7 @@ describe('Test a client controllers', function () { expect(res.text).to.contain('') }) - it('It should have valid Open Graph tags on the watch page with video uuid', async function () { + it('Should have valid Open Graph tags on the watch page with video uuid', async function () { const res = await request(server.url) .get('/videos/watch/' + server.video.uuid) .expect(200) @@ -57,6 +57,19 @@ describe('Test a client controllers', function () { expect(res.text).to.contain('') }) + it('Should have valid oEmbed discovery tags', async function () { + const path = '/videos/watch/' + server.video.uuid + const res = await request(server.url) + .get(path) + .expect(200) + + const expectedLink = '` + + expect(res.text).to.contain(expectedLink) + }) + after(async function () { process.kill(-server.app.pid) diff --git a/server/tests/utils/index.ts b/server/tests/utils/index.ts index 99c445887..90ee2d515 100644 --- a/server/tests/utils/index.ts +++ b/server/tests/utils/index.ts @@ -7,6 +7,7 @@ export * from './pods' export * from './request-schedulers' export * from './requests' export * from './servers' +export * from './services' export * from './users' export * from './video-abuses' export * from './video-blacklist' diff --git a/server/tests/utils/servers.ts b/server/tests/utils/servers.ts index 88027f74e..3526ffa51 100644 --- a/server/tests/utils/servers.ts +++ b/server/tests/utils/servers.ts @@ -23,6 +23,8 @@ interface ServerInfo { video?: { id: number uuid: string + name: string + author: string } remoteVideo?: { diff --git a/server/tests/utils/services.ts b/server/tests/utils/services.ts new file mode 100644 index 000000000..1a53dd4cf --- /dev/null +++ b/server/tests/utils/services.ts @@ -0,0 +1,23 @@ +import * as request from 'supertest' + +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(200) +} + +// --------------------------------------------------------------------------- + +export { + getOEmbed +} -- cgit v1.2.3