-
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
9 changed files
with
125 additions
and
16 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
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
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,15 @@ | ||
/** | ||
* @name userResponse | ||
* @param {Object} res express response object | ||
* @param {Number} code status code to return | ||
* @param {Object} user object with response details | ||
* @param {Object} token strings | ||
* @returns {JSON} JSON response with status and response information | ||
*/ | ||
const userResponse = (res, code, user, token) => { | ||
delete user.dataValues.password; | ||
return token | ||
? res.status(code).json({ user, token }) | ||
: res.status(code).json({ user }); | ||
}; | ||
export default userResponse; |
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 |
---|---|---|
|
@@ -22,4 +22,6 @@ route.patch( | |
Profiles.update | ||
); | ||
|
||
route.get('/:id', Profiles.view); | ||
|
||
export default route; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import * as update from './update.test'; | ||
import * as view from './view.test'; | ||
|
||
export default update; | ||
export { update, view }; |
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,47 @@ | ||
import chai, { expect } from 'chai'; | ||
import chaiHttp from 'chai-http'; | ||
import { config } from 'dotenv'; | ||
import sinon from 'sinon'; | ||
import app from '../../server'; | ||
import Profiles from '../../server/controllers/Profiles'; | ||
|
||
const { view } = Profiles; | ||
|
||
config(); | ||
|
||
chai.use(chaiHttp); | ||
|
||
const baseUrl = process.env.BASE_URL; | ||
|
||
describe('GET Profile', () => { | ||
context('when a user checks their profile', () => { | ||
it(' returns the user profile', async () => { | ||
const response = await chai.request(app).get(`${baseUrl}/profiles/1`); | ||
expect(response).to.have.status(200); | ||
}); | ||
}); | ||
|
||
context('when a user checks another profile that does not exist', () => { | ||
it('returns a not found error', async () => { | ||
const response = await chai.request(app).get(`${baseUrl}/profiles/90000`); | ||
expect(response).to.have.status(404); | ||
}); | ||
}); | ||
|
||
context('when the database is unable to query the user table ', () => { | ||
it('will throw a server error', async () => { | ||
const stubfunc = { view }; | ||
const sandbox = sinon.createSandbox(); | ||
sandbox.stub(stubfunc, 'view').rejects(new Error('Server Error')); | ||
|
||
const next = sinon.spy(); | ||
const res = { | ||
status: () => ({ | ||
json: next | ||
}) | ||
}; | ||
await view({}, res); | ||
sinon.assert.calledOnce(next); | ||
}); | ||
}); | ||
}); |