diff --git a/.travis.yml b/.travis.yml
index 0ccbe30..827059e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,3 +9,4 @@ node_js:
addons:
postgresql: "9.6"
script: ./go test
+
diff --git a/src/browser/components/common/router.js b/src/browser/components/common/router.js
index 61007a9..2e3e44b 100644
--- a/src/browser/components/common/router.js
+++ b/src/browser/components/common/router.js
@@ -11,8 +11,8 @@ import ApprovalPage from '../pages/approval/index'
import Profile from '../pages/profile/index'
import Requests from './requests'
+constructor(props) {
export default class Routes extends Component {
- constructor(props) {
super(props)
this.state = {user: {},
topics: [],
@@ -24,8 +24,7 @@ export default class Routes extends Component {
componentDidMount() {
Promise.all([Requests.get('/api/users/current_user'), Requests.get('/api/topics/'), Requests.get('/api/topics/with-questions')])
.then(([user, topicsResponse, topicsWithQuestionsResponse]) => {
- let currentState = this.state
- this.setState(Object.assign(currentState, {user: user, topics: topicsResponse.topics, topicsWithQuestions: topicsWithQuestionsResponse, message: topicsResponse.message}))
+ this.setState(Object.assign(this.state, { user: user, topics: topicsResponse.topics, topicsWithQuestions: topicsWithQuestionsResponse.topics }))
})
}
diff --git a/src/browser/components/pages/approval/index.js b/src/browser/components/pages/approval/index.js
index 62da1dc..1e8ac43 100644
--- a/src/browser/components/pages/approval/index.js
+++ b/src/browser/components/pages/approval/index.js
@@ -69,7 +69,7 @@ export default class ApprovalPage extends Component {
super(props)
this.inputModules = inputModules
Request.get('/api/topics/')
- .then(topics => this.inputModules[2].options = topics)
+ .then(topics => this.inputModules[2].options = topics.topics)
this.state = {questions: [], id: 0, filter: "All", triggerState: true, currentQuestion: null, inputModules: this.inputModules}
}
diff --git a/src/database/migrations/20170424134531_add-interviews-table.js b/src/database/migrations/20170424134531_add-interviews-table.js
index cf3f8e4..be9fff5 100644
--- a/src/database/migrations/20170424134531_add-interviews-table.js
+++ b/src/database/migrations/20170424134531_add-interviews-table.js
@@ -2,7 +2,7 @@ exports.up = function(knex, Promise) {
return Promise.all([
knex.schema.createTable('interviews', function(table) {
table.integer('user_id')
- table.foreign('user_id').references('users.id')
+ table.foreign('user_id').references('users.id').onDelete('cascade')
table.text('feedback');
}),
])
diff --git a/src/database/queries/questions.js b/src/database/queries/questions.js
index 49429f0..453b340 100644
--- a/src/database/queries/questions.js
+++ b/src/database/queries/questions.js
@@ -9,7 +9,7 @@ const create = ( question ) => {
is_approved : false,
level : question.level,
answer : question.answer,
- game_mode : question.game_mode,
+ // game_mode : question.game_mode,
points : question.points}, 'id')
.then( newQuestionID => {
return knex('hints')
@@ -22,7 +22,7 @@ const create = ( question ) => {
.from('topics')
.whereIn('name',question.topics)
.then( topicIDs => {
- if(topicIDs.length != question.topics.length){
+ if(topicIDs.length === 0 ){
return Promise.reject(new Error('topic not found'))
}
return knex('questionTopics')
@@ -75,7 +75,7 @@ const updatebyID = ( question ) => {
question : question.question,
level : question.level,
answer : question.answer,
- game_mode: question.game_mode,
+ // game_mode: question.game_mode,
points : question.points,
is_approved : question.is_approved},
'id')
@@ -102,6 +102,10 @@ const updatebyID = ( question ) => {
.then(trx.commit)
.catch(trx.rollback)
})
+ .then(function(resp) {
+ return question
+ })
+ .catch(err => {err})
}
const findbyID = ( data ) => {
@@ -111,7 +115,8 @@ const findbyID = ( data ) => {
.where( 'questions.id', data)
.innerJoin('questionTopics','questions.id','questionTopics.question_id')
.innerJoin('topics','questionTopics.topic_id','topics.id')
- .innerJoin('hints','questions.id','hints.question_id').then( results => {
+ .leftJoin('hints','questions.id','hints.question_id')
+ .then( results => {
return hintTopicMiddleWare(results)[0]
})
}
@@ -172,7 +177,8 @@ const deletebyID = ( data ) => {
.del()
}
-function hintTopicMiddleWare(array){
+// function hintTopicMiddleWare(array){
+const hintTopicMiddleWare = (array) => {
var newObj = array.reduce(function(obj,question){
if(obj[question.id]){
if(!obj[question.id].topics.includes(question.topics)){
@@ -184,7 +190,11 @@ function hintTopicMiddleWare(array){
}else{
obj[question.id] = question
question.topics = [question.topics]
- question.hints = [question.hints]
+ if(question.hints === null) {
+ question.hints = []
+ } else {
+ question.hints = [question.hints]
+ }
}
return obj
},{})
@@ -198,6 +208,7 @@ export {
findbyLevel,
findAllQuestions,
updatebyID,
- findbyApproval,
- deletebyID
+ findByApproval,
+ deletebyID,
+ hintTopicMiddleWare
}
diff --git a/src/database/queries/users.js b/src/database/queries/users.js
index f2d70e5..9d5341e 100644
--- a/src/database/queries/users.js
+++ b/src/database/queries/users.js
@@ -14,7 +14,7 @@ const findbyName = ( data ) =>
.then(user => user)
const updatebyGithub = ( data, attributes ) =>
- utilities.update('users', 'github_handle', data.github_handle, attributes)
+ utilities.update('users', 'github_handle', data, attributes)
.then(users => users)
const updatebyName = ( data, attributes ) =>
diff --git a/src/server/routes/questions.js b/src/server/routes/questions.js
index dd95700..1aa5813 100644
--- a/src/server/routes/questions.js
+++ b/src/server/routes/questions.js
@@ -26,7 +26,7 @@ router.get('/approval', (request, response) => {
router.delete('/approval/:id', (request, response) => {
const { id } = request.params
questions.deletebyID( id )
- .then( () => response.json( { 'message': 'deleted' } ) )
+ .then( () => response.json( { 'message': 'deleted', 'id': id } ) )
.catch( err => console.log('err', err) )
})
@@ -39,7 +39,9 @@ router.post('/', (request, response) => {
}
//TODO need to findOrCreate Topics if they don't exist;
questions.create( attributes )
- .then( (question) => response.json( question ) )
+ .then( (questionId) => {
+ response.json( questionId )
+ })
.catch( err => response.status(400).json({error: 'Could not create the question.', errorMsg: err.message, params: attributes}) )
})
@@ -52,9 +54,9 @@ router.put('/approval/:id', (request, response) => {
router.get('/:id', (request, response) => {
const { id } = request.params
- const attributes = request.body
- questions.findbyID( id, attributes )
- .then( question => response.json( question ) )
+ questions.findbyID( parseInt(id) )
+ .then( question => {
+ return response.json( question )} )
.catch( err => console.log('err', err) )
})
diff --git a/src/server/routes/topics.js b/src/server/routes/topics.js
index 76f9166..6668cd5 100644
--- a/src/server/routes/topics.js
+++ b/src/server/routes/topics.js
@@ -5,14 +5,20 @@ const router = express.Router()
router.get('/', (request, response) => {
topics.all()
- .then(results => response.json({message: "Retrieved all topics", topics: results}))
- .catch( err => console.log('err', err) )
+ .then(results => response.json( { message: 'Successfully got back topics', topics: results } ))
+ .catch( err => {
+ console.log('err', err)
+ response.json( { error: err.message } )
+ } )
})
router.get('/with-questions', (request, response) => {
topics.withQuestions()
- .then(results => response.json(results))
- .catch( err => console.log('err', err) )
+ .then(results => response.json({ message: 'Successfully got back topics with questions', topics: results }))
+ .catch( err => {
+ console.log('err', err)
+ response.json( { error: err.message } )
+ } )
})
export default router
diff --git a/test/browser/components/atoms/form-input-test.js b/test/browser/components/atoms/form-input-test.js
new file mode 100644
index 0000000..d3893d2
--- /dev/null
+++ b/test/browser/components/atoms/form-input-test.js
@@ -0,0 +1,19 @@
+import React from 'react'
+import { expect } from 'chai'
+import { shallow, mount } from 'enzyme'
+import { jsdom } from 'jsdom'
+
+import FormInput from '../../../src/browser/components/atoms/form-input/index'
+
+describe('', () => {
+
+ it('should return a div', () => {
+ const wrapper = shallow()
+ expect(wrapper.find('div.uk-form-controls')).to.have.length(1)
+ })
+
+ it('should have an input field inside the main div', () => {
+ const wrapper = mount()
+ expect(wrapper.find('input.form-horizontal-text')).to.have.length(1)
+ })
+})
diff --git a/test/browser/components/atoms/profile-box-test.js b/test/browser/components/atoms/profile-box-test.js
new file mode 100644
index 0000000..c833ff5
--- /dev/null
+++ b/test/browser/components/atoms/profile-box-test.js
@@ -0,0 +1,22 @@
+import React from 'react'
+import { expect } from 'chai'
+import { shallow, mount } from 'enzyme'
+import { jsdom } from 'jsdom'
+
+import ProfileBox from '../../../src/browser/components/atoms/profile-box/index'
+
+describe('', () => {
+
+ it('should return a div', () => {
+ const wrapper = shallow()
+ expect(wrapper.children()).to.have.length(1)
+ })
+
+ it('the child element should be a div', () => {
+ const wrapper = mount()
+ expect(wrapper.find('div.uk-grid-small').childAt(0).type()).to.equal('div')
+ })
+
+
+
+});
diff --git a/test/browser/components/atoms/select-tag-test.js b/test/browser/components/atoms/select-tag-test.js
new file mode 100644
index 0000000..aad8a17
--- /dev/null
+++ b/test/browser/components/atoms/select-tag-test.js
@@ -0,0 +1,48 @@
+import React from 'react'
+import { expect } from 'chai'
+import { shallow, mount } from 'enzyme'
+import { jsdom } from 'jsdom'
+
+import SelectTag from '../../../src/browser/components/atoms/form-select/index'
+
+
+describe('', () => {
+ const label = 'difficulty'
+ const options = ['Javascript', 'SQL', 'http']
+ const value = 'SQL'
+
+ it('should return a div', () => {
+ const wrapper = shallow()
+ expect(wrapper.find('div.uk-margin')).to.have.length(1)
+ })
+
+ context('the outer div should contain two html elements', () => {
+ it('should have a label', () => {
+ const wrapper = mount()
+ expect(wrapper.find('div.uk-margin').childAt(0).type()).to.equal('label')
+ expect(wrapper.props().label).to.equal('difficulty')
+ })
+
+ it('should have a div', () => {
+ const wrapper = mount()
+ expect(wrapper.find('div.uk-margin').childAt(1).type()).to.equal('div')
+ })
+ })
+
+ context('inner divs child should be a select', () => {
+ it('is a selector', () => {
+ const wrapper = mount()
+ expect(wrapper.find('div.uk-form-controls').children().type()).to.equal('select')
+ })
+ it('should display a value', () => {
+ const wrapper = mount()
+ expect(wrapper.props().value).to.equal('SQL')
+ })
+ })
+
+ it('should render N+1