Skip to content

Commit 395bef4

Browse files
committed
fixed conflicts
2 parents ec20b7b + 8f92e6b commit 395bef4

File tree

9 files changed

+70
-20
lines changed

9 files changed

+70
-20
lines changed

app.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ const notificationRouter = require('./app/routes/notification')
2424
const proposalRouter = require('./app/routes/proposal')
2525
const app = express()
2626
const server = require('http').Server(app)
27-
server.listen(process.env.SOCKET_PORT || 8810)
27+
if (process.env.NODE_ENV !== 'testing') {
28+
server.listen(process.env.SOCKET_PORT || 8810)
29+
}
2830
// WARNING: app.listen(80) will NOT work here!
2931
const io = socket.listen(server)
3032

app/controllers/auth.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ const HttpStatus = require('http-status-codes')
33
class Auth {
44
constructor (UserModel) {
55
this.UserModel = UserModel
6-
this.initBinding()
6+
this.#initBinding()
77
}
88

9-
initBinding () {
9+
// PRIVATE ES6
10+
#initBinding = () => {
1011
this.authenticateUser = this.authenticateUser.bind(this)
1112
this.logout = this.logout.bind(this)
1213
this.logoutAll = this.logoutAll.bind(this)

app/controllers/comment.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ const helper = require('../utils/paginate')
66
class Comment {
77
constructor(CommentModel) {
88
this.CommentModel = CommentModel
9-
this.initBinding()
9+
this.#initBinding()
1010
}
1111

12-
initBinding () {
12+
// PRIVATE ES6
13+
#initBinding = () => {
1314
this.comment = this.comment.bind(this)
1415
this.update = this.update.bind(this)
1516
this.delete = this.delete.bind(this)

app/controllers/notification.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ const ProposalNotifications = require('../models/ProposalNotification')
77

88
class NotificationProvider {
99
constructor(NotificationModel, UserModel, ProposalModel) {
10-
this.initModels(NotificationModel, UserModel, ProposalModel)
11-
this.initBinding()
10+
this.#initModels(NotificationModel, UserModel, ProposalModel)
11+
this.#initBinding()
1212
}
1313

14-
initModels (NotificationModel, UserModel, ProposalModel) {
14+
// PRIVATE ES6
15+
#initModels = (NotificationModel, UserModel, ProposalModel) => {
1516
this.UserModel = UserModel
1617
this.NotificationModel = NotificationModel
1718
this.ProposalModel = ProposalModel
1819
}
1920

20-
initBinding () {
21+
// PRIVATE ES6
22+
#initBinding = () => {
2123
this.getOrgNotifications = this.getOrgNotifications.bind(this)
2224
this.getUserNotification = this.getUserNotification.bind(this)
2325
this.getProposalNotifications = this.getProposalNotifications.bind(this)

app/controllers/user.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class UserController extends Notification {
158158
'Forgot password!',
159159
'Password successfully updated!',
160160
TAGS.UPDATE)
161-
notificationHelper.addToNotificationForUser(id, res, newNotif, next)
161+
await notificationHelper.addToNotificationForUser(id, res, newNotif, next)
162162
return res.status(HttpStatus.OK).json({ updated: true })
163163
} else {
164164
res.status(HttpStatus.BAD_REQUEST).json({ error: 'Token expired' })
@@ -215,7 +215,7 @@ class UserController extends Notification {
215215
'Account successfully activated!',
216216
TAGS.ACTIVATE
217217
)
218-
notificationHelper.addToNotificationForUser(user._id, res, newNotif, next)
218+
await notificationHelper.addToNotificationForUser(user._id, res, newNotif, next)
219219
return res.status(HttpStatus.OK).json({ msg: 'Succesfully activated!' })
220220
}
221221
} catch (Error) {
@@ -299,7 +299,7 @@ class UserController extends Notification {
299299
`${req.user.name.firstName} started following you!`,
300300
TAGS.FOLLOWER
301301
)
302-
notificationHelper.addToNotificationForUser(user._id, res, newNotif, next)
302+
await notificationHelper.addToNotificationForUser(user._id, res, newNotif, next)
303303
const userData = await this.UserModel.findById(req.user._id)
304304
.populate('followings', ['name.firstName', 'name.lastName', 'info.about.designation', '_id', 'isAdmin'])
305305
.populate('followers', ['name.firstName', 'name.lastName', 'info.about.designation', '_id', 'isAdmin'])

app/models/Proposal.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const proposalSchema = new Schema(
77
type: String,
88
required: true
99
},
10+
organization: {
11+
type: String
12+
},
1013
content: {
1114
type: String,
1215
required: true

test/organisation.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ describe('POST /org/', () => {
108108
.set('Authorization', `Bearer ${token}`)
109109
.send(testOrg)
110110
.expect(HttpStatus.CREATED)
111-
orgId = response.body.org._id
111+
orgId = response.body.orgData._id
112112
/** DB must be changed **/
113-
const org = await Organization.findById(response.body.org._id)
113+
const org = await Organization.findById(response.body.orgData._id)
114114
expect(org).not.toBeNull()
115115

116116
/** Check the response **/
117117
expect(response.body).toMatchObject({
118-
org: {
118+
orgData: {
119119
isArchived: false,
120120
_id: `${orgId}`,
121121
name: `${testOrg.name}`,

test/proposal.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const app = require('../app')
1+
const app = require('../app').app
22
const mongoose = require('mongoose')
33
const jwt = require('jsonwebtoken')
44
const HttpStatus = require('http-status-codes')
@@ -195,3 +195,12 @@ test('Should return the proposal by the given Id', async (done) => {
195195

196196
done()
197197
})
198+
199+
afterAll(async () => {
200+
// avoid jest open handle error
201+
await new Promise((resolve) => setTimeout(() => resolve(), 500))
202+
// close server
203+
await server.close()
204+
// Closing the DB connection allows Jest to exit successfully.
205+
await mongoose.connection.close()
206+
})

test/user.test.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,38 @@ test('Should not get profile for unauthenticated user', async () => {
185185
.expect(HttpStatus.UNAUTHORIZED)
186186
})
187187

188+
/** Should update user profile */
189+
test('Should update profile or authenticated user', async () => {
190+
await request(app)
191+
.patch('/user/me')
192+
.set('Authorization', `Bearer ${testUser.tokens[0].token}`)
193+
.send({
194+
email: 'updated@example.com'
195+
})
196+
.expect(HttpStatus.OK)
197+
})
198+
199+
/** Should fail to make updates that are not allowed to user profile */
200+
test('Should be able to make only allowed updates to authenticated user', async () => {
201+
await request(app)
202+
.patch('/user/me')
203+
.set('Authorization', `Bearer ${testUser.tokens[0].token}`)
204+
.send({
205+
gender: 'Male'
206+
})
207+
.expect(HttpStatus.BAD_REQUEST)
208+
})
209+
210+
/** Should Fail updating profile of unauthenticate user */
211+
test('Should not update profile or unauthenticated user', async () => {
212+
await request(app)
213+
.patch('/user/me')
214+
.send({
215+
email: 'updated@example.com'
216+
})
217+
.expect(HttpStatus.UNAUTHORIZED)
218+
})
219+
188220
/** Delete authenticated user profile */
189221
test('Should delete profile of authenticated user', async () => {
190222
await request(app)
@@ -209,7 +241,7 @@ test('Should not delete profile of unauthenticated user', async () => {
209241
/** Forgot password request **/
210242
test('Should send the request to change the password ', async () => {
211243
const response = await request(app)
212-
.post('/user/password_reset')
244+
.patch('/user/password_reset/request')
213245
.send({
214246
email: `${testUser.email}`
215247
})
@@ -221,7 +253,7 @@ test('Should send the request to change the password ', async () => {
221253
/* Password update */
222254
test('Should update the password ', async () => {
223255
await request(app)
224-
.post(`/user/password_reset/${passwordToken}`)
256+
.patch(`/user/password_reset/${passwordToken}`)
225257
.send({
226258
password: 'newPassword',
227259
id: testUserId
@@ -243,7 +275,7 @@ test('Should activate the account ', async (done) => {
243275
/* Get invite link */
244276
test('Should generate an invite link and send', async () => {
245277
const response = await request(app)
246-
.get('/user/invite')
278+
.get('/user/invite?role=user')
247279
.set('Authorization', `Bearer ${testUser.tokens[0].token}`)
248280
.send()
249281
.expect(HttpStatus.OK)
@@ -258,7 +290,7 @@ test('Should validate the invite link token ', async () => {
258290
await request(app)
259291
.get(`/user/invite/${inviteToken}`)
260292
.send()
261-
.expect(HttpStatus.OK)
293+
.expect(HttpStatus.MOVED_TEMPORARILY)
262294
})
263295

264296
/* Logout the user */

0 commit comments

Comments
 (0)