Browse Source

page.test.js

mizozobu 6 years ago
parent
commit
882ae3b868
2 changed files with 49 additions and 49 deletions
  1. 1 1
      src/server/models/index.js
  2. 48 48
      src/test/models/page.test.js

+ 1 - 1
src/server/models/index.js

@@ -1,5 +1,5 @@
 module.exports = {
 module.exports = {
-  Config: require('./Config'),
+  Config: require('./config'),
   Page: require('./page'),
   Page: require('./page'),
   PageTagRelation: require('./page-tag-relation'),
   PageTagRelation: require('./page-tag-relation'),
   User: require('./user'),
   User: require('./user'),

+ 48 - 48
src/test/models/page.test.js

@@ -314,55 +314,55 @@ describe('Page', () => {
         expect(page).toBeNull();
         expect(page).toBeNull();
       });
       });
     });
     });
+  });
+
+  describe('findListWithDescendants', () => {
+    test('should return only /page/', async() => {
+      const result = await Page.findListWithDescendants('/page/', testUser0, { isRegExpEscapedFromPath: true });
+
+      // assert totalCount
+      expect(result.totalCount).toEqual(1);
+      // assert paths
+      const pagePaths = result.pages.map((page) => { return page.path });
+      expect(pagePaths).toContainEqual('/page/for/extended');
+    });
+
+    test('should return only /page1/', async() => {
+      const result = await Page.findListWithDescendants('/page1/', testUser0, { isRegExpEscapedFromPath: true });
 
 
-    // describe('findListWithDescendants', () => {
-    //   test('should return only /page/', async() => {
-    //     const user = createdUsers[0];
-
-    //     const result = await Page.findListWithDescendants('/page/', user, { isRegExpEscapedFromPath: true });
-
-    //     // assert totalCount
-    //     expect(result.totalCount).to.equal(1);
-    //     // assert paths
-    //     const pagePaths = result.pages.map((page) => { return page.path });
-    //     expect(pagePaths).to.include.members(['/page/for/extended']);
-    //   });
-    //   test('should return only /page1/', async() => {
-    //     const user = createdUsers[0];
-
-    //     const result = await Page.findListWithDescendants('/page1/', user, { isRegExpEscapedFromPath: true });
-
-    //     // assert totalCount
-    //     expect(result.totalCount).to.equal(2);
-    //     // assert paths
-    //     const pagePaths = result.pages.map((page) => { return page.path });
-    //     expect(pagePaths).to.include.members(['/page1', '/page1/child1']);
-    //   });
-    // });
-
-    // describe('findListByStartWith', () => {
-    //   test('should return pages which starts with /page', async() => {
-    //     const user = createdUsers[0];
-
-    //     const result = await Page.findListByStartWith('/page', user, {});
-
-    //     // assert totalCount
-    //     expect(result.totalCount).to.equal(4);
-    //     // assert paths
-    //     const pagePaths = result.pages.map((page) => { return page.path });
-    //     expect(pagePaths).to.include.members(['/page/for/extended', '/page1', '/page1/child1', '/page2']);
-    //   });
-    //   test('should process with regexp', async() => {
-    //     const user = createdUsers[0];
-
-    //     const result = await Page.findListByStartWith('/page\\d{1}/', user, {});
-
-  //     // assert totalCount
-  //     expect(result.totalCount).to.equal(3);
-  //     // assert paths
-  //     const pagePaths = result.pages.map((page) => { return page.path });
-  //     expect(pagePaths).to.include.members(['/page1', '/page1/child1', '/page2']);
-  //   });
+      // assert totalCount
+      expect(result.totalCount).toEqual(2);
+      // assert paths
+      const pagePaths = result.pages.map((page) => { return page.path });
+      expect(pagePaths).toContainEqual('/page1');
+      expect(pagePaths).toContainEqual('/page1/child1');
+    });
   });
   });
 
 
+  describe('findListByStartWith', () => {
+    test('should return pages which starts with /page', async() => {
+      const result = await Page.findListByStartWith('/page', testUser0, {});
+
+      // assert totalCount
+      expect(result.totalCount).toEqual(4);
+      // assert paths
+      const pagePaths = result.pages.map((page) => { return page.path });
+      expect(pagePaths).toContainEqual('/page/for/extended');
+      expect(pagePaths).toContainEqual('/page1');
+      expect(pagePaths).toContainEqual('/page1/child1');
+      expect(pagePaths).toContainEqual('/page2');
+    });
+
+    test('should process with regexp', async() => {
+      const result = await Page.findListByStartWith('/page\\d{1}/', testUser0, {});
+
+      // assert totalCount
+      expect(result.totalCount).toEqual(3);
+      // assert paths
+      const pagePaths = result.pages.map((page) => { return page.path });
+      expect(pagePaths).toContainEqual('/page1');
+      expect(pagePaths).toContainEqual('/page1/child1');
+      expect(pagePaths).toContainEqual('/page2');
+    });
+  });
 });
 });