config.test.js 1.9 KB

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