Files
freeCodeCamp/cypress/integration/learn/challenges/failed-updates.js
Oliver Eyton-Williams f0f44ca315 feat(client): re-enable failed update re-submission (#46064)
* refactor: return response with data from ajax

Because we still need to manipulate the data coming back from the server
(files -> challengeFiles) and we want to keep ajax.ts as the interface
between client and server we need to return the manipulated data with
the response.

* feat: re-enable failed updates flushing

* test: failed updates get resubmitted and flushed

* fix: convert settings requests to use { data }

* refactor: use preserveSession
2022-06-07 17:52:23 +03:00

60 lines
1.9 KiB
JavaScript

const store = require('store');
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';
describe('failed update flushing', () => {
before(() => {
cy.exec('npm run seed');
cy.login();
});
beforeEach(() => {
cy.preserveSession();
});
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 => {
const completedIds = completedChallenges.map(challenge => challenge.id);
failedUpdates.forEach(failedUpdate => {
expect(completedIds).not.to.include(failedUpdate.payload.id);
});
});
cy.intercept('http://localhost:3000/modern-challenge-completed').as(
'completed'
);
cy.wrap(store.get(failedUpdatesKey)).should('deep.equal', failedUpdates);
cy.reload();
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 => {
const completedIds = completedChallenges.map(challenge => challenge.id);
failedUpdates.forEach(failedUpdate => {
expect(completedIds).to.include(failedUpdate.payload.id);
});
expect(store.get(failedUpdatesKey)).to.be.empty;
});
});
});