Skip to content

Commit

Permalink
added in testing suite and finished list number
Browse files Browse the repository at this point in the history
  • Loading branch information
jcolemorrison committed Jan 2, 2018
1 parent 9df4630 commit 4d75e0b
Show file tree
Hide file tree
Showing 8 changed files with 1,097 additions and 28 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
src/tpls/
3 changes: 2 additions & 1 deletion .eslintrc
Expand Up @@ -30,6 +30,7 @@
"no-param-reassign": 0,
"no-underscore-dangle": 0,
"no-bitwise": 0,
"prefer-destructuring": 0
"prefer-destructuring": 0,
"no-restricted-globals": 0
}
}
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,3 +1,4 @@
node_modules/
jsconfig.json
.vscode
.vscode
.nyc_output
16 changes: 15 additions & 1 deletion package.json
Expand Up @@ -18,6 +18,16 @@
"node",
"node.js"
],
"scripts": {
"lint": "eslint 'src/**/*.js'",
"start": "node .",
"test": "nyc -r text-summary yarn test:unit",
"test:unit": "NODE_ENV=test mocha --recursive",
"test:unit:report": "nyc -r html report",
"test:unit:run": "mocha -R spec",
"test:unit:watch": "mocha -w -R spec",
"posttest": "yarn lint"
},
"dependencies": {
"aws-sdk": "^2.162.0",
"chalk": "^2.3.0",
Expand All @@ -29,8 +39,12 @@
"jsonlint": "^1.6.2"
},
"devDependencies": {
"chai": "^4.1.2",
"eslint": "^4.9.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.7.0",
"eslint-config-airbnb-base": "^12.1.0"
"mocha": "^4.1.0",
"nyc": "^11.4.1",
"sinon": "^4.1.3"
}
}
26 changes: 23 additions & 3 deletions src/utils/index.js
Expand Up @@ -218,7 +218,8 @@ const buildNumberInquiry = (param, name) => {

if (AllowedValues) {
type = 'list'
inquiry.choices = AllowedValues
inquiry.choices = AllowedValues.map(d => d.toString())
inquiry.default = Default.toString()
}

if (type === 'input' || type === 'password') {
Expand All @@ -240,6 +241,7 @@ const buildNumberInquiry = (param, name) => {
}

inquiry.type = type
inquiry.filter = input => parseFloat(input)

return inquiry
}
Expand Down Expand Up @@ -332,8 +334,26 @@ const buildNumberListInquiry = (param, name) => {
}

if (type === 'checkbox') {
inquiry.choices = AllowedValues
inquiry.filter = input => input //TODO: test and turn into proper comma separated number list
let defaults

if (Default) {
if (!isNaN(parseFloat(Default)) && isFinite(Default)) {
defaults = [parseFloat(Default)]
} else {
defaults = Default && Default.split(',').map(d => parseFloat(d))
}
}

inquiry.choices = AllowedValues.reduce((sum, val) => {
const result = {
name: val,
value: val,
}
if (defaults && defaults.indexOf(val) > -1) result.checked = true
return sum.concat(result)
}, [])

inquiry.filter = input => input.join(',')
}

return inquiry
Expand Down
8 changes: 8 additions & 0 deletions test/.eslintrc
@@ -0,0 +1,8 @@
{
"env": {
"mocha": true
},
"rules": {
"no-unused-expressions": 0
}
}
40 changes: 40 additions & 0 deletions test/utils/index.test.js
@@ -0,0 +1,40 @@
const expect = require('chai').expect
const sinon = require('sinon')
const utils = require('../../src/utils/index.js')

const { buildNumberListInquiry } = utils

describe('Utility Funcitons', () => {
describe('#buildNumberListInquiry()', () => {
describe('-> with AllowedValues', () => {
const ConstraintDescription = 'Only 1 2 or 3'
const Description = 'Choose a number 1 through 3'

it('should set the inquiry with choices equal to AllowedValues and handle Number choices and defaults', () => {
const param = {
Default: 1,
AllowedValues: [1, 2, 3],
ConstraintDescription,
Description,
}
const name = 'ParamNumbersList'
const testCase = {
type: 'checkbox',
name,
message: param.Description,
default: 1,
choices: [
{ name: 1, value: 1, checked: true },
{ name: 2, value: 2 },
{ name: 3, value: 3 },
],
}
const result = buildNumberListInquiry(param, name)
const { filter, ...props } = result

expect(props).to.deep.equal(testCase)
expect(filter([1, 3])).to.equal('1,3')
})
})
})
})

0 comments on commit 4d75e0b

Please sign in to comment.