fix: tests

This commit is contained in:
Bouncey
2019-02-04 12:34:44 +00:00
committed by mrugesh mohapatra
parent d79f9f4899
commit 29113fc9f2
3 changed files with 17 additions and 22 deletions

View File

@ -1,4 +1,4 @@
/* global describe expect */
/* global describe expect it */
const { createRedirects } = require('./createRedirects');
@ -6,7 +6,6 @@ const testLocations = {
api: 'https://api.example.com',
home: 'https://home.example.com',
forum: 'https://forum.example.com',
forumProxy: 'https://proxy.example.com'
};
describe('createRedirects', () => {
@ -19,7 +18,7 @@ describe('createRedirects', () => {
});
it('replaces instances of `#{{...}}` with the locations provided', () => {
expect.assertions(8);
expect.assertions(7);
const apiPlaceholderRE = /#\{\{API\}\}/;
const homePlaceholderRE = /#\{\{HOME\}\}/;
@ -37,34 +36,30 @@ describe('createRedirects', () => {
expect(hasForumPlaceholder).toBe(false);
expect(hasForumProxyPlaceholder).toBe(false);
const { api, home, forum, forumProxy } = testLocations;
const { api, home, forum } = testLocations;
expect(redirects.includes(`${api}/internal/:splat`)).toBe(true);
expect(
redirects.includes(
`${home}/forum/t/free-code-camp-privacy-policy/19545 301`
)
).toBe(true);
expect(redirects.includes(`${forum} 301`)).toBe(true);
expect(redirects.includes(`${forumProxy} 200`)).toBe(true);
expect(redirects.includes(`${forum}`)).toBe(true);
});
it('throws when any location is missing', () => {
expect.assertions(4);
expect.assertions(3);
const api = 'api';
const home = 'home';
const forum = 'forum';
const forumProxy = 'forumProxy';
const noApi = { forum, home, forumProxy };
const noHome = { api, forum, forumProxy };
const noForum = { api, home, forumProxy };
const noProxy = { api, home, forum };
const noApi = { forum, home };
const noHome = { api, forum };
const noForum = { api, home };
expect(() => createRedirects(noApi)).toThrow();
expect(() => createRedirects(noHome)).toThrow();
expect(() => createRedirects(noForum)).toThrow();
expect(() => createRedirects(noProxy)).toThrow();
});
it('matches the snapshot', () =>