mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Removed redirects regression tests in favor of unit test
refs https://linear.app/tryghost/issue/CORE-84/have-a-look-at-the-eggs-redirects-refactor-branch - The regression test should not be testing edge cases like this and it's far more flexible and performant to test the service on the unit test level
This commit is contained in:
parent
c3edd4b3d4
commit
1c4dea00b9
4 changed files with 29 additions and 57 deletions
|
@ -42,29 +42,6 @@ describe('Redirects API', function () {
|
|||
configUtils.config.set('paths:contentPath', originalContentPath);
|
||||
});
|
||||
|
||||
it('file does not exist', async function () {
|
||||
// Just set any content folder, which does not contain a redirects file.
|
||||
// configUtils.set('paths:contentPath', path.join(__dirname, '../../../utils/fixtures/data'));
|
||||
|
||||
await startGhost({
|
||||
redirectsFile: true,
|
||||
redirectsFileExt: null,
|
||||
forceStart: true
|
||||
});
|
||||
|
||||
await request
|
||||
.get(localUtils.API.getApiQuery('redirects/download/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.expect(200)
|
||||
.then((res) => {
|
||||
res.headers['content-disposition'].should.eql('Attachment; filename="redirects.json"');
|
||||
res.headers['content-type'].should.eql('application/json; charset=utf-8');
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
|
||||
should.deepEqual(res.body, []);
|
||||
});
|
||||
});
|
||||
|
||||
it('file exists', async function () {
|
||||
await startGhost({
|
||||
redirectsFile: true,
|
||||
|
|
|
@ -32,23 +32,6 @@ describe('Redirects API', function () {
|
|||
configUtils.config.set('paths:contentPath', originalContentPath);
|
||||
});
|
||||
|
||||
it('file does not exist', function () {
|
||||
// Just set any content folder, which does not contain a redirects file.
|
||||
configUtils.set('paths:contentPath', path.join(__dirname, '../../../utils/fixtures/data'));
|
||||
|
||||
return request
|
||||
.get(localUtils.API.getApiQuery('redirects/json/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.expect(200)
|
||||
.then((res) => {
|
||||
res.headers['content-disposition'].should.eql('Attachment; filename="redirects.json"');
|
||||
res.headers['content-type'].should.eql('application/json; charset=utf-8');
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
|
||||
should.deepEqual(res.body, []);
|
||||
});
|
||||
});
|
||||
|
||||
it('file exists', function () {
|
||||
return request
|
||||
.get(localUtils.API.getApiQuery('redirects/json/'))
|
||||
|
|
|
@ -42,23 +42,6 @@ describe('Redirects API', function () {
|
|||
configUtils.config.set('paths:contentPath', originalContentPath);
|
||||
});
|
||||
|
||||
it('file does not exist', function () {
|
||||
// Just set any content folder, which does not contain a redirects file.
|
||||
configUtils.set('paths:contentPath', path.join(__dirname, '../../../utils/fixtures/data'));
|
||||
|
||||
return request
|
||||
.get(localUtils.API.getApiQuery('redirects/json/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.expect(200)
|
||||
.then((res) => {
|
||||
res.headers['content-disposition'].should.eql('Attachment; filename="redirects.json"');
|
||||
res.headers['content-type'].should.eql('application/json; charset=utf-8');
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
|
||||
should.deepEqual(res.body, []);
|
||||
});
|
||||
});
|
||||
|
||||
it('file exists', function () {
|
||||
return request
|
||||
.get(localUtils.API.getApiQuery('redirects/json/'))
|
||||
|
|
29
test/unit/server/services/redirects/api.test.js
Normal file
29
test/unit/server/services/redirects/api.test.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
const should = require('should');
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
|
||||
const DynamicRedirectManager = require('@tryghost/express-dynamic-redirects');
|
||||
const CustomRedirectsAPI = require('../../../../../core/server/services/redirects/api');
|
||||
|
||||
describe('UNIT: redirects CustomRedirectsAPI class', function () {
|
||||
describe('get', function () {
|
||||
it('returns nothing if file does not exist', async function () {
|
||||
// Just set any content folder, which does not contain a redirects file.
|
||||
const basePath = path.join(__dirname, '../../../utils/fixtures/does-not-exist/');
|
||||
const redirectManager = new DynamicRedirectManager({
|
||||
permanentMaxAge: 100,
|
||||
getSubdirectoryURL: (pathname) => {
|
||||
return `/ghost/${pathname}`;
|
||||
}
|
||||
});
|
||||
|
||||
const customRedirectsAPI = new CustomRedirectsAPI({
|
||||
basePath
|
||||
}, redirectManager);
|
||||
|
||||
const file = await customRedirectsAPI.get();
|
||||
|
||||
should.deepEqual(file, []);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue