Skip to content

Add prefs changetimeout (issue #99) #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

rrgodhorus
Copy link

Requirements

  • Set session timeout to be a configurable pref

Description of the Change

Added 'changetimeout' pref which currently accepts session as timeout type and time in seconds.

Benefits

Session timeout is no longer a hard-coded value

Possible Drawbacks

Applicable Issues

@rrgodhorus
Copy link
Author

@prasadtalasila Sir I haven't written the tests for this yet, however I was able to run it properly and it seemed to work fine (for now)...The cli-prefs.json file is also getting properly updated

@rrgodhorus
Copy link
Author

Also I've used 'timeouttype' instead of 'type' because type is already being used to denote the server type

@prasadtalasila
Copy link
Member

@mukkachaitanya please review this PR.

Copy link
Collaborator

@mukkachaitanya mukkachaitanya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks great. However, there are some minor changes and comment. Please have a look at them @rrgodhorus and sir, @prasadtalasila.

const { type, time } = changeTimeoutEvent.details;
const supportedTimeoutTypes = Object.keys(defaultPrefs.timeouts);
if (!supportedTimeoutTypes.includes(type)) {
console.log('DEbug');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this debug log.

@@ -79,6 +79,26 @@ const validateLogger = (changeLoggerEvent) => {
return changeLoggerEvent;
};

const validateChangeTimeout = (changeTimeoutEvent) => {
const { type, time } = changeTimeoutEvent.details;
const supportedTimeoutTypes = Object.keys(defaultPrefs.timeouts);
Copy link
Collaborator

@mukkachaitanya mukkachaitanya Feb 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use lodash 's function .keys() to have uniformity across the project for such functionality.

},
};
}
if (!time || !validator.isInt(time) || !(parseInt(time, 10) > 0)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good check for the timeout to be positive 👍

Copy link
Collaborator

@mukkachaitanya mukkachaitanya Feb 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also maybe you can consider using the options field of the validator. So the whole statement reduces to

if(!time || !validator.isInt(time, { gt: '0' }){
  ...
}

'cliPrefs',
{
timeouts: {
session: +time,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though this conversion of string to integer works well in most cases, it's debatable. We need to consider if we want to use this conversion or use parseInt() instead.

A good discussion regarding the same here and a table here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay,I'll change it to parseInt() then ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used + because it is used in line 65, maxSize: +details.maxSize

// const SECONDS = 60;
// const MINUTES = 60;
// const HOURS = 2;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments can be removed.

@@ -10,6 +10,7 @@ const eventForShowPref = (changePrefEvent) => {
logger_dir: cliPrefs.logger.logDirectory,
logger_location: cliPrefs.logger.logLocation,
logger_blacklist: cliPrefs.logger.blacklist,
timeouts_session: cliPrefs.timeouts.session,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to decouple the model and output for prefs. What do you think, sir @prasadtalasila?
Well, it's not of concern with regard to this PR, can go in another one later.

@@ -27,6 +27,8 @@ const addTo = (program) => {
.option('--lang <lang>', 'Change language')
.option('--maxsize <size>', 'Change logger file maxsize')
.option('--blacklist <keyword>', 'Add keyword to logger blacklist')
.option('--timeouttype <type>', 'Timeout type ( session ) ')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An option of the form --timeout-type would be preferred. Caporal does support such options, see here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've fixed this too

@codecov
Copy link

codecov bot commented Feb 15, 2019

Codecov Report

Merging #122 into dev will decrease coverage by 7.32%.
The diff coverage is 33.92%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #122      +/-   ##
==========================================
- Coverage   99.28%   91.95%   -7.33%     
==========================================
  Files          24       24              
  Lines         695      746      +51     
==========================================
- Hits          690      686       -4     
- Misses          5       60      +55
Flag Coverage Δ
#integration 89.67% <33.92%> (-4.57%) ⬇️
#unit 72.25% <32.14%> (-27.03%) ⬇️
Impacted Files Coverage Δ
lib/controller/prefs.js 100% <ø> (ø) ⬆️
lib/utils/command-validator.js 100% <100%> (ø) ⬆️
lib/utils/preference-manager.js 98.63% <100%> (-1.37%) ⬇️
lib/cli/input/prefs.js 76.92% <14.28%> (-23.08%) ⬇️
lib/cli/output/prefs.js 80.43% <20%> (-19.57%) ⬇️
lib/controller/validate/prefs.js 86.44% <20%> (-13.56%) ⬇️
lib/cli/input/prefsprompt.js 92.85% <28.57%> (-7.15%) ⬇️
lib/model/prefs.js 88.57% <42.85%> (-11.43%) ⬇️
index.js 0% <0%> (-100%) ⬇️
lib/controller/validate/eval.js 63.15% <0%> (-36.85%) ⬇️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b0534f8...dfe378a. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants