Skip to content

Commit

Permalink
updated join route test
Browse files Browse the repository at this point in the history
updating user in store when joining community
  • Loading branch information
kyletozer committed Oct 2, 2018
1 parent 37f27aa commit 1252595
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
6 changes: 4 additions & 2 deletions routes/api/join.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ module.exports = (req, res, next) => {
user.communities.push(req.body._id)
return user.save()
})
.then(() => {
res.locals = authResponse(true, { status: 204 })
.then(user => user.populate('communities'))
.then(user => {
res.locals = authResponse(true, { status: 200, user })
res.locals.user = user
next()
})
.catch(next)
Expand Down
7 changes: 3 additions & 4 deletions routes/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ module.exports = {
return { ...responseObj, ...data }
},
responseHandler: (req, res) => {
const { locals } = res
res.status(locals.status)
delete locals.status
res.json(locals)
res.status(res.locals.status)
delete res.locals.status
res.json(res.locals)
}
}
4 changes: 2 additions & 2 deletions src/components/Community.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="card community mb-2">
<div class="card-body">
<div v-if="community" class="card-body">
<h5 class="card-title">{{ community.title }}</h5>
<p class="card-text">
{{ community.description | excerpt }} <span class="clickable">Read More</span>
Expand All @@ -23,7 +23,7 @@ export default {
join() {
axios.put(`/api/join/${this.community._id}`, this.community)
.then(res => {
console.log(res)
this.$store.commit('setUser', res.data.user)
})
.catch(err => {
console.log(err.response)
Expand Down
2 changes: 1 addition & 1 deletion src/views/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<hr>
<!-- communities -->
<div class="active-panel" v-show="activePanel === 'communities'">
<div v-if="user.communities && user.communities.length > 0">
<div v-if="user && user.communities && user.communities.length > 0">
<div class="communities">
<div v-for="(community, key) in user.communities" :key="key">
<community :community="community"></community>
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/join-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ describe('"/join" Route', () => {
.put(`/api/join/${community._id}`)
.send(community)
.then(res => {
expect(res).to.have.status(204)
expect(res).to.have.status(200)
expect(res.body).to.have.property('user')
expect(res.body.user).to.have.property('communities')
// expect(res.body.user.communties).to.be.an('array')
// expect(res.body.user.communities[0]).to.have.property('_id')
done()
})
.catch(done)
Expand Down

0 comments on commit 1252595

Please sign in to comment.