-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
9,246 additions
and
9,581 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
### Node ### | ||
# Logs | ||
src/logs/app.log | ||
src/logs/app*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import chai from 'chai'; | ||
import chaiHttp from 'chai-http'; | ||
import sinon from 'sinon'; | ||
import Sinonchai from 'sinon-chai'; | ||
import app from '../index'; | ||
import JWTService from '../services/jwt.service'; | ||
import UserController from '../controllers/user.controller'; | ||
|
||
chai.use(Sinonchai); | ||
chai.use(chaiHttp); | ||
chai.should(); | ||
|
||
const profileEndpoint = '/api/v1/user/profile'; | ||
let userToken = `Bearer ${JWTService.generateToken({ id: 1, role: 'requester'})}`; | ||
|
||
describe('/RETRIEVE PROFILE', () => { | ||
|
||
it('should allow only logged in users', (done) => { | ||
chai.request(app) | ||
.get(`${profileEndpoint}?rememberMe=yes`) | ||
.set('Authorization', '') | ||
.end((err, res) => { | ||
res.should.have.status(401); | ||
res.body.should.have.property('status').eql('error'); | ||
done(); | ||
}) | ||
}); | ||
|
||
it('should return 200 if profile is retrieved successfully', (done) => { | ||
chai.request(app) | ||
.get(`${profileEndpoint}?rememberMe=yes`) | ||
.set('Authorization', userToken) | ||
.end((err, res) => { | ||
res.should.have.status(200); | ||
res.body.should.have.property('status').eql('success'); | ||
done(); | ||
}) | ||
}); | ||
|
||
it('should return 500 if something goes wrong', (done) => { | ||
const req = { | ||
query: { | ||
rememberMe: 'yes' | ||
}, | ||
headers: { | ||
authorization: userToken | ||
}, | ||
body: { | ||
user: { | ||
id: 3 | ||
} | ||
} | ||
}; | ||
|
||
const res = { | ||
status() {}, | ||
send() {} | ||
}; | ||
|
||
sinon.stub(res, 'status').returnsThis(); | ||
|
||
UserController.retrieveProfile(req, res); | ||
(res.status).should.have.callCount(0); | ||
done(); | ||
}); | ||
|
||
it('should return 400 when rememberMe is set to NO', (done) => { | ||
chai.request(app) | ||
.get(`${profileEndpoint}?rememberMe=no`) | ||
.set('Authorization', userToken) | ||
.end((err, res) => { | ||
res.should.have.status(400); | ||
res.body.should.have.property('status').eql('error'); | ||
done(); | ||
}) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const ratingCalculator = (data) => { | ||
const { facility_id } = data[0]; | ||
const ratingTable = { | ||
facility_id, | ||
ratings: { | ||
'5-stars': 0, | ||
'4-stars': 0, | ||
'3-stars': 0, | ||
'2-stars': 0, | ||
'1-star': 0, | ||
} | ||
}; | ||
|
||
for (let i = 0; i < data.length; i += 1) { | ||
ratingTable.ratings[`${data[i].rating}-stars`] += 1; | ||
} | ||
return ratingTable; | ||
}; | ||
|
||
export default ratingCalculator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters