fix(api): remove redirects from api

They should be handled either by nginx or by the client. Turned out a
lot of code, including the path migration, existed to support them.
Hence the large number of removals
This commit is contained in:
Oliver Eyton-Williams
2020-08-21 18:55:28 +02:00
committed by Mrugesh Mohapatra
parent 4a45b5ac1c
commit 1ad5f756e0
12 changed files with 3 additions and 234 deletions

View File

@ -1,17 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`createPathMigrationMap output snapshot 1`] = `
Object {
"challenge-eight": "/learn/super-block-a/block-two/challenge-eight",
"challenge-eleven": "/learn/super-block-b/block-one/challenge-eleven",
"challenge-five": "/learn/super-block-a/block-two/challenge-five",
"challenge-four": "/learn/super-block-a/block-one/challenge-four",
"challenge-one": "/learn/super-block-a/block-one/challenge-one",
"challenge-seven": "/learn/super-block-a/block-two/challenge-seven",
"challenge-six": "/learn/super-block-a/block-two/challenge-six",
"challenge-ten": "/learn/super-block-b/block-one/challenge-ten",
"challenge-three": "/learn/super-block-a/block-one/challenge-three",
"challenge-twelve": "/learn/super-block-b/block-one/challenge-twelve",
"challenge-two": "/learn/super-block-a/block-one/challenge-two",
}
`;

View File

@ -1,27 +0,0 @@
const path = require('path');
const fs = require('fs');
require('dotenv').config({ path: path.resolve(__dirname, '../../../.env') });
const debug = require('debug');
const { getChallengesForLang } = require('../../../curriculum/getChallenges');
const { createPathMigrationMap } = require('./createPathMigrationMap');
const log = debug('fcc:tools:seedChallenges');
const { LOCALE: lang = 'english' } = process.env;
getChallengesForLang(lang).then(curriculum => {
log('generating path migration map');
const pathMap = createPathMigrationMap(curriculum);
const outputDir = path.resolve(
__dirname,
'../../../api-server/server/resources/pathMigration.json'
);
fs.writeFile(outputDir, JSON.stringify(pathMap), err => {
if (err) {
console.error('failed to save pathMigration');
console.error(err);
} else {
log('path migration map generated');
}
});
});

View File

@ -1,25 +0,0 @@
const { flatten } = require('lodash');
const { dasherize } = require('../../../utils/slugs');
function createPathMigrationMap(curriculum) {
return Object.keys(curriculum)
.map(key => curriculum[key].blocks)
.reduce((challenges, current) => {
const superChallenges = Object.keys(current).map(
key => current[key].challenges
);
return challenges.concat(flatten(superChallenges));
}, [])
.filter(({ isPrivate }) => !isPrivate)
.reduce((map, challenge) => {
const { title, block, superBlock } = challenge;
const dashedTitle = dasherize(title);
map[dashedTitle] = `/learn/${dasherize(superBlock)}/${dasherize(
block
)}/${dashedTitle}`;
return map;
}, {});
}
exports.createPathMigrationMap = createPathMigrationMap;

View File

@ -1,36 +0,0 @@
/* global describe expect */
const { isPlainObject } = require('lodash');
const { createPathMigrationMap } = require('./createPathMigrationMap');
const mockCurriculum = require('./__mocks__/curriculum.json');
describe('createPathMigrationMap', () => {
const pathMap = createPathMigrationMap(mockCurriculum);
it('is a function', () => {
expect(typeof createPathMigrationMap).toEqual('function');
});
it('returns an object', () => {
expect(isPlainObject(pathMap)).toBe(true);
});
it('maps a challenge title to the correct uri slug', () => {
expect.assertions(3);
const slugOne = '/learn/super-block-b/block-one/challenge-ten';
const slugTwo = '/learn/super-block-a/block-two/challenge-five';
const slugThree = '/learn/super-block-a/block-one/challenge-three';
expect(pathMap['challenge-ten']).toEqual(slugOne);
expect(pathMap['challenge-five']).toEqual(slugTwo);
expect(pathMap['challenge-three']).toEqual(slugThree);
});
it('does not add uri migrations for private challenges', () => {
expect(pathMap['challenge-nine']).toBeUndefined();
});
it('output snapshot', () => {
expect(createPathMigrationMap(mockCurriculum)).toMatchSnapshot();
});
});