mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
refs https://github.com/TryGhost/Toolbox/issues/138 - Having the "ghost" alias only added cognitive load when reading through the test code and didn't provide any additional value. Removed the pattern to keep things simpler and more explicit
68 lines
2.4 KiB
JavaScript
68 lines
2.4 KiB
JavaScript
const path = require('path');
|
|
const should = require('should');
|
|
const supertest = require('supertest');
|
|
const sinon = require('sinon');
|
|
const testUtils = require('../../../../utils');
|
|
const localUtils = require('./utils');
|
|
const config = require('../../../../../core/shared/config');
|
|
|
|
let request;
|
|
|
|
describe('Labels API', function () {
|
|
after(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
before(function () {
|
|
return testUtils.startGhost()
|
|
.then(function () {
|
|
request = supertest.agent(config.get('url'));
|
|
})
|
|
.then(function () {
|
|
return localUtils.doAuth(request);
|
|
});
|
|
});
|
|
|
|
it('Errors when adding label with the same name', function () {
|
|
const label = {
|
|
name: 'test'
|
|
};
|
|
|
|
return request
|
|
.post(localUtils.API.getApiQuery(`labels/`))
|
|
.send({labels: [label]})
|
|
.set('Origin', config.get('url'))
|
|
.expect('Content-Type', /json/)
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
.expect(201)
|
|
.then((res) => {
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
const jsonResponse = res.body;
|
|
should.exist(jsonResponse);
|
|
should.exist(jsonResponse.labels);
|
|
jsonResponse.labels.should.have.length(1);
|
|
|
|
jsonResponse.labels[0].name.should.equal(label.name);
|
|
jsonResponse.labels[0].slug.should.equal(label.name);
|
|
})
|
|
.then(() => {
|
|
return request
|
|
.post(localUtils.API.getApiQuery(`labels/`))
|
|
.send({labels: [label]})
|
|
.set('Origin', config.get('url'))
|
|
.expect('Content-Type', /json/)
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
.expect(422);
|
|
})
|
|
.then((res) => {
|
|
should.not.exist(res.headers['x-cache-invalidate']);
|
|
const jsonResponse = res.body;
|
|
should.exist(jsonResponse);
|
|
should.exist(jsonResponse.errors);
|
|
jsonResponse.errors.should.have.length(1);
|
|
|
|
jsonResponse.errors[0].type.should.equal('ValidationError');
|
|
jsonResponse.errors[0].context.should.equal('Label already exists');
|
|
});
|
|
});
|
|
});
|