Files
freeCodeCamp/cypress/e2e/default/learn/challenges/failed-updates.ts
Oliver Eyton-Williams c772b9884a chore(deps): update Cypress to version 12 (#51622)
Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com>
2023-09-22 15:42:56 -05:00

56 lines
1.9 KiB
TypeScript

import store from 'store';
import { ChallengeData } from '../../../../../tools/challenge-editor/api/interfaces/challenge-data';
const failedUpdates = [
{
endpoint: '/modern-challenge-completed',
payload: { id: '5dc1798ff86c76b9248c6eb3', challengeType: 0 },
id: '4bd1d704-cfaa-44f7-92a3-bc0d857dbaa6'
},
{
endpoint: '/modern-challenge-completed',
payload: { id: '5dc17d3bf86c76b9248c6eb4', challengeType: 0 },
id: 'ea289e2f-a5d2-45e0-b795-0f9f4afc5124'
}
];
const failedUpdatesKey = 'fcc-failed-updates';
function getCompletedIds(completedChallenges: ChallengeData[]): string[] {
return completedChallenges.map((challenge: ChallengeData) => challenge.id);
}
describe('failed update flushing', function () {
before(() => {
cy.task('seed');
cy.login();
});
it('should resubmit failed updates, check they are stored, then flush', () => {
store.set(failedUpdatesKey, failedUpdates);
cy.request('http://localhost:3000/user/get-session-user')
.its('body.user.developmentuser.completedChallenges')
.then(
(completedChallenges: ChallengeData[]) =>
expect(completedChallenges).to.be.empty
);
cy.intercept('http://localhost:3000/modern-challenge-completed').as(
'completed'
);
cy.wrap(store.get(failedUpdatesKey)).should('deep.equal', failedUpdates);
cy.visit('/');
cy.wait('@completed');
// if we don't wait for both requests to complete, we have a race condition
cy.wait('@completed');
cy.request('http://localhost:3000/user/get-session-user')
.its('body.user.developmentuser.completedChallenges')
.then((completedChallenges: ChallengeData[]) => {
const completedIds: string[] = getCompletedIds(completedChallenges);
failedUpdates.forEach(failedUpdate => {
expect(completedIds).to.include(failedUpdate.payload.id);
});
expect(store.get(failedUpdatesKey)).to.be.empty;
});
});
});