config.test.js 2.4 KB

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