Skip to content

Commit

Permalink
Merge pull request #9 from KevinAst/next5
Browse files Browse the repository at this point in the history
streamline index.js, complete auth service mock, and misc
  • Loading branch information
KevinAst authored Feb 1, 2019
2 parents 284517d + 260f940 commit 6651551
Show file tree
Hide file tree
Showing 29 changed files with 135 additions and 197 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": ["expo", "plugin:react/recommended"],
"env": {
"browser": true, // 1/25/2019 added this to eliminate complaints about setTimeout() not being defined
},
"rules": {
"react/prop-types": "off", // relax react prop-types validation
"babel/object-curly-spacing": "off", // relax spacing inside braces
Expand Down
14 changes: 0 additions & 14 deletions src/features/diag/index.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/features/diag/logActions/index.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/features/diag/sandbox/index.js

This file was deleted.

83 changes: 63 additions & 20 deletions src/features/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,65 @@
import init from './init';
import views from './views';
import services from './services';
import support from './support';
import diag from './diag';

/**
* The **eatery-nod** application is composed of the following **features**:
*
* - **init**: a collection of **"Initialization Related"** features
* - **views**: a collection of **"UI Related"** features
* - **services**: a collection of **"Service Related"** features _(some of which are "mockable")_
* - **support**: a collection of **"Support Utility"** features
* - **diag**: a collection of **"Diagnostic Related"** features
*/
import device from './init/device/feature';
import auth from './init/auth/feature';

import eateries from './views/eateries/feature';
import discovery from './views/discovery/feature';
import leftNav from './views/leftNav/feature';
import currentView from './views/currentView/feature';

import deviceService from './services/deviceService/feature';

import authService from './services/authService/feature';
import authServiceFirebase from './services/authService/authServiceFirebase/feature';
import authServiceMock from './services/authService/authServiceMock/feature';

import eateryService from './services/eateryService/feature';
import eateryServiceFirebase from './services/eateryService/eateryServiceFirebase/feature';
import eateryServiceMock from './services/eateryService/eateryServiceMock/feature';

import discoveryService from './services/discoveryService/feature';
import discoveryServiceGooglePlaces from './services/discoveryService/discoveryServiceGooglePlaces/feature';
import discoveryServiceMock from './services/discoveryService/discoveryServiceMock/feature';

import bootstrap from './support/bootstrap/feature';
import firebaseInit from './support/firebaseInit/feature';

import logActions from './diag/logActions/feature';
import sandbox from './diag/sandbox/feature';

// accumulate ALL features
// ... see README.md for details
export default [
...init,
...views,
...services,
...support,
...diag,

// ... init
device,
auth,

// ... views
eateries,
discovery,
leftNav,
currentView,

// ... services
deviceService,

authService,
authServiceFirebase,
authServiceMock,

eateryService,
eateryServiceFirebase,
eateryServiceMock,

discoveryService,
discoveryServiceGooglePlaces,
discoveryServiceMock,

// ... support
bootstrap,
firebaseInit,

// ... diag
logActions,
sandbox,
];
2 changes: 0 additions & 2 deletions src/features/init/auth/index.js

This file was deleted.

3 changes: 3 additions & 0 deletions src/features/init/auth/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import _auth from './featureName';
import _authAct from './actions';
import signInFormMeta from './signInFormMeta';
import discloseError from '../../../util/discloseError';
import {toast} from '../../../util/notify';

/**
* Start our authorization process, once the bootstrap initialization process is complete.
Expand Down Expand Up @@ -197,6 +198,7 @@ export const checkEmailVerified = createLogic({

transform({getState, action, fassets}, next, reject) {

toast({ msg:`verifying your email: ${fassets.sel.curUser(getState()).email}` });
// fetch the most up-to-date user
fassets.authService.refreshUser()
.then( user => {
Expand Down Expand Up @@ -225,6 +227,7 @@ export const resendEmailVerification = createLogic({
type: String(_authAct.signIn.resendEmailVerification),

transform({getState, action, fassets}, next) {
toast({ msg:`resending email to: ${fassets.sel.curUser(getState()).email}` });
fassets.authService.resendEmailVerification()
next(action);
},
Expand Down
2 changes: 0 additions & 2 deletions src/features/init/device/index.js

This file was deleted.

14 changes: 0 additions & 14 deletions src/features/init/index.js

This file was deleted.

11 changes: 10 additions & 1 deletion src/features/services/authService/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class User {
// ... unrecognized named parameter
const unknownArgKeys = Object.keys(unknownArgs);
check(unknownArgKeys.length === 0, `unrecognized named parameter(s): ${unknownArgKeys}`);
// ... unrecognized positional parameter (NOTE: when defaulting entire struct, arguents.length is 0)
// ... unrecognized positional parameter (NOTE: when defaulting entire struct, arguments.length is 0)
check(arguments.length === 0 || arguments.length === 1, 'unrecognized positional parameters (only named parameters can be specified)');

// retain supplied state in self
Expand Down Expand Up @@ -119,4 +119,13 @@ export default class User {
};
}

/**
* Clone self into a new User object
*
* @returns {User} the new cloned User object.
*/
clone() {
return new User(this.toStruct());
}

};
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default class AuthServiceFirebase extends AuthServiceAPI {
if (err.code) { // expected condition
err.defineUserMsg('Invalid SignIn credentials.'); // make generic ... do NOT expose err.code to the user
}
else { // unexpected conition
else { // unexpected condition
err.defineAttemptingToMsg('sign in to eatery-nod');
}
return reject(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,36 @@ export default class AuthServiceMock extends AuthServiceAPI {
return new Promise( (resolve, reject) => {

// stimulate various errors with variations in email/pass
if (pass === 'unexpect') { // <<< unexpected condition
if (pass === 'unexpect') { // ... unexpected condition
return reject(
new Error(`***ERROR*** Simulated Unexpected Condition`)
.defineAttemptingToMsg('sign in to eatery-nod')
);
}

if (pass === 'expect') { // <<< expected condition
if (pass === 'expect') { // ... expected condition
return reject(
new Error(`***ERROR*** Invalid Password`) // do NOT expose details to the user (e.g. Invalid Password)
.defineUserMsg('Invalid SignIn credentials.') // keep generic
.defineAttemptingToMsg('sign in to eatery-nod')
);
}

// very simple mock ... sign in the supplied user
// define our mock user
this.currentAppUser = new User({
"name": "MockGuy",
"email": email,
"emailVerified": true,
"pool": "mock"
"name": "MockGuy",
email,
"emailVerified": false,
"pool": "mock"
});

// sign in the supplied user
if (pass === 'unverify') { // ... simulate user unverified
return resolve(this.currentAppUser);
}

// ... all other cases: user is verified
this.currentAppUser.emailVerified = true;
return resolve(this.currentAppUser);

});
Expand All @@ -51,14 +59,9 @@ export default class AuthServiceMock extends AuthServiceAPI {

refreshUser() { // ... see AuthServiceAPI
return new Promise( (resolve, reject) => {

// very simple mock ... sign in the supplied user
this.currentAppUser = new User({
"name": "MockGuy",
"email": email,
"emailVerified": true,
"pool": "mock"
});
// very simple mock ... assume they have now been verified
this.currentAppUser = this.currentAppUser.clone();
this.currentAppUser.emailVerified = true;
return resolve(this.currentAppUser);

});
Expand Down
9 changes: 0 additions & 9 deletions src/features/services/authService/index.js

This file was deleted.

58 changes: 32 additions & 26 deletions src/features/services/deviceService/DeviceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,8 @@ export default class DeviceService {
* Instantiate the DeviceService service object.
*/
constructor() {

// conditionally mock getCurPos(), as directed by featureFlags
if (featureFlags.mockGPS) {

const GlenCarbonIL = {lat: 38.752209, lng: -89.986610};
const defaultLoc = GlenCarbonIL;
const mockLoc = featureFlags.mockGPS.lat ? featureFlags.mockGPS : defaultLoc;

this.getCurPos = () => { // override method with our mock
// console.log(`xx DeviceService.getCurPos() request ... mocked to: `, mockLoc);
return new Promise( (resolve, reject) => {
//setTimeout(() => { // TEMPORARY: for testing delay just a bit

// TEMPORARY: for testing, simulate error condition
// ... NOTE: reject() passes error into .catch(), throw does NOT
// return reject(new Error('Simulated Error in Expo GPS Location acquisition') );

// communicate device location
return resolve(mockLoc);
//}, 10000); // TEMPORARY: for testing delay just a bit
});
};
}

// conditionally mock various service methods, as directed by featureFlags
mock_getCurPos_asNeeded(this);
}


Expand All @@ -64,7 +42,7 @@ export default class DeviceService {
// ... NOTE: reject() passes error into .catch(), throw does NOT
// return reject( new Error('Simulated Error in Expo Font.loadAsync()') );

// load needed custome fonts for NativeBase UI
// load needed custom fonts for NativeBase UI
Font.loadAsync({'Roboto': require('native-base/Fonts/Roboto.ttf'),
'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
})
Expand Down Expand Up @@ -199,4 +177,32 @@ export default class DeviceService {
});
}

};
}


// conditionally mock getCurPos(), as directed by featureFlags
function mock_getCurPos_asNeeded(deviceService) {

if (featureFlags.mockGPS) { // ... if requested by featureFlags

const GlenCarbonIL = {lat: 38.752209, lng: -89.986610};
const defaultLoc = GlenCarbonIL;
const mockLoc = featureFlags.mockGPS.lat ? featureFlags.mockGPS : defaultLoc;

deviceService.getCurPos = () => { // override method with our mock
// console.log(`xx DeviceService.getCurPos() request ... mocked to: `, mockLoc);
return new Promise( (resolve, reject) => {
//setTimeout(() => { // TEMPORARY: for testing delay just a bit

// TEMPORARY: for testing, simulate error condition
// ... NOTE: reject() passes error into .catch(), throw does NOT
// return reject(new Error('Simulated Error in Expo GPS Location acquisition') );

// communicate device location
return resolve(mockLoc);
//}, 10000); // TEMPORARY: for testing delay just a bit
});
};
}

}
2 changes: 0 additions & 2 deletions src/features/services/deviceService/index.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/features/services/discoveryService/index.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/features/services/eateryService/index.js

This file was deleted.

19 changes: 0 additions & 19 deletions src/features/services/index.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/features/support/bootstrap/index.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/features/support/firebaseInit/index.js

This file was deleted.

Loading

0 comments on commit 6651551

Please sign in to comment.