|
|
@@ -29,6 +29,7 @@ describe('ShareLink', () => {
|
|
|
|
|
|
const shareLink = {
|
|
|
relatedPage: 'relatedPageId',
|
|
|
+ populate: null,
|
|
|
};
|
|
|
|
|
|
const relatedPage = {
|
|
|
@@ -43,7 +44,7 @@ describe('ShareLink', () => {
|
|
|
|
|
|
test('share link is not found', async() => {
|
|
|
|
|
|
- shareLink.populate = () => { return null };
|
|
|
+ shareLink.populate = jest.fn(() => { return null });
|
|
|
|
|
|
jest.spyOn(ShareLink, 'findOne').mockImplementation(() => {
|
|
|
return shareLink;
|
|
|
@@ -51,25 +52,27 @@ describe('ShareLink', () => {
|
|
|
|
|
|
const response = await Page.showSharedPage(req, res);
|
|
|
|
|
|
+ expect(shareLink.populate).toHaveBeenCalled();
|
|
|
expect(response).toEqual('layout-growi/not_found_shared_page');
|
|
|
});
|
|
|
|
|
|
test('share link is found, but it does not have Page', async() => {
|
|
|
|
|
|
- shareLink.populate = () => { return { _id: 'somePageId' } };
|
|
|
+ shareLink.populate = jest.fn(() => { return { _id: 'somePageId' } });
|
|
|
|
|
|
jest.spyOn(ShareLink, 'findOne').mockImplementation(() => {
|
|
|
return shareLink;
|
|
|
});
|
|
|
const response = await Page.showSharedPage(req, res);
|
|
|
|
|
|
+ expect(shareLink.populate).toHaveBeenCalled();
|
|
|
expect(response).toEqual('layout-growi/not_found_shared_page');
|
|
|
});
|
|
|
|
|
|
|
|
|
test('share link is found, but it is expired', async() => {
|
|
|
|
|
|
- shareLink.populate = () => { return { _id: 'somePageId', relatedPage, isExpired: () => { return true } } };
|
|
|
+ shareLink.populate = jest.fn(() => { return { _id: 'somePageId', relatedPage, isExpired: () => { return true } } });
|
|
|
|
|
|
jest.spyOn(ShareLink, 'findOne').mockImplementation(() => {
|
|
|
return shareLink;
|
|
|
@@ -77,18 +80,20 @@ describe('ShareLink', () => {
|
|
|
|
|
|
const response = await Page.showSharedPage(req, res);
|
|
|
|
|
|
+ expect(shareLink.populate).toHaveBeenCalled();
|
|
|
expect(response).toEqual('layout-growi/expired_shared_page');
|
|
|
});
|
|
|
|
|
|
test('share link is found, and it has the page you can see', async() => {
|
|
|
|
|
|
- shareLink.populate = () => { return { _id: 'somePageId', relatedPage, isExpired: () => { return false } } };
|
|
|
+ shareLink.populate = jest.fn(() => { return { _id: 'somePageId', relatedPage, isExpired: () => { return false } } });
|
|
|
|
|
|
jest.spyOn(ShareLink, 'findOne').mockImplementation(() => {
|
|
|
return shareLink;
|
|
|
});
|
|
|
const response = await Page.showSharedPage(req, res);
|
|
|
|
|
|
+ expect(shareLink.populate).toHaveBeenCalled();
|
|
|
expect(response).toEqual('layout-growi/shared_page');
|
|
|
});
|
|
|
});
|