Yuki Takei 6 лет назад
Родитель
Сommit
49e3cef3a6
3 измененных файлов с 17 добавлено и 32 удалено
  1. 10 18
      src/test/models/page.test.js
  2. 3 8
      src/test/models/updatePost.test.js
  3. 4 6
      src/test/models/user.test.js

+ 10 - 18
src/test/models/page.test.js

@@ -117,23 +117,17 @@ describe('Page', () => {
 
   describe('.isPublic', () => {
     describe('with a public page', () => {
-      test('should return true', (done) => {
-        Page.findOne({ path: '/grant/public' }, (err, page) => {
-          expect(err).toBeNull();
-          expect(page.isPublic()).toEqual(true);
-          done();
-        });
+      test('should return true', async() => {
+        const page = await Page.findOne({ path: '/grant/public' });
+        expect(page.isPublic()).toEqual(true);
       });
     });
 
     ['restricted', 'specified', 'owner'].forEach((grant) => {
       describe(`with a ${grant} page`, () => {
-        test('should return false', (done) => {
-          Page.findOne({ path: `/grant/${grant}` }, (err, page) => {
-            expect(err).toBeNull();
-            expect(page.isPublic()).toEqual(false);
-            done();
-          });
+        test('should return false', async() => {
+          const page = await Page.findOne({ path: `/grant/${grant}` });
+          expect(page.isPublic()).toEqual(false);
         });
       });
     });
@@ -241,12 +235,10 @@ describe('Page', () => {
 
   describe('Extended field', () => {
     describe('Slack Channel.', () => {
-      test('should be empty', (done) => {
-        Page.findOne({ path: '/page/for/extended' }, (err, page) => {
-          expect(page.extended.hoge).toEqual(1);
-          expect(page.getSlackChannel()).toEqual('');
-          done();
-        });
+      test('should be empty', async() => {
+        const page = await Page.findOne({ path: '/page/for/extended' });
+        expect(page.extended.hoge).toEqual(1);
+        expect(page.getSlackChannel()).toEqual('');
       });
 
       test('set slack channel and should get it and should keep hoge ', async() => {

+ 3 - 8
src/test/models/updatePost.test.js

@@ -19,40 +19,35 @@ describe('UpdatePost', () => {
 
   describe('.createPrefixesByPathPattern', () => {
     describe('with a path', () => {
-      test('should return right patternPrfixes', (done) => {
+      test('should return right patternPrfixes', () => {
         expect(UpdatePost.createPrefixesByPathPattern('/*')).toEqual(['*', '*']);
         expect(UpdatePost.createPrefixesByPathPattern('/user/*/日報*')).toEqual(['user', '*']);
         expect(UpdatePost.createPrefixesByPathPattern('/project/hoge/*')).toEqual(['project', 'hoge']);
         expect(UpdatePost.createPrefixesByPathPattern('/*/MTG/*')).toEqual(['*', 'MTG']);
         expect(UpdatePost.createPrefixesByPathPattern('自己紹介')).toEqual(['*', '*']);
         expect(UpdatePost.createPrefixesByPathPattern('/user/aoi/メモ/2016/02/10/xxx')).toEqual(['user', 'aoi']);
-
-        done();
       });
     });
   });
 
   describe('.getRegExpByPattern', () => {
     describe('with a pattern', () => {
-      test('should return right regexp', (done) => {
+      test('should return right regexp', () => {
         expect(UpdatePost.getRegExpByPattern('/*')).toEqual(/^\/.*/);
         expect(UpdatePost.getRegExpByPattern('/user/*/日報*')).toEqual(/^\/user\/.*\/日報.*/);
         expect(UpdatePost.getRegExpByPattern('/project/hoge/*')).toEqual(/^\/project\/hoge\/.*/);
         expect(UpdatePost.getRegExpByPattern('/*/MTG/*')).toEqual(/^\/.*\/MTG\/.*/);
         expect(UpdatePost.getRegExpByPattern('自己紹介')).toEqual(/^\/.*自己紹介.*/);
         expect(UpdatePost.getRegExpByPattern('/user/aoi/メモ/2016/02/10/xxx')).toEqual(/^\/user\/aoi\/メモ\/2016\/02\/10\/xxx/);
-        done();
       });
     });
   });
 
   describe('.normalizeChannelName', () => {
     describe('with a channel name', () => {
-      test('should return true', (done) => {
+      test('should return true', () => {
         expect(UpdatePost.normalizeChannelName('#pj-hoge')).toEqual('pj-hoge');
         expect(UpdatePost.normalizeChannelName('pj-hoge')).toEqual('pj-hoge');
-
-        done();
       });
     });
   });

+ 4 - 6
src/test/models/user.test.js

@@ -25,6 +25,7 @@ describe('User', () => {
 
   describe('Create and Find.', () => {
     describe('The user', () => {
+      /* eslint-disable jest/no-test-callback */
       test('should created with createUserByEmailAndPassword', (done) => {
         User.createUserByEmailAndPassword('Example2 for User Test', 'usertest2', 'usertest2@example.com', 'usertest2pass', 'en', (err, userData) => {
           expect(err).toBeNull();
@@ -33,6 +34,7 @@ describe('User', () => {
           done();
         });
       });
+      /* eslint-enable jest/no-test-callback */
 
       test('should be found by findUserByUsername', async() => {
         const user = await User.findUserByUsername('usertest');
@@ -52,23 +54,19 @@ describe('User', () => {
 
   describe('User Utilities', () => {
     describe('Get username from path', () => {
-      test('found', (done) => {
+      test('found', () => {
         let username = null;
         username = User.getUsernameByPath('/user/sotarok');
         expect(username).toEqual('sotarok');
 
         username = User.getUsernameByPath('/user/some.user.name12/'); // with slash
         expect(username).toEqual('some.user.name12');
-
-        done();
       });
 
-      test('not found', (done) => {
+      test('not found', () => {
         let username = null;
         username = User.getUsernameByPath('/the/page/is/not/related/to/user/page');
         expect(username).toBeNull();
-
-        done();
       });
     });
   });