Skip to content

Commit

Permalink
remove version from the state tree since it never changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jebeck committed Feb 11, 2016
1 parent 5d205c5 commit ac4252e
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 98 deletions.
6 changes: 0 additions & 6 deletions docs/state/StateTreeGlossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@ Since the Tidepool Uploader is a Chrome App that runs *outside* of the browser e

To ensure the highest possible standards of data quality, it is very important for us at Tidepool to prevent uploaders that have been succeeded by newer versions from uploading to the Tidepool cloud. To this end, we have implemented an "info" endpoint on our data ingestion API that responds with (among other things) the minimum version of the Tidepool Uploader that the data ingestion API will accept data from.

#### `version`

*The property `version` encodes the current version of the uploader in [semver](http://semver.org/).*

While we use semver at Tidepool, the Chrome Store does not support patch-level version increments, so the minimum - and typical - version number increase that will appear in the Tidepool Uploader is a minor version bump. As a way of distinguishing major releases, on occasion we will choose an arbitrary increase of the minor version number - e.g., skipping from 0.122.0 to 0.150.0 for a major feature release in 0.150.0.

#### `working`

*The `working` property is an object with a small handful of keys that record the app's current state with respect to certain asynchronous actions.*
Expand Down
1 change: 0 additions & 1 deletion lib/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ export default connect(
os: state.os,
page: state.page,
targetUsersForUpload: state.targetUsersForUpload,
version: state.version,
unsupported: state.unsupported,
uploadIsInProgress: state.working.uploading,
uploadsByUser: state.uploadsByUser,
Expand Down
4 changes: 2 additions & 2 deletions lib/containers/root/Root.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import configureStore from '../../redux/store/configureStore';
import App from '../App';
import DevTools from '../../components/DevTools';

const { store, api } = configureStore();
const { api, store, version } = configureStore();

export default class Root extends Component {
render() {
return (
<Provider store={store}>
<div className='DevTools-container'>
<App api={api} />
<App api={api} version={version} />
<div className='DevTools'>
<DevTools store={store} />
</div>
Expand Down
4 changes: 2 additions & 2 deletions lib/containers/root/Root.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import configureStore from '../../redux/store/configureStore';

import App from '../App';

const { store, api } = configureStore();
const { api, store, version } = configureStore();

export default class Root extends Component {
render() {
return (
<Provider store={store}>
<App api={api} />
<App api={api} version={version} />
</Provider>
);
}
Expand Down
13 changes: 7 additions & 6 deletions lib/redux/actions/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ let daysForCareLink = null;

export function doAppInit(config, servicesToInit) {
return (dispatch, getState) => {
dispatch(syncActions.setVersion(config.version));
services = servicesToInit;
versionInfo.semver = config.version;
versionInfo.name = config.namedVersion;
Expand Down Expand Up @@ -191,7 +190,8 @@ export function doLogout() {
export function doCareLinkUpload(deviceKey, creds, utc) {
return (dispatch, getState) => {
const { api, carelink } = services;
const { devices, targetTimezones, uploadTargetUser, version } = getState();
const version = versionInfo.semver;
const { devices, targetTimezones, uploadTargetUser } = getState();

const targetDevice = devices[deviceKey];

Expand Down Expand Up @@ -240,7 +240,8 @@ export function doCareLinkUpload(deviceKey, creds, utc) {
export function doDeviceUpload(driverId, utc) {
return (dispatch, getState) => {
const { device } = services;
const { devices, os, targetTimezones, uploadTargetUser, version } = getState();
const version = versionInfo.semver;
const { devices, os, targetTimezones, uploadTargetUser } = getState();
const targetDevice = _.findWhere(devices, {source: {driverId: driverId}});
dispatch(syncActions.deviceDetectRequest());
const opts = {
Expand Down Expand Up @@ -305,7 +306,7 @@ export function doUpload(deviceKey, opts, utc) {
return (dispatch, getState) => {
dispatch(syncActions.versionCheckRequest());
const { api } = services;
let { version } = getState();
const version = versionInfo.semver;
api.upload.getVersions((err, versions) => {
if (err) {
dispatch(syncActions.versionCheckFailure(err));
Expand Down Expand Up @@ -355,7 +356,7 @@ export function readFile(userId, deviceKey, file, extension) {
return;
}
dispatch(syncActions.choosingFile(userId, deviceKey));
const { version } = getState();
const version = versionInfo.semver;

if (file.name.slice(-extension.length) !== extension) {
let err = new Error(errorText.E_FILE_EXT + extension);
Expand Down Expand Up @@ -396,7 +397,7 @@ export function doVersionCheck() {
return (dispatch, getState) => {
dispatch(syncActions.versionCheckRequest());
const { api } = services;
let { version } = getState();
const version = versionInfo.semver;
api.upload.getVersions((err, versions) => {
if (err) {
return dispatch(syncActions.versionCheckFailure(err));
Expand Down
8 changes: 0 additions & 8 deletions lib/redux/actions/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,6 @@ export function setUploadTargetUser(userId) {
};
}

export function setVersion(version) {
return {
type: actionTypes.SET_VERSION,
payload: { version },
meta: {source: actionSources[actionTypes.SET_VERSION]}
};
}

export function toggleDropdown(previous, actionSource = actionSources[actionTypes.TOGGLE_DROPDOWN]) {
return {
type: actionTypes.TOGGLE_DROPDOWN,
Expand Down
9 changes: 0 additions & 9 deletions lib/redux/reducers/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,6 @@ export function blipUrls(state = {}, action) {
}
}

export function version(state = null, action) {
switch (action.type) {
case actionTypes.SET_VERSION:
return action.payload.version;
default:
return state;
}
}

function checkingVersion(state = false, action) {
switch (action.type) {
case actionTypes.VERSION_CHECK_FAILURE:
Expand Down
2 changes: 1 addition & 1 deletion lib/redux/store/configureStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ else {

export default function configureStore(initialState) {
const store = finalCreateStore(uploader, initialState);
return { api, store };
return { api, store, version: config.version};
}
60 changes: 28 additions & 32 deletions test/browser/redux/actions/async.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ describe('Asynchronous Actions', () => {
log: _.noop
};
const expectedActions = [
{
type: actionTypes.SET_VERSION,
payload: {version: config.version},
meta: {source: actionSources[actionTypes.SET_VERSION]}
},
{
type: actionTypes.INIT_APP_REQUEST,
meta: {source: actionSources[actionTypes.INIT_APP_REQUEST]}
Expand Down Expand Up @@ -131,7 +126,10 @@ describe('Asynchronous Actions', () => {
meta: {source: actionSources[actionTypes.VERSION_CHECK_SUCCESS]}
}
];
const store = mockStore({version: config.version}, expectedActions, done);
asyncActions.__Rewire__('versionInfo', {
semver: config.version
});
const store = mockStore({}, expectedActions, done);
store.dispatch(asyncActions.doAppInit(config, servicesToInit));
});
});
Expand Down Expand Up @@ -172,11 +170,6 @@ describe('Asynchronous Actions', () => {
log: _.noop
};
const expectedActions = [
{
type: actionTypes.SET_VERSION,
payload: {version: config.version},
meta: {source: actionSources[actionTypes.SET_VERSION]}
},
{
type: actionTypes.INIT_APP_REQUEST,
meta: {source: actionSources[actionTypes.INIT_APP_REQUEST]}
Expand Down Expand Up @@ -233,9 +226,11 @@ describe('Asynchronous Actions', () => {
meta: {source: actionSources[actionTypes.SET_PAGE]}
}
];
asyncActions.__Rewire__('versionInfo', {
semver: config.version
});
const state = {
uploadTargetUser: pwd.user.userid,
version: config.version
uploadTargetUser: pwd.user.userid
};
const store = mockStore(state, expectedActions, done);
store.dispatch(asyncActions.doAppInit(config, servicesToInit));
Expand Down Expand Up @@ -269,11 +264,6 @@ describe('Asynchronous Actions', () => {
log: _.noop
};
const expectedActions = [
{
type: actionTypes.SET_VERSION,
payload: {version: '0.100.0'},
meta: {source: actionSources[actionTypes.SET_VERSION]}
},
{
type: actionTypes.INIT_APP_REQUEST,
meta: {source: actionSources[actionTypes.INIT_APP_REQUEST]}
Expand All @@ -295,6 +285,9 @@ describe('Asynchronous Actions', () => {
meta: {source: actionSources[actionTypes.INIT_APP_FAILURE]}
}
];
asyncActions.__Rewire__('versionInfo', {
semver: config.version
});
const store = mockStore({}, expectedActions, done);
store.dispatch(asyncActions.doAppInit(config, servicesToInit));
});
Expand Down Expand Up @@ -441,9 +434,7 @@ describe('Asynchronous Actions', () => {
describe('doUpload [upload aborted b/c version check failed]', () => {
it('should dispatch VERSION_CHECK_REQUEST, VERSION_CHECK_FAILURE, UPLOAD_ABORTED', (done) => {
const requiredVersion = '0.99.0';
const initialState = {
version: '0.50.0'
};
const currentVersion = '0.50.0';
asyncActions.__Rewire__('services', {
api: {
upload: {
Expand All @@ -459,7 +450,7 @@ describe('Asynchronous Actions', () => {
{
type: actionTypes.VERSION_CHECK_FAILURE,
error: true,
payload: new UnsupportedError(initialState.version, requiredVersion),
payload: new UnsupportedError(currentVersion, requiredVersion),
meta: {
source: actionSources[actionTypes.VERSION_CHECK_FAILURE],
metric: {
Expand All @@ -475,15 +466,17 @@ describe('Asynchronous Actions', () => {
meta: {source: actionSources[actionTypes.UPLOAD_ABORTED]}
}
];
const store = mockStore(initialState, expectedActions, done);
asyncActions.__Rewire__('versionInfo', {
semver: currentVersion
});
const store = mockStore({}, expectedActions, done);
store.dispatch(asyncActions.doUpload());
});
});

describe('doUpload [upload aborted b/c another upload already in progress]', () => {
it('should dispatch VERSION_CHECK_REQUEST, VERSION_CHECK_SUCCESS, UPLOAD_ABORTED', (done) => {
const initialState = {
version: '0.100.0',
working: {uploading: true}
};
asyncActions.__Rewire__('services', {
Expand All @@ -509,6 +502,9 @@ describe('Asynchronous Actions', () => {
meta: {source: actionSources[actionTypes.UPLOAD_ABORTED]}
}
];
asyncActions.__Rewire__('versionInfo', {
semver: '0.100.0'
});
const store = mockStore(initialState, expectedActions, done);
store.dispatch(asyncActions.doUpload());
});
Expand Down Expand Up @@ -1538,10 +1534,10 @@ describe('Asynchronous Actions', () => {
}
}
});
const state = {
version: currentVersion
};
const store = mockStore(state, expectedActions, done);
asyncActions.__Rewire__('versionInfo', {
semver: currentVersion
});
const store = mockStore({}, expectedActions, done);
store.dispatch(asyncActions.doVersionCheck());
});
});
Expand All @@ -1566,10 +1562,10 @@ describe('Asynchronous Actions', () => {
}
}
});
const state = {
version: currentVersion
};
const store = mockStore(state, expectedActions, done);
asyncActions.__Rewire__('versionInfo', {
semver: currentVersion
});
const store = mockStore({}, expectedActions, done);
store.dispatch(asyncActions.doVersionCheck());
});
});
Expand Down
18 changes: 0 additions & 18 deletions test/browser/redux/actions/sync.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,24 +278,6 @@ describe('Synchronous Actions', () => {
});
});

describe('setVersion', () => {
const VERSION = '0.100.0';
it('should be an FSA', () => {
let action = syncActions.setVersion(VERSION);

expect(isFSA(action)).to.be.true;
});

it('should create an action to set the uploader version', () => {
const expectedAction = {
type: actionTypes.SET_VERSION,
payload: {version: VERSION},
meta: {source: actionSources[actionTypes.SET_VERSION]}
};
expect(syncActions.setVersion(VERSION)).to.deep.equal(expectedAction);
});
});

describe('toggleDropdown', () => {
const DROPDOWN_PREVIOUS_STATE = true;
it('should be an FSA', () => {
Expand Down
13 changes: 0 additions & 13 deletions test/browser/redux/reducers/misc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,6 @@ describe('misc reducers', () => {
});
});

describe('version', () => {
it('should return the initial state', () => {
expect(misc.version(undefined, {})).to.be.null;
});

it('should handle SET_VERSION', () => {
expect(misc.version(undefined, {
type: actionTypes.SET_VERSION,
payload: {version: '0.100.0'}
})).to.deep.equal('0.100.0');
});
});

describe('working', () => {
it('should return the initial state', () => {
expect(misc.working(undefined, {})).to.deep.equal({
Expand Down

0 comments on commit ac4252e

Please sign in to comment.