Skip to content

Commit

Permalink
[Fixes #167484590] implementing feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
raymond42 committed Aug 13, 2019
1 parent e4a56d6 commit 301d266
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ SECRET_KEY=
SENDGRID_API_KEY=
EMAIL_SENDER=
APP_URL=
CLOUDINARY_SECRET_KEY=
CLOUDINARY_API_KEY=
CLOUDINARY_NAME=
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "rm -rf build && babel -d ./build ./src -s",
"start": "npm run build && node ./build/index.js",
"pretest": "cross-env NODE_ENV=test npm run down && NODE_ENV=test npm run migrate && NODE_ENV=test npm run seed",
"test": "cross-env NODE_ENV=test nyc --reporter=text mocha --require @babel/register --require @babel/polyfill ./src/tests/*.js --timeout 5000 --exit",
"test": "cross-env NODE_ENV=test nyc --reporter=text mocha --require @babel/register --require @babel/polyfill ./src/tests/*.js --timeout 10000 --exit",
"down": "cross-env NODE_ENV=test sequelize db:migrate:undo",
"migrate": "cross-env NODE_ENV=test sequelize db:migrate",
"seed": "sequelize db:seed:all"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { User } from '../sequelize/models';

config();
cloudinary.config({
cloud_name: process.env.cloudinaryName,
api_key: process.env.cloudinaryApiKey,
api_secret: process.env.cloudinarySecretKey,
cloud_name: process.env.CLOUDINARY_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_SECRET_KEY,
});

/**
Expand All @@ -20,16 +20,16 @@ class Profile {
* @returns {object} return object containing user profile
*/
static async user(req, res) {
const { userName } = req.params;
const userName = req.params.username;
try {
const userfound = await User.findOne({ where: { userName } });
if (!userfound) {
return res.status(404).json({
message: `profile for ${userName} not found`,
message: `Profile for ${userName} not found`,
});
}
res.status(200).json({
message: 'successfully retrieved a user profile',
message: 'Successfully retrieved a user profile',
data: {
userName: userfound.userName,
bio: userfound.bio,
Expand Down Expand Up @@ -68,7 +68,7 @@ class Profile {
const usernamefound = await User.findOne({ where: { userName: inputUsername } });
if (usernamefound) {
return res.status(409).json({
message: 'sorry! the profile username taken, try another one'
message: 'Sorry! The profile username taken, try another one'
});
}
}
Expand Down Expand Up @@ -97,7 +97,7 @@ class Profile {
upadatedAt: updateProfile[1].upadatedAt,
};
res.status(200).json({
message: 'successfully updated the profile',
message: 'Successfully updated the profile',
data: newProfile,
});
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/editProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const canEditProfile = async (req, res, next) => {

if (trueUsername !== suggestedUsername) {
return res.status(403).send({
error: 'sorry! you can not edit the profile that is not yours'
error: 'Sorry! You cannot edit the profile that is not yours'
});
}
next();
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default {
const { error } = Joi.validate(req.body, profileSchema, options);
if (error) {
return res.status(400).json({
error: error.details[0].message
error: error.details[0].message.replace(/\\|(")/g, '')
});
}
next();
Expand Down
4 changes: 2 additions & 2 deletions src/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import connectmultiparty from 'connect-multiparty';
import Validation from '../middleware/validation';
import UserAuth from '../controllers/userController';
import verifyToken from '../middleware/verifyToken';
import Profile from '../controllers/profile';
import Profile from '../controllers/profileController';
import canEditProfile from '../middleware/editProfile';

const router = express.Router();

const connectMulti = connectmultiparty();

router.post('/api/v1/users', Validation.signupValidation, UserAuth.signup);
router.get('/api/v1/profiles/:userName', Profile.user);
router.get('/api/v1/profiles/:username', Profile.user);
router.put('/api/v1/profiles/:username', [verifyToken, connectMulti, canEditProfile, Validation.profileValidation, Validation.imageValidation], Profile.editProfile);
router.post('/api/v1/send-email', Validation.emailValidation, UserAuth.emailSender);
router.post('/api/v1/reset-password/:token', verifyToken, Validation.passwordValidation, UserAuth.resetPassword);
Expand Down
6 changes: 3 additions & 3 deletions src/tests/userprofile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('GET /api/v1/profiles', () => {
expect(res).have.status(200);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'data');
expect(res.body.message).to.deep.equal('successfully retrieved a user profile');
expect(res.body.message).to.deep.equal('Successfully retrieved a user profile');
expect(res.body.data).to.have.keys('userName', 'bio', 'image');
done();
});
Expand All @@ -34,7 +34,7 @@ describe('GET /api/v1/profiles', () => {
expect(res).have.status(404);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message');
expect(res.body.message).to.deep.equal('profile for Kadhutiiii not found');
expect(res.body.message).to.deep.equal('Profile for Kadhutiiii not found');
done();
});
});
Expand All @@ -51,7 +51,7 @@ describe('PUT /api/v1/profiles', () => {
expect(res).have.status(403);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('error');
expect(res.body.error).to.deep.equal('sorry! you can not edit the profile that is not yours');
expect(res.body.error).to.deep.equal('Sorry! You cannot edit the profile that is not yours');
done();
});
});
Expand Down

0 comments on commit 301d266

Please sign in to comment.