mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-26 17:16:11 -05:00
fix bug, updating session request retry code per rschamp's feedback
This commit is contained in:
parent
69e519286d
commit
d53fe43241
3 changed files with 8 additions and 8 deletions
|
@ -64,6 +64,6 @@ module.exports.requestSessionWithRetry = (resolve, reject, retriesLeft, totalDel
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.requestSessionOnce = (resolve, reject) => (
|
module.exports.requestSession = (resolve, reject) => (
|
||||||
module.exports.requestSessionWithRetry(resolve, reject, 0, 0)
|
module.exports.requestSessionWithRetry(resolve, reject, 0, 0)
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const keyMirror = require('keymirror');
|
const keyMirror = require('keymirror');
|
||||||
const defaults = require('lodash.defaults');
|
const defaults = require('lodash.defaults');
|
||||||
|
|
||||||
const sessionLib = require('../lib/session');
|
const {requestSession, requestSessionWithRetry} = require('../lib/session');
|
||||||
const messageCountActions = require('./message-count.js');
|
const messageCountActions = require('./message-count.js');
|
||||||
const permissionsActions = require('./permissions.js');
|
const permissionsActions = require('./permissions.js');
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ const handleSessionResponse = (dispatch, body) => {
|
||||||
module.exports.refreshSession = () => (dispatch => {
|
module.exports.refreshSession = () => (dispatch => {
|
||||||
dispatch(module.exports.setStatus(module.exports.Status.FETCHING));
|
dispatch(module.exports.setStatus(module.exports.Status.FETCHING));
|
||||||
return new Promise((resolve, reject) => (
|
return new Promise((resolve, reject) => (
|
||||||
sessionLib.requestSessionOnce(resolve, reject).then(body => {
|
requestSession(resolve, reject).then(body => {
|
||||||
handleSessionResponse(dispatch, body);
|
handleSessionResponse(dispatch, body);
|
||||||
}, err => {
|
}, err => {
|
||||||
dispatch(module.exports.setSessionError(err));
|
dispatch(module.exports.setSessionError(err));
|
||||||
|
@ -111,7 +111,7 @@ module.exports.refreshSession = () => (dispatch => {
|
||||||
module.exports.refreshSessionWithRetry = () => (dispatch => {
|
module.exports.refreshSessionWithRetry = () => (dispatch => {
|
||||||
dispatch(module.exports.setStatus(module.exports.Status.FETCHING));
|
dispatch(module.exports.setStatus(module.exports.Status.FETCHING));
|
||||||
return new Promise((resolve, reject) => (
|
return new Promise((resolve, reject) => (
|
||||||
sessionLib.requestSessionWithRetry(4, resolve, reject)
|
requestSessionWithRetry(resolve, reject, 4, 7500)
|
||||||
)).then(body => {
|
)).then(body => {
|
||||||
handleSessionResponse(dispatch, body);
|
handleSessionResponse(dispatch, body);
|
||||||
}, err => {
|
}, err => {
|
||||||
|
|
|
@ -43,10 +43,10 @@ describe('session library', () => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('requestSessionOnce can call api 1 time, when session found', done => {
|
test('requestSession can call api 1 time, when session found', done => {
|
||||||
whichMockAPIRequest = sessionYesUser;
|
whichMockAPIRequest = sessionYesUser;
|
||||||
new Promise((resolve, reject) => { // eslint-disable-line no-undef
|
new Promise((resolve, reject) => { // eslint-disable-line no-undef
|
||||||
sessionLib.requestSessionOnce(resolve, reject);
|
sessionLib.requestSession(resolve, reject);
|
||||||
}).then(body => {
|
}).then(body => {
|
||||||
expect(sessionYesUser).toHaveBeenCalledTimes(1);
|
expect(sessionYesUser).toHaveBeenCalledTimes(1);
|
||||||
expect(body).toEqual({user: {username: 'test_username'}});
|
expect(body).toEqual({user: {username: 'test_username'}});
|
||||||
|
@ -54,10 +54,10 @@ describe('session library', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('requestSessionOnce can call api 1 time, when session not found', done => {
|
test('requestSession can call api 1 time, when session not found', done => {
|
||||||
whichMockAPIRequest = sessionNoUser;
|
whichMockAPIRequest = sessionNoUser;
|
||||||
new Promise((resolve, reject) => { // eslint-disable-line no-undef
|
new Promise((resolve, reject) => { // eslint-disable-line no-undef
|
||||||
sessionLib.requestSessionOnce(resolve, reject);
|
sessionLib.requestSession(resolve, reject);
|
||||||
}).then(body => {
|
}).then(body => {
|
||||||
expect(sessionNoUser).toHaveBeenCalledTimes(1);
|
expect(sessionNoUser).toHaveBeenCalledTimes(1);
|
||||||
expect(body).toEqual({});
|
expect(body).toEqual({});
|
||||||
|
|
Loading…
Reference in a new issue