itizawa hace 5 años
padre
commit
e0a6c3b2d3
Se han modificado 1 ficheros con 34 adiciones y 1 borrados
  1. 34 1
      src/test/models/shareLink.test.js

+ 34 - 1
src/test/models/shareLink.test.js

@@ -28,11 +28,44 @@ describe('ShareLink', () => {
 
 
     test('share link is not found', async() => {
     test('share link is not found', async() => {
 
 
-      jest.spyOn(ShareLink, 'findOne').mockImplementation(() => { return { populate: () => { return { expiredAt: '2020-05-29T14:44:28.064Z' } } } });
+      jest.spyOn(ShareLink, 'findOne').mockImplementation(() => {
+        return { populate: () => { return null } };
+      });
       const response = await Page.showSharedPage(req, res);
       const response = await Page.showSharedPage(req, res);
 
 
       expect(response).toEqual('layout-growi/not_found_shared_page');
       expect(response).toEqual('layout-growi/not_found_shared_page');
     });
     });
+
+    test('share link is found, but it does not have Page', async() => {
+
+      jest.spyOn(ShareLink, 'findOne').mockImplementation(() => {
+        return { populate: () => { return { _id: '5ed11fcc60ec00c9072f7490' } } };
+      });
+      const response = await Page.showSharedPage(req, res);
+
+      expect(response).toEqual('layout-growi/not_found_shared_page');
+    });
+
+
+    test('share link is found, but it is expired', async() => {
+
+      jest.spyOn(ShareLink, 'findOne').mockImplementation(() => {
+        return { populate: () => { return { _id: '5ed11fcc60ec00c9072f7490', relatedPage: {}, expiredAt: '2020-06-17T10:09:29.088Z' } } };
+      });
+      const response = await Page.showSharedPage(req, res);
+
+      expect(response).toEqual('layout-growi/expired_shared_page');
+    });
+
+    test('share link is found, and it has the page you can see', async() => {
+
+      jest.spyOn(ShareLink, 'findOne').mockImplementation(() => {
+        return { populate: () => { return { _id: '5ed11fcc60ec00c9072f7490', relatedPage: {}, expiredAt: '2100-06-17T10:09:29.088Z' } } };
+      });
+      const response = await Page.showSharedPage(req, res);
+
+      expect(response).toEqual('layout-growi/shared_page');
+    });
   });
   });
 
 
 });
 });