fix: Fix _redirects file
This commit is contained in:
committed by
mrugesh mohapatra
parent
9a4e13954a
commit
f9ff43d128
@ -4,7 +4,7 @@ const { createRedirects } = require('./createRedirects');
|
||||
|
||||
const testLocations = {
|
||||
api: 'https://api.example.com',
|
||||
home: 'https://home.example.com',
|
||||
news: 'https://news.example.com',
|
||||
forum: 'https://forum.example.com',
|
||||
};
|
||||
|
||||
@ -18,29 +18,26 @@ describe('createRedirects', () => {
|
||||
});
|
||||
|
||||
it('replaces instances of `#{{...}}` with the locations provided', () => {
|
||||
expect.assertions(7);
|
||||
expect.assertions(6);
|
||||
|
||||
const apiPlaceholderRE = /#\{\{API\}\}/;
|
||||
const homePlaceholderRE = /#\{\{HOME\}\}/;
|
||||
const forumPlacehilderRE = /#\{\{FORUM\}\}/;
|
||||
const forumProxyPlaceholderRE = /#\{\{FORUM_PROXY\}\}/;
|
||||
const newsPlaceholderRE = /#\{\{NEWS\}\}/;
|
||||
const forumPlaceholderRE = /#\{\{FORUM\}\}/;
|
||||
const redirects = createRedirects(testLocations);
|
||||
|
||||
const hasApiPlaceholder = apiPlaceholderRE.test(redirects);
|
||||
const hasHomePlaceholder = homePlaceholderRE.test(redirects);
|
||||
const hasForumPlaceholder = forumPlacehilderRE.test(redirects);
|
||||
const hasForumProxyPlaceholder = forumProxyPlaceholderRE.test(redirects);
|
||||
const hasNewsPlaceholder = newsPlaceholderRE.test(redirects);
|
||||
const hasForumPlaceholder = forumPlaceholderRE.test(redirects);
|
||||
|
||||
expect(hasApiPlaceholder).toBe(false);
|
||||
expect(hasHomePlaceholder).toBe(false);
|
||||
expect(hasNewsPlaceholder).toBe(false);
|
||||
expect(hasForumPlaceholder).toBe(false);
|
||||
expect(hasForumProxyPlaceholder).toBe(false);
|
||||
|
||||
const { api, home, forum } = testLocations;
|
||||
const { api, forum } = testLocations;
|
||||
expect(redirects.includes(`${api}/internal/:splat`)).toBe(true);
|
||||
expect(
|
||||
redirects.includes(
|
||||
`${home}/forum/t/free-code-camp-privacy-policy/19545 301`
|
||||
`${forum}/t/free-code-camp-privacy-policy/19545 301`
|
||||
)
|
||||
).toBe(true);
|
||||
expect(redirects.includes(`${forum}`)).toBe(true);
|
||||
@ -50,15 +47,15 @@ describe('createRedirects', () => {
|
||||
expect.assertions(3);
|
||||
|
||||
const api = 'api';
|
||||
const home = 'home';
|
||||
const news = 'news';
|
||||
const forum = 'forum';
|
||||
|
||||
const noApi = { forum, home };
|
||||
const noHome = { api, forum };
|
||||
const noForum = { api, home };
|
||||
const noApi = { forum, news };
|
||||
const noNews = { api, forum };
|
||||
const noForum = { api, news };
|
||||
|
||||
expect(() => createRedirects(noApi)).toThrow();
|
||||
expect(() => createRedirects(noHome)).toThrow();
|
||||
expect(() => createRedirects(noNews)).toThrow();
|
||||
expect(() => createRedirects(noForum)).toThrow();
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user