Procházet zdrojové kódy

For poll vote route redirect to get poll route

sbkwgh před 8 roky
rodič
revize
0e094ec8fd
2 změnil soubory, kde provedl 7 přidání a 2 odebrání
  1. 1 1
      routes/poll.js
  2. 6 1
      test/poll.js

+ 1 - 1
routes/poll.js

@@ -161,7 +161,7 @@ router.post('/:id', async (req, res) => {
 		await pollVote.setPollQuestion(poll)
 		await pollVote.setPollAnswer(pollAnswer)
 
-		res.json(pollVote.toJSON())
+		res.redirect('/api/v1/poll/' + req.params.id)
 	} catch (e) {
 		if(e instanceof Sequelize.ValidationError) {
 			res.status(400)

+ 6 - 1
test/poll.js

@@ -312,13 +312,18 @@ describe('Poll', () => {
 				res.should.be.json
 				res.should.have.status(200)
 
+				res.body.should.have.property('question', 'Poll question')
+				res.body.should.have.deep.property('PollAnswers')
+
 				let answer = await PollAnswer.findOne({
 					where: {
 						answer: 'poll answer 1'
 					}
 				})
 
-				let vote = await PollVote.findById(res.body.id)
+				let vote = await PollVote.findById(
+					res.body.PollAnswers[0].PollVotes[0].id
+				)
 				vote.should.not.be.null
 				vote.should.have.property('PollQuestionId', id)
 				vote.should.have.property('PollAnswerId', answer.id)