Skip to content
This repository has been archived by the owner on May 9, 2021. It is now read-only.

Commit

Permalink
feat(userProfile): implement user profile update
Browse files Browse the repository at this point in the history
- remove backend functionality to upload image(multipart/form-data)

[#161291007]
  • Loading branch information
Andela-Jalil committed Nov 7, 2018
1 parent 1e79e62 commit 3c03a22
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 170 deletions.
110 changes: 0 additions & 110 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"method-override": "^2.3.10",
"methods": "^1.1.2",
"morgan": "^1.9.0",
"multer": "^1.4.1",
"nodemon": "^1.18.5",
"nyc": "^13.1.0",
"passport": "^0.4.0",
Expand Down
18 changes: 11 additions & 7 deletions server/controllers/UsersController.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,17 @@ class UsersController {
'twitterUrl',
];
const updateFields = Object.keys(updateData);
updateFields.forEach((field) => {
if (profileFields.indexOf(field) < 0) {
const error = new Error(`user column '${field}' does not exist`);
error.status = 422;
return next(error);
}
});
try {
updateFields.forEach((field) => {
if (profileFields.indexOf(field) < 0) {
const error = new Error(`user column '${field}' does not exist`);
error.status = 422;
throw error;
}
});
} catch (err) {
return next(err);
}

// function to update the user profile
const updateProfile = async () => {
Expand Down
52 changes: 0 additions & 52 deletions test/server/controllers/UserController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,56 +316,4 @@ describe('Update user profile', () => {
.equal('user not found');
});
});

describe('with image', function uploadImage() {
this.timeout(30000);
const resData = {};
before((done) => {
chai.request(app)
.patch(`/api/v1/users/${userData.id}`)
.set('authorization', userData.token)
.attach('avatar', './mockdata/pngimage.png', 'pngimage.png')
.end((err, res) => {
resData.status = res.status;
resData.body = res.body;
done();
});
});

// check return status and body
it('should return status 200', () => {
resData.status.should.equal(200);
});
it('should update one user profile', () => {
resData.body.status.should.equal('success');
resData.body.message.should
.equal('1 user profile updated successfully');
});
});

describe('with svg image', function uploadImage() {
this.timeout(30000);
const resData = {};
before((done) => {
chai.request(app)
.patch(`/api/v1/users/${userData.id}`)
.set('authorization', userData.token)
.attach('avatar', './mockdata/svgimage.svg', 'svgimage.svg')
.end((err, res) => {
resData.status = res.status;
resData.body = res.body;
done();
});
});

// check return status and body
it('should return status 422', () => {
resData.status.should.equal(422);
});
it('should update one user profile', () => {
resData.body.status.should.equal('failure');
resData.body.errors.message.should
.equal('Only jpg, jpeg and png files allowed');
});
});
});

0 comments on commit 3c03a22

Please sign in to comment.