Skip to content

Commit

Permalink
Fixes shuffle always on. Adds test
Browse files Browse the repository at this point in the history
  • Loading branch information
zrrrzzt committed Nov 10, 2017
1 parent 6a887b5 commit 20b1eeb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports.getItems = (lang = 'en', shuffle = false) => {
throw new Error('Inventory not found. Try another language input.')
}

const inventory = shuffle ? knuthShuffle(questions) : questions
const inventory = shuffle === true ? knuthShuffle(questions) : questions
return inventory.map((question, i) => Object.assign(question, {choices: choices[question.keyed], num: ++i}))
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "b5-johnson-120-ipip-neo-pi-r",
"description": "Module for returning Big Five Johnson 120 IPIP-NEO-PI-R items",
"version": "1.1.1",
"version": "1.1.2",
"license": "MIT",
"author": {
"name": "Geir Gåsodden",
Expand Down
14 changes: 13 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const test = require('ava')
const pkg = require('../package.json')
const dependencies = pkg.dependencies || false
const devDependencies = pkg.devDependencies || false
const {getInfo, getItems} = require('../')
const { getInfo, getItems } = require('../')

test('basic check', t => {
t.true(true, 'ava works ok')
Expand Down Expand Up @@ -37,6 +37,18 @@ test('it throws error for lang xx', t => {
}
})

test('validation of question ids across languages', t => {
const languages = getInfo().languages
const questions = languages.map(getItems)
const ids = questions.map(qs => qs.map(q => q.id))
ids.reduce((previous, current) => {
if (previous !== false) {
t.deepEqual(previous, current, 'ids match')
}
return current
}, false)
})

test('it returns sorted inventory items', t =>
t.truthy(getItems('en', false), 'sorted items ok')
)
Expand Down

0 comments on commit 20b1eeb

Please sign in to comment.