config.test.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. var chai = require('chai')
  2. , expect = chai.expect
  3. , sinon = require('sinon')
  4. , sinonChai = require('sinon-chai')
  5. , proxyquire = require('proxyquire')
  6. , Promise = require('bluebird')
  7. ;
  8. chai.use(sinonChai);
  9. describe('Config model test', function () {
  10. var conn
  11. , crowi = new (require(ROOT_DIR + '/lib/crowi'))(ROOT_DIR, process.env)
  12. , Config = proxyquire(MODEL_DIR + '/config.js', {mongoose: mongoose})(crowi)
  13. ;
  14. before(function (done) {
  15. if (mongoUri) {
  16. // 基本的に mongoUri がセットされてたら、そのURIにはつながる前提
  17. conn = mongoose.createConnection(mongoUri, function(err) {
  18. if (err) {
  19. done(); // ここで skip したいなあ
  20. }
  21. Config = conn.model('Config');
  22. var fixture = [
  23. {ns: 'crowi', key: 'test:test', value: JSON.stringify('crowi test value')},
  24. {ns: 'crowi', key: 'test:test2', value: JSON.stringify(11111)},
  25. {ns: 'crowi', key: 'test:test3', value: JSON.stringify([1, 2, 3, 4, 5])},
  26. {ns: 'plugin', key: 'other:config', value: JSON.stringify('this is data')},
  27. ];
  28. testDBUtil.generateFixture(conn, 'Config', fixture)
  29. .then(function(configs) {
  30. done();
  31. });
  32. });
  33. }
  34. });
  35. beforeEach(function () {
  36. });
  37. after(function (done) {
  38. if (mongoUri) {
  39. testDBUtil.cleanUpDb(conn, 'Config')
  40. .then(function() {
  41. return conn.close(done);
  42. });
  43. }
  44. });
  45. describe('.CONSTANTS', function () {
  46. it('Config has constants', function() {
  47. expect(Config.SECURITY_REGISTRATION_MODE_OPEN).to.have.string('Open');
  48. expect(Config.SECURITY_REGISTRATION_MODE_RESTRICTED).to.have.string('Resricted');
  49. expect(Config.SECURITY_REGISTRATION_MODE_CLOSED).to.have.string('Closed');
  50. });
  51. });
  52. describe('.loadAllConfig', function () {
  53. it('Get config array', function(done) {
  54. Config.loadAllConfig(function(err, config) {
  55. expect(config.crowi).to.be.an('Object');
  56. expect(config.crowi).to.have.property('test:test')
  57. .and.equal('crowi test value');
  58. expect(config.crowi).to.have.property('test:test2')
  59. .and.equal(11111);
  60. expect(config.crowi).to.have.property('test:test3')
  61. .and.to.be.instanceof(Array)
  62. .and.deep.equal([1, 2, 3, 4, 5]);
  63. expect(config.plugin).to.be.an('Object')
  64. .and.have.property('other:config')
  65. .and.equal('this is data');
  66. done();
  67. });
  68. });
  69. });
  70. });