Yuki Takei 6 лет назад
Родитель
Сommit
b4277fbe20
2 измененных файлов с 43 добавлено и 50 удалено
  1. 33 41
      src/test/models/config.test.js
  2. 10 9
      src/test/utils.js

+ 33 - 41
src/test/models/config.test.js

@@ -1,22 +1,13 @@
-const chai = require('chai');
-const sinonChai = require('sinon-chai');
-
-const mongoose = require('mongoose');
-
 const utils = require('../utils.js');
 
-const { expect } = chai;
-
-chai.use(sinonChai);
-
 /* global testDBUtil */
 
 describe('Config model test', () => {
-  const Config = mongoose.model('Config');
-
-  const conn = utils.mongoose.connection;
+  // const conn = utils.mongoose.connection;
+  // const Config = utils.models.Config;
 
   beforeAll((done) => {
+
     const fixture = [
       { ns: 'crowi', key: 'test:test', value: JSON.stringify('crowi test value') },
       { ns: 'crowi', key: 'test:test2', value: JSON.stringify(11111) },
@@ -24,40 +15,41 @@ describe('Config model test', () => {
       { ns: 'plugin', key: 'other:config', value: JSON.stringify('this is data') },
     ];
 
-    testDBUtil.generateFixture(conn, 'Config', fixture)
-      .then((configs) => {  // eslint-disable-line
-        done();
-      }).catch(() => {
-        done(new Error('Skip this test.'));
-      });
+    done();
+
+    // testDBUtil.generateFixture(conn, 'Config', fixture)
+    //   .then((configs) => {
+    //     done();
+    //   })
+    //   .catch(() => {
+    //     done(new Error('Skip this test.'));
+    //   });
   });
 
   describe('.CONSTANTS', () => {
     test('Config has constants', () => {
-      expect(Config.SECURITY_REGISTRATION_MODE_OPEN).to.have.string('Open');
-      expect(Config.SECURITY_REGISTRATION_MODE_RESTRICTED).to.have.string('Resricted');
-      expect(Config.SECURITY_REGISTRATION_MODE_CLOSED).to.have.string('Closed');
+      expect('hoge').toBe('Open');
+      // expect(Config.SECURITY_REGISTRATION_MODE_OPEN).toBe('Open');
+      // expect(Config.SECURITY_REGISTRATION_MODE_RESTRICTED).toBe('Resricted');
+      // expect(Config.SECURITY_REGISTRATION_MODE_CLOSED).toBe('Closed');
     });
   });
 
-  describe('.loadAllConfig', () => {
-    test('Get config array', (done) => {
-      Config.loadAllConfig((err, config) => {
-        expect(config.crowi).to.be.an('Object');
-        expect(config.crowi).to.have.property('test:test')
-          .and.equal('crowi test value');
-        expect(config.crowi).to.have.property('test:test2')
-          .and.equal(11111);
-        expect(config.crowi).to.have.property('test:test3')
-          .and.to.be.instanceof(Array)
-          .and.deep.equal([1, 2, 3, 4, 5]);
-
-        expect(config.plugin).to.be.an('Object')
-          .and.have.property('other:config')
-          .and.equal('this is data');
-
-        done();
-      });
-    });
-  });
+  // describe('.loadAllConfig', () => {
+  //   test('Get config array', (done) => {
+  //     const Config = mongoose.model('Config');
+
+  //     Config.loadAllConfig((err, config) => {
+  //       expect(config.crowi).toBeInstanceOf(Object);
+  //       expect(config.crowi).toHaveProperty('test:test', 'crowi test value');
+  //       expect(config.crowi).toHaveProperty('test:test2', 11111);
+  //       expect(config.crowi).toHaveProperty('test:test3', [1, 2, 3, 4, 5]);
+
+  //       expect(config.plugin).toBeInstanceOf(Object);
+  //       expect(config.plugin).toHaveProperty('other:config', 'this is data');
+
+  //       done();
+  //     });
+  //   });
+  // });
 });

+ 10 - 9
src/test/utils.js

@@ -3,12 +3,11 @@ const mongoUri = process.env.MONGOLAB_URI || process.env.MONGOHQ_URL || process.
 
 const mongoose = require('mongoose');
 
-const helpers = require('@commons/util/helpers');
-const Crowi = require('@server/crowi');
-
-const crowi = new Crowi(helpers.root(), process.env);
+const models = require('@server/models');
+models.Config = require('@server/models/config');
 
-const models = {};
+const helpers = require('@commons/util/helpers');
+const crowi = new (require('@server/crowi'))(helpers.root());
 
 mongoose.Promise = global.Promise;
 
@@ -18,11 +17,7 @@ beforeAll(async() => {
   }
 
   await mongoose.connect(mongoUri, { useNewUrlParser: true });
-
-  // drop database
   await mongoose.connection.dropDatabase();
-
-  await crowi.initForTest();
 });
 
 afterAll(async() => {
@@ -33,6 +28,12 @@ afterAll(async() => {
   return mongoose.disconnect();
 });
 
+// Setup Models
+// for (const [modelName, model] of Object.entries(models)) {
+//   models[modelName] = model(crowi);
+// }
+// crowi.models = models;
+
 module.exports = {
   models,
   mongoose,