0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-15 03:01:37 -05:00

Rewrote validation regression tests to be unit tests

refs refs https://linear.app/tryghost/issue/CORE-84/have-a-look-at-the-eggs-redirects-refactor-branch

- These regression tests are slow and should have been unit tests to start with
This commit is contained in:
Naz 2021-11-02 17:54:38 +04:00 committed by naz
parent e1d16a55e1
commit d101ef5293
4 changed files with 14 additions and 42 deletions

View file

@ -50,20 +50,6 @@ describe('Redirects API', function () {
.expect(400);
});
it('wrong format: no array', function () {
fs.writeFileSync(path.join(config.get('paths:contentPath'), 'redirects.json'), JSON.stringify({
from: 'c',
to: 'd'
}));
return request
.post(localUtils.API.getApiQuery('redirects/upload/'))
.set('Origin', config.get('url'))
.attach('redirects', path.join(config.get('paths:contentPath'), 'redirects.json'))
.expect('Content-Type', /application\/json/)
.expect(422);
});
it('wrong format: no from/to', function () {
fs.writeFileSync(path.join(config.get('paths:contentPath'), 'redirects.json'), JSON.stringify([{to: 'd'}]));

View file

@ -40,20 +40,6 @@ describe('Redirects API', function () {
.expect(400);
});
it('wrong format: no array', function () {
fs.writeFileSync(path.join(config.get('paths:contentPath'), 'redirects.json'), JSON.stringify({
from: 'c',
to: 'd'
}));
return request
.post(localUtils.API.getApiQuery('redirects/json/'))
.set('Origin', config.get('url'))
.attach('redirects', path.join(config.get('paths:contentPath'), 'redirects.json'))
.expect('Content-Type', /application\/json/)
.expect(422);
});
it('wrong format: no from/to', function () {
fs.writeFileSync(path.join(config.get('paths:contentPath'), 'redirects.json'), JSON.stringify([{to: 'd'}]));

View file

@ -50,20 +50,6 @@ describe('Redirects API', function () {
.expect(400);
});
it('wrong format: no array', function () {
fs.writeFileSync(path.join(config.get('paths:contentPath'), 'redirects.json'), JSON.stringify({
from: 'c',
to: 'd'
}));
return request
.post(localUtils.API.getApiQuery('redirects/json/'))
.set('Origin', config.get('url'))
.attach('redirects', path.join(config.get('paths:contentPath'), 'redirects.json'))
.expect('Content-Type', /application\/json/)
.expect(422);
});
it('wrong format: no from/to', function () {
fs.writeFileSync(path.join(config.get('paths:contentPath'), 'redirects.json'), JSON.stringify([{to: 'd'}]));

View file

@ -41,4 +41,18 @@ describe('UNIT: custom redirects validation', function () {
err.message.should.equal('Incorrect RegEx in redirects file.');
}
});
it('throws when setting a file with wrong format: no array', function () {
const config = {
from: 'c',
to: 'd'
};
try {
validate(config);
should.fail('should have thrown');
} catch (err) {
err.message.should.equal('Incorrect redirects file format.');
}
});
});