config.test.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. , app = new express()
  11. , Config = proxyquire(MODEL_DIR + '/config.js', {mongoose: mongoose})(app)
  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. testDBUtil.cleanUpDb(conn, 'Config', function(err, doc) {
  36. conn.close();
  37. done();
  38. });
  39. }
  40. });
  41. describe('.CONSTANTS', function () {
  42. it('Config has constants', function() {
  43. expect(Config.SECURITY_REGISTRATION_MODE_OPEN).to.have.string('Open');
  44. expect(Config.SECURITY_REGISTRATION_MODE_RESTRICTED).to.have.string('Resricted');
  45. expect(Config.SECURITY_REGISTRATION_MODE_CLOSED).to.have.string('Closed');
  46. });
  47. });
  48. describe('.loadAllConfig', function () {
  49. it('Get config array', function(done) {
  50. Config.loadAllConfig(function(err, config) {
  51. expect(config.crowi).to.be.an('Object');
  52. expect(config.crowi).to.have.property('test:test')
  53. .and.equal('crowi test value');
  54. expect(config.crowi).to.have.property('test:test2')
  55. .and.equal(11111);
  56. expect(config.crowi).to.have.property('test:test3')
  57. .and.to.be.instanceof(Array)
  58. .and.deep.equal([1, 2, 3, 4, 5]);
  59. expect(config.plugin).to.be.an('Object')
  60. .and.have.property('other:config')
  61. .and.equal('this is data');
  62. done();
  63. });
  64. });
  65. });
  66. });