Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Change the attribute used to check already exisiting emails when updating one's account

## [2.0.0](https://github.com/hackmcgill/hackerapi/tree/2.0.0) - 2019-12-17

### Added
Expand Down
2 changes: 1 addition & 1 deletion middlewares/account.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async function updateAccount(req, res, next) {
// TODO: When pull request for parse patch refactor #546 hits, req.body.email will not be present.
if (req.body.email && account.email != req.body.email) {
const existingAccount = await Services.Account.findByEmail(
account.email
req.body.email
);
if (existingAccount) {
return next({
Expand Down
30 changes: 28 additions & 2 deletions tests/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,15 @@ describe("PATCH update account", function() {
const updatedInfo = {
_id: teamHackerAccount0._id,
firstName: "new",
lastName: "name"
lastName: "name",
email: "newUpdatedEmail@mail.com"
};

const failUpdatedInfo = {
_id: Admin0._id,
firstName: "fail",
lastName: "fail"
lastName: "fail",
email: storedAccount1.email
};

// fail on authentication
Expand Down Expand Up @@ -358,6 +360,7 @@ describe("PATCH update account", function() {
// Is this correct matching of data?
res.body.data.firstName.should.equal(updatedInfo.firstName);
res.body.data.lastName.should.equal(updatedInfo.lastName);
res.body.data.email.should.equal(updatedInfo.email);
done();
});
});
Expand Down Expand Up @@ -387,6 +390,29 @@ describe("PATCH update account", function() {
});
});
});

// fail due to attempt to update account email to one that already exists in DB
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a success test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failure test, I'll write a success one!

it("should FAIL to update email to one that already exists", function(done) {
util.auth.login(agent, Admin0, (error) => {
if (error) {
agent.close();
return done(error);
}
agent
.patch(`/api/account/${failUpdatedInfo._id}`)
.type("application/json")
.send(failUpdatedInfo)
.end(function(err, res) {
res.should.have.status(409);
res.should.be.json;
res.body.should.have.property("message");
res.body.message.should.equal(
Constants.Error.ACCOUNT_EMAIL_409_MESSAGE
);
done();
});
});
});
});

describe("POST reset password", function() {
Expand Down