Added asset settings + improved tests for routes

This commit is contained in:
Wyatt Johnson
2016-11-29 10:01:52 -07:00
parent 735f2d09ad
commit ac17fc2cc6
13 changed files with 401 additions and 407 deletions
+32 -39
View File
@@ -10,49 +10,42 @@ chai.use(require('chai-http'));
const Setting = require('../../../../models/setting');
const defaults = {id: '1', moderation: 'pre'};
describe('GET /settings', () => {
describe('/api/v1/settings', () => {
beforeEach(() => {
return Setting.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true});
beforeEach(() => Setting.create(defaults));
describe('#get', () => {
it('should return a settings object', () => {
return chai.request(app)
.get('/api/v1/settings')
.set(passport.inject({
roles: ['admin']
}))
.then((res) => {
expect(res).to.have.status(200);
expect(res).to.be.json;
expect(res.body).to.have.property('moderation', 'pre');
});
});
});
it('should return a settings object', () => {
return chai.request(app)
.get('/api/v1/settings')
.set(passport.inject({
roles: ['admin']
}))
.then((res) => {
expect(res).to.have.status(200);
expect(res).to.be.json;
expect(res.body).to.have.property('moderation', 'pre');
});
});
});
describe('#put', () => {
// update the settings.
describe('update settings', () => {
it('should respond ok to a PUT', () => {
return Setting
.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true})
.then(() => {
return chai.request(app)
.put('/api/v1/settings')
.set(passport.inject({
roles: ['admin']
}))
.send({moderation: 'post'});
})
.then(res => {
expect(res).to.have.status(204);
it('should update the settings', () => {
return chai.request(app)
.put('/api/v1/settings')
.set(passport.inject({roles: ['admin']}))
.send({moderation: 'post'})
.then((res) => {
expect(res).to.have.status(204);
return Setting.getSettings();
})
.then(settings => {
// confirm updated settings in db
expect(settings).to.have.property('moderation');
expect(settings.moderation).to.equal('post');
});
return Setting.getSettings();
})
.then((settings) => {
expect(settings).to.have.property('moderation', 'post');
});
});
});
});