2018-11-02 11:32:26 +03:00
|
|
|
const nock = require('nock');
|
|
|
|
const should = require('should');
|
|
|
|
const supertest = require('supertest');
|
2019-09-20 18:02:45 +03:00
|
|
|
const testUtils = require('../../utils/index');
|
|
|
|
const config = require('../../../server/config/index');
|
2018-11-02 11:32:26 +03:00
|
|
|
const localUtils = require('./utils');
|
|
|
|
|
|
|
|
const ghost = testUtils.startGhost;
|
|
|
|
|
|
|
|
describe('Oembed API', function () {
|
|
|
|
let ghostServer, request;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
return ghost()
|
|
|
|
.then((_ghostServer) => {
|
|
|
|
ghostServer = _ghostServer;
|
|
|
|
request = supertest.agent(config.get('url'));
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
return localUtils.doAuth(request);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
it('can fetch an embed', function (done) {
|
|
|
|
let requestMock = nock('https://www.youtube.com')
|
|
|
|
.get('/oembed')
|
|
|
|
.query(true)
|
|
|
|
.reply(200, {
|
|
|
|
html: '<iframe width="480" height="270" src="https://www.youtube.com/embed/E5yFcdPAGv0?feature=oembed" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>',
|
|
|
|
thumbnail_width: 480,
|
|
|
|
width: 480,
|
|
|
|
author_url: 'https://www.youtube.com/user/gorillaz',
|
|
|
|
height: 270,
|
|
|
|
thumbnail_height: 360,
|
|
|
|
provider_name: 'YouTube',
|
|
|
|
title: 'Gorillaz - Humility (Official Video)',
|
|
|
|
provider_url: 'https://www.youtube.com/',
|
|
|
|
author_name: 'Gorillaz',
|
|
|
|
version: '1.0',
|
|
|
|
thumbnail_url: 'https://i.ytimg.com/vi/E5yFcdPAGv0/hqdefault.jpg',
|
|
|
|
type: 'video'
|
|
|
|
});
|
2018-11-02 11:32:26 +03:00
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
request.get(localUtils.API.getApiQuery('oembed/?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DE5yFcdPAGv0'))
|
|
|
|
.set('Origin', config.get('url'))
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2018-11-02 11:32:26 +03:00
|
|
|
|
2019-02-04 17:16:24 +03:00
|
|
|
requestMock.isDone().should.be.true();
|
|
|
|
should.exist(res.body.html);
|
|
|
|
done();
|
|
|
|
});
|
2018-11-02 11:32:26 +03:00
|
|
|
});
|
|
|
|
});
|