fix: clean failed challenges (#37526)

This commit is contained in:
Ahmad Abdolsaheb
2019-11-04 16:50:14 +03:00
committed by mrugesh
parent c2e7809ccd
commit 55a4cadf2a
4 changed files with 81 additions and 1 deletions

View File

@ -19,6 +19,9 @@
.universal-nav a { .universal-nav a {
text-decoration: none; text-decoration: none;
}
.universal-nav .universal-nav-right a {
font-family: 'Roboto Mono', monospace; font-family: 'Roboto Mono', monospace;
} }

View File

@ -19,6 +19,7 @@ import {
} from './'; } from './';
import postUpdate$ from '../templates/Challenges/utils/postUpdate$'; import postUpdate$ from '../templates/Challenges/utils/postUpdate$';
import { isGoodXHRStatus } from '../templates/Challenges/utils'; import { isGoodXHRStatus } from '../templates/Challenges/utils';
import { backEndProject } from '../../utils/challengeTypes';
const key = 'fcc-failed-updates'; const key = 'fcc-failed-updates';
@ -26,6 +27,10 @@ function delay(time = 0, fn) {
return setTimeout(fn, time); return setTimeout(fn, time);
} }
// check if backenEndProjects have a solution
const isSubmitable = failure =>
failure.payload.challengeType !== backEndProject || failure.payload.solution;
function failedUpdateEpic(action$, state$) { function failedUpdateEpic(action$, state$) {
const storeUpdates = action$.pipe( const storeUpdates = action$.pipe(
ofType(types.updateFailed), ofType(types.updateFailed),
@ -45,7 +50,16 @@ function failedUpdateEpic(action$, state$) {
filter(() => store.get(key)), filter(() => store.get(key)),
filter(() => isOnlineSelector(state$.value)), filter(() => isOnlineSelector(state$.value)),
tap(() => { tap(() => {
const failures = store.get(key) || []; let failures = store.get(key) || [];
let submitableFailures = failures.filter(isSubmitable);
// delete unsubmitable failed challenges
if (submitableFailures.length !== failures.length) {
store.set(key, submitableFailures);
failures = submitableFailures;
}
let delayTime = 100; let delayTime = 100;
const batch = failures.map((update, i) => { const batch = failures.map((update, i) => {
// we stagger the updates here so we don't hammer the server // we stagger the updates here so we don't hammer the server

View File

@ -0,0 +1,62 @@
/* global expect */
import { Subject } from 'rxjs';
import { ActionsObservable, StateObservable } from 'redux-observable';
import failedUpdatesEpic from './failed-updates-epic';
import { types } from './';
import store from 'store';
const key = 'fcc-failed-updates';
describe('failed-updates-epic', () => {
it('should remove falty backend challenges from localStorage', async () => {
store.set(key, failedSubmitions);
const action$ = ActionsObservable.of({
type: types.updateComplete
});
const state$ = new StateObservable(new Subject(), initialState);
const epic$ = failedUpdatesEpic(action$, state$);
await epic$.toPromise();
expect(store.get(key)).toEqual(submitableChallenges);
});
});
const initialState = {
app: {
isOnline: true,
appUsername: 'developmentuser'
}
};
const failedSubmitions = [
{
endpoint: '/project-completed',
id: 'b1507944-7310-479f-bb59-ccafac488592',
payload: { id: '587d8249367417b2b2512c41', challengeType: 4 }
},
{
endpoint: '/project-completed',
id: 'b1507944-7310-479f-bb59-ccafac488593',
payload: {
id: '587d8249367417b2b2512c42',
challengeType: 4,
solution: 'http://freecodecamp.org/',
githubLink: 'https://github.com/'
}
},
{
endpoint: '/project-completed',
id: 'b1507944-7310-479f-bb59-ccafac488594',
payload: {
id: '587d8249367417b2b2512c43',
challengeType: 4,
solution: 'http://freecodecamp.org/',
githubLink: 'https://github.com/'
}
}
];
const submitableChallenges = failedSubmitions.slice(1);

View File

@ -13,6 +13,7 @@ const invalid = 9;
// individual exports // individual exports
exports.backend = backend; exports.backend = backend;
exports.frontEndProject = frontEndProject; exports.frontEndProject = frontEndProject;
exports.backEndProject = backEndProject;
exports.challengeTypes = { exports.challengeTypes = {
html, html,