From 7fae1cf0f77c5b728448e48ca78e09870bb8917b Mon Sep 17 00:00:00 2001 From: Tyrone Wong Date: Tue, 17 Dec 2019 13:28:53 -0500 Subject: [PATCH 1/6] Quick fix to update email duplicate bug --- middlewares/account.middleware.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middlewares/account.middleware.js b/middlewares/account.middleware.js index 38b14170..3c4ef751 100644 --- a/middlewares/account.middleware.js +++ b/middlewares/account.middleware.js @@ -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({ From b8531a0cf0274b9d7bc2d4adc539c4cbd3d9b2e1 Mon Sep 17 00:00:00 2001 From: Tyrone Wong Date: Wed, 18 Dec 2019 04:11:49 -0500 Subject: [PATCH 2/6] Changelog updated --- .github/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 940324bd..6d5f4380 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add accept hacker route - Create changelog + ### Changed - Match npm scripts with dashboard @@ -26,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update pre-acceptance email templates: none hacker status, applied hacker status, account invitation, account confirmation, password reset - Group application enums - Change job interest enums +- Changed the attribute used to check already exisiting emails when updating one's account ### Security From f59b455cd35dae2c381f4eb8a92efcccc995c5fe Mon Sep 17 00:00:00 2001 From: Tyrone Wong Date: Wed, 18 Dec 2019 04:16:13 -0500 Subject: [PATCH 3/6] duplicate email test written --- tests/account.test.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/account.test.js b/tests/account.test.js index 467f4101..723bfb2b 100644 --- a/tests/account.test.js +++ b/tests/account.test.js @@ -293,7 +293,8 @@ describe("PATCH update account", function() { const failUpdatedInfo = { _id: Admin0._id, firstName: "fail", - lastName: "fail" + lastName: "fail", + email: storedAccount1.email }; // fail on authentication @@ -387,6 +388,29 @@ describe("PATCH update account", function() { }); }); }); + + // fail due to attempt to update account email to one that already exists in DB + 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() { From 7b4d1e3b3c28405362d8578471c8e39d245ea431 Mon Sep 17 00:00:00 2001 From: Loreina Chew Date: Wed, 18 Dec 2019 23:10:55 -0500 Subject: [PATCH 4/6] update changelog --- .github/CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 79382c40..e68eed45 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -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] + +### Changed + +- Changed 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 @@ -16,7 +22,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add accept hacker route - Create changelog - ### Changed - Match npm scripts with dashboard @@ -27,7 +32,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update pre-acceptance email templates: none hacker status, applied hacker status, account invitation, account confirmation, password reset - Group application enums - Change job interest enums -- Changed the attribute used to check already exisiting emails when updating one's account ### Fixed From fbdb6570b2cf47999ec138e5884a812f4d96f48a Mon Sep 17 00:00:00 2001 From: Loreina Chew Date: Thu, 19 Dec 2019 18:02:58 -0500 Subject: [PATCH 5/6] update changelog to use fixed --- .github/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index e68eed45..7a253d96 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -7,9 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -### Changed +### Fixed -- Changed the attribute used to check already exisiting emails when updating one's account +- 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 From 3cc878040c80cb84c9a01d9dc7f2a1a77cf8ed0d Mon Sep 17 00:00:00 2001 From: Tyrone Wong Date: Mon, 23 Dec 2019 13:42:59 -0500 Subject: [PATCH 6/6] added test tweak to verify successful modification of email in account --- tests/account.test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/account.test.js b/tests/account.test.js index 723bfb2b..ca456296 100644 --- a/tests/account.test.js +++ b/tests/account.test.js @@ -287,7 +287,8 @@ describe("PATCH update account", function() { const updatedInfo = { _id: teamHackerAccount0._id, firstName: "new", - lastName: "name" + lastName: "name", + email: "newUpdatedEmail@mail.com" }; const failUpdatedInfo = { @@ -359,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(); }); }); @@ -390,7 +392,7 @@ describe("PATCH update account", function() { }); // fail due to attempt to update account email to one that already exists in DB - it("should FAIL to update email to one that already exists", function (done) { + it("should FAIL to update email to one that already exists", function(done) { util.auth.login(agent, Admin0, (error) => { if (error) { agent.close(); @@ -400,7 +402,7 @@ describe("PATCH update account", function() { .patch(`/api/account/${failUpdatedInfo._id}`) .type("application/json") .send(failUpdatedInfo) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(409); res.should.be.json; res.body.should.have.property("message");