config.test.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. var chai = require('chai')
  2. , expect = chai.expect
  3. , sinon = require('sinon')
  4. , sinonChai = require('sinon-chai')
  5. , Promise = require('bluebird')
  6. , utils = require('../utils.js')
  7. ;
  8. chai.use(sinonChai);
  9. describe('Config model test', function () {
  10. var Page = utils.models.Page,
  11. Config = utils.models.Config,
  12. User = utils.models.User,
  13. conn = utils.mongoose.connection;
  14. before(function (done) {
  15. var fixture = [
  16. {ns: 'crowi', key: 'test:test', value: JSON.stringify('crowi test value')},
  17. {ns: 'crowi', key: 'test:test2', value: JSON.stringify(11111)},
  18. {ns: 'crowi', key: 'test:test3', value: JSON.stringify([1, 2, 3, 4, 5])},
  19. {ns: 'plugin', key: 'other:config', value: JSON.stringify('this is data')},
  20. ];
  21. testDBUtil.generateFixture(conn, 'Config', fixture)
  22. .then(function(configs) {
  23. done();
  24. }).catch(function() {
  25. done(new Error('Skip this test.'));
  26. });
  27. });
  28. describe('.CONSTANTS', function () {
  29. it('Config has constants', function() {
  30. expect(Config.SECURITY_REGISTRATION_MODE_OPEN).to.have.string('Open');
  31. expect(Config.SECURITY_REGISTRATION_MODE_RESTRICTED).to.have.string('Resricted');
  32. expect(Config.SECURITY_REGISTRATION_MODE_CLOSED).to.have.string('Closed');
  33. });
  34. });
  35. describe('.loadAllConfig', function () {
  36. it('Get config array', function(done) {
  37. Config.loadAllConfig(function(err, config) {
  38. expect(config.crowi).to.be.an('Object');
  39. expect(config.crowi).to.have.property('test:test')
  40. .and.equal('crowi test value');
  41. expect(config.crowi).to.have.property('test:test2')
  42. .and.equal(11111);
  43. expect(config.crowi).to.have.property('test:test3')
  44. .and.to.be.instanceof(Array)
  45. .and.deep.equal([1, 2, 3, 4, 5]);
  46. expect(config.plugin).to.be.an('Object')
  47. .and.have.property('other:config')
  48. .and.equal('this is data');
  49. done();
  50. });
  51. });
  52. });
  53. });