mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14:03 +03:00
7433378e6a
refs: https://github.com/TryGhost/Toolbox/issues/245 - There was only a serializer in place for redirects.download. - Upload was falling through, which means nothing happens by default atm - We want to change this default, so I'm making sure all our routes have serializers declared and tests - Updated the tests and checked the behaviour was the same before and after: - We can't use our new framework here yet because it doesn't support uploads or downloads - Instead, just add simple matching for the body of the responses
66 lines
2.8 KiB
JavaScript
66 lines
2.8 KiB
JavaScript
const should = require('should');
|
|
const supertest = require('supertest');
|
|
const fs = require('fs-extra');
|
|
const path = require('path');
|
|
const localUtils = require('./utils');
|
|
const config = require('../../../core/shared/config');
|
|
|
|
describe('Redirects API', function () {
|
|
let request;
|
|
|
|
before(async function () {
|
|
await localUtils.startGhost();
|
|
request = supertest.agent(config.get('url'));
|
|
await localUtils.doAuth(request);
|
|
});
|
|
|
|
it('download', function () {
|
|
return request
|
|
.get(localUtils.API.getApiQuery('redirects/download/'))
|
|
.set('Origin', config.get('url'))
|
|
.expect('Content-Type', /application\/json/)
|
|
.expect('Content-Disposition', 'Attachment; filename="redirects.json"')
|
|
.expect(200)
|
|
.expect((res) => {
|
|
res.body.should.eql([
|
|
{from: '^/post/[0-9]+/([a-z0-9\\-]+)', to: '/$1'},
|
|
{permanent: true, from: '/my-old-blog-post/', to: '/revamped-url/'},
|
|
{permanent: true, from: '/test-params', to: '/result?q=abc'},
|
|
{from: '^\\/what(\\/?)$', to: '/what-does-god-say'},
|
|
{from: '^\\/search\\/label\\/([^\\%20]+)$', to: '/tag/$1'},
|
|
{from: '^\\/topic\\/', to: '/'},
|
|
{from: '^/resources\\/download(\\/?)$', to: '/shubal-stearns'},
|
|
{from: '^/(?:capture1|capture2)/([A-Za-z0-9\\-]+)', to: '/$1'},
|
|
{
|
|
from: '^\\/[0-9]{4}\\/[0-9]{2}\\/([a-z0-9\\-]+)(\\.html)?(\\/)?$',
|
|
to: '/$1'
|
|
},
|
|
{from: '^/prefix/([a-z0-9\\-]+)?', to: '/blog/$1'},
|
|
{from: '/^\\/case-insensitive/i', to: '/redirected-insensitive'},
|
|
{from: '^\\/Case-Sensitive', to: '/redirected-sensitive'},
|
|
{from: '^\\/Default-Sensitive', to: '/redirected-default'},
|
|
{from: '/external-url', to: 'https://ghost.org'},
|
|
{from: '/external-url/(.*)', to: 'https://ghost.org/$1'}
|
|
]);
|
|
});
|
|
});
|
|
|
|
it('upload', function () {
|
|
// Provide a redirects file in the root directory of the content test folder
|
|
fs.writeFileSync(path.join(config.get('paths:contentPath'), 'redirects-init.json'), JSON.stringify([{
|
|
from: 'k',
|
|
to: 'l'
|
|
}]));
|
|
|
|
return request
|
|
.post(localUtils.API.getApiQuery('redirects/upload/'))
|
|
.set('Origin', config.get('url'))
|
|
.attach('redirects', path.join(config.get('paths:contentPath'), 'redirects-init.json'))
|
|
.expect('Content-Type', /application\/json/)
|
|
.expect(200)
|
|
.expect((res) => {
|
|
res.body.should.be.empty();
|
|
});
|
|
});
|
|
});
|