diff --git a/tests/models/setting.js b/tests/models/setting.js new file mode 100644 index 000000000..e2600fb0f --- /dev/null +++ b/tests/models/setting.js @@ -0,0 +1,32 @@ +/* eslint-env node, mocha */ + +require('../utils/mongoose'); + +const Setting = require('../../models/setting'); +const expect = require('chai').expect; + +describe('Setting: model', () => { + + beforeEach(() => { + const defaults = {id: 1, moderation: 'pre'}; + return Setting.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true}); + }); + + describe('#getSettings()', () => { + it('should have a moderation field defined', () => { + return Setting.getSettings().then(settings => { + expect(settings).to.have.property('moderation').and.to.equal('pre'); + }); + }); + }); + + describe('#updateSettings()', () => { + it('should update the settings with a passed object', () => { + const mockSettings = {moderation: 'post'}; + return Setting.updateSettings(mockSettings).then(updatedSettings => { + expect(updatedSettings).to.have.property('moderation').and.to.equal('post'); + }); + }); + }); + +}); diff --git a/tests/routes/api/settings/index.js b/tests/routes/api/settings/index.js new file mode 100644 index 000000000..8c2cd221e --- /dev/null +++ b/tests/routes/api/settings/index.js @@ -0,0 +1,62 @@ +process.env.NODE_ENV = 'test'; + +require('../../../utils/mongoose'); + +const app = require('../../../../app'); +const chai = require('chai'); +const chaiHttp = require('chai-http'); +chai.use(chaiHttp); +const expect = chai.expect; + +const Setting = require('../../../../models/setting'); +const defaults = {id: '1', moderation: 'pre'}; + +describe('GET /settings', () => { + + beforeEach(() => { + return Setting.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true}); + }); + + it('should return a settings object', done => { + chai.request(app) + .get('/api/v1/settings') + .end((err, res) => { + expect(err).to.be.null; + expect(res).to.have.status(200); + expect(res).to.be.json; + expect(res.body).to.have.property('moderation'); + expect(res.body.moderation).to.equal('pre'); + done(err); + }); + }); +}); + +// update the settings. +describe('update settings', () => { + + before(() => { + return Setting.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true}); + }); + + it('should respond to a PUT with new settings', () => { + chai.request(app) + .put('/api/v1/settings') + .send({moderation: 'post'}, (err, res) => { + expect(err).to.be.null; + expect(res).to.have.status(204); + done(err); + }); + }); + + it('should have updates settings', () => { + chai.request(app) + .get('/api/v1/settings') + .end((err, res) => { + expect(err).to.be.null; + expect(res).to.have.status(200); + expect(res).to.be.json; + expect(res.body).to.have.property('moderation'); + expect(res.body.moderation).to.equal('post'); + }); + }); +});