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 it */
/* global describe beforeEach expect it */
import inMemoryCache from './in-memory-cache';
import sinon from 'sinon';

View File

@ -25,18 +25,18 @@ exports[`createRedirects matches the snapshot 1`] = `
/ue/* https://api.example.com/ue/:splat
# misc redirects
/agile / 200
/agile / 301
/chat https://gitter.im/FreeCodeCamp/FreeCodeCamp 301
/twitch https://twitch.tv/freecodecamp 301
/nonprofits-form / 200
/pmi-acp-agile-project-managers / 200
/pmi-acp-agile-project-managers-form / 200
/stories / 200
/all-stories / 200
/field-guide/* https://forum.example.com 301
/nonprofits-form / 301
/pmi-acp-agile-project-managers / 301
/pmi-acp-agile-project-managers-form / 301
/stories / 301
/all-stories / 301
/field-guide/* /forum 301
/learn-to-code /learn 200
/map /learn 200
/forum/* https://proxy.example.com 200
/forum/* https://forum.example.com/:splat
/privacy https://home.example.com/forum/t/free-code-camp-privacy-policy/19545 301
/nonprofit-project-instructions https://home.example.com/forum/t/how-free-code-camps-nonprofits-projects-work/19547 301
/how-nonprofit-projects-work https://medium.freecodecamp.org/open-source-for-good-1a0ea9f32d5a 301

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', () =>