Skip to content

Commit fd08de9

Browse files
authored
fix: add confirmationType to confirmation token, and filter by type when returning invites (#681)
* fix: add confirmationType to confirmation token, and filter by type when returning invites * fix: fix failing test
1 parent bdc1497 commit fd08de9

File tree

7 files changed

+40
-19
lines changed

7 files changed

+40
-19
lines changed

constants/general.constant.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ const HACKER_STATUSES = [
2828
// This date is Jan 6, 2020 00:00:00 GMT -0500
2929
const APPLICATION_CLOSE_TIME = 1578286800000;
3030

31+
const CONFIRMATION_TYPE_INVITE = "Invite";
32+
const CONFIRMATION_TYPE_ORGANIC = "Organic";
33+
const CONFIRMATION_TYPES = [
34+
CONFIRMATION_TYPE_INVITE,
35+
CONFIRMATION_TYPE_ORGANIC
36+
];
37+
3138
const TRAVEL_STATUS_NONE = "None"; // Hacker has not been offered compensation for travelling
3239
const TRAVEL_STATUS_BUS = "Bus"; // Hacker is taking bus to hackathon
33-
const TRAVEL_STATUS_POLICY = "Policy"; // Hacker has been offer some reimbursement, but we are waiting for hacker to accept travel policy first
40+
const TRAVEL_STATUS_POLICY = "Policy"; // Hacker has been offer some reimbursement, but we are waiting for hacker to accept travel policy first
3441
const TRAVEL_STATUS_OFFERED = "Offered"; // Hacker has been offered some amount of compensation for travelling, but we have not verified their reciepts yet
3542
const TRAVEL_STATUS_VALID = "Valid"; // Hacker has been offered some amount of compensation for travelling and have uploaded reciepts which we have confirmed to be an approprate amount
3643
const TRAVEL_STATUS_INVALID = "Invalid"; // Hacker has been offered some amount of compensation for travelling but have uploaded reciepts which we have confirmed to be an inapproprate amount
@@ -213,5 +220,8 @@ module.exports = {
213220
CACHE_KEY_STATS: CACHE_KEY_STATS,
214221
MAX_TEAM_SIZE: MAX_TEAM_SIZE,
215222
WEEK_OF: WEEK_OF,
216-
SAMPLE_DIET_RESTRICTIONS: SAMPLE_DIET_RESTRICTIONS
223+
SAMPLE_DIET_RESTRICTIONS: SAMPLE_DIET_RESTRICTIONS,
224+
CONFIRMATION_TYPES: CONFIRMATION_TYPES,
225+
CONFIRMATION_TYPE_INVITE: CONFIRMATION_TYPE_INVITE,
226+
CONFIRMATION_TYPE_ORGANIC: CONFIRMATION_TYPE_ORGANIC
217227
};

middlewares/account.middleware.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const Middleware = {
1616
};
1717

1818
const Constants = {
19-
Error: require("../constants/error.constant")
19+
Error: require("../constants/error.constant"),
20+
General: require("../constants/general.constant")
2021
};
2122

2223
/**
@@ -212,7 +213,8 @@ async function inviteAccount(req, res, next) {
212213
const accountType = req.body.accountType;
213214
const confirmationObj = await Services.AccountConfirmation.create(
214215
accountType,
215-
email
216+
email,
217+
Constants.General.CONFIRMATION_TYPE_INVITE
216218
);
217219
const confirmationToken = Services.AccountConfirmation.generateToken(
218220
confirmationObj.id
@@ -248,7 +250,9 @@ async function inviteAccount(req, res, next) {
248250
* @param {(err?)=>void} next
249251
*/
250252
async function getInvites(req, res, next) {
251-
const invites = await Services.AccountConfirmation.find({});
253+
const invites = await Services.AccountConfirmation.find({
254+
confirmationType: Constants.General.CONFIRMATION_TYPE_INVITE
255+
});
252256
req.body.invites = invites;
253257
next();
254258
}

middlewares/auth.middleware.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ async function sendConfirmAccountEmail(req, res, next) {
217217
await Services.AccountConfirmation.create(
218218
Constants.General.HACKER,
219219
account.email,
220+
Constants.General.CONFIRMATION_TYPE_ORGANIC,
220221
account.id
221222
);
222223
const accountConfirmationToken = await Services.AccountConfirmation.findByAccountId(

models/accountConfirmationToken.model.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ const AccountConfirmationSchema = new mongoose.Schema({
1818
email: {
1919
type: String,
2020
required: true
21+
},
22+
confirmationType: {
23+
type: String,
24+
enum: Constants.General.CONFIRMATION_TYPES,
25+
default: Constants.General.CONFIRMATION_TYPE_ORGANIC
2126
}
2227
});
2328

services/accountConfirmation.service.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@ function find(query) {
5656
* Creates Account Confirmation document in the database
5757
* @param {String} type the type of user which to create the token for
5858
* @param {String} email
59+
* @param {"Invite"|"Organic"} confirmationType whether this confirmation token is for an organic acct creation, or an invited account
5960
* @param {ObjectId} accountId optional accountId parameter to link to account, optional when token is being made for not a hacker
6061
* @returns {Promise.<*>}
6162
*/
62-
async function create(type, email, accountId) {
63+
async function create(type, email, confirmationType, accountId) {
6364
//Create new instance of account confirmation
6465
const newAccountToken = AccountConfirmation({
6566
accountType: type,
66-
email: email
67+
email: email,
68+
confirmationType: confirmationType
6769
});
6870
if (accountId !== undefined) {
6971
newAccountToken.accountId = accountId;

tests/account.test.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ const chai = require("chai");
33
const chaiHttp = require("chai-http");
44
chai.use(chaiHttp);
55
const server = require("../app");
6-
const logger = require("../services/logger.service");
76
const Account = require("../models/account.model");
8-
const should = chai.should();
7+
chai.should();
98
const Constants = {
109
Error: require("../constants/error.constant"),
1110
General: require("../constants/general.constant"),
@@ -245,8 +244,8 @@ describe("POST create account", function() {
245244

246245
it("should SUCCEED and create a new account without a phone number", function(done) {
247246
chai.request(server.app)
248-
.post('/api/account')
249-
.type('application/json')
247+
.post("/api/account")
248+
.type("application/json")
250249
.send(noPhoneAccount)
251250
.end(function(err, res) {
252251
res.should.have.status(200);
@@ -265,8 +264,8 @@ describe("POST create account", function() {
265264
JSON.stringify(acc)
266265
);
267266
done();
268-
})
269-
})
267+
});
268+
});
270269
});
271270

272271
describe("POST confirm account", function() {
@@ -708,9 +707,7 @@ describe("GET invites", function() {
708707
);
709708
res.body.should.have.property("data");
710709
res.body.data.should.have.property("invites");
711-
res.body.data.invites.length.should.equal(
712-
util.accountConfirmation.AccountConfirmationTokens.length
713-
);
710+
res.body.data.invites.length.should.equal(1);
714711
done();
715712
});
716713
});

tests/util/accountConfirmation.test.util.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ const HackerConfirmation3 = {
3333
email: Util.Account.unlinkedAccounts.new[0].email
3434
};
3535

36-
const HackerConfirmation4 = {
36+
const InvitedConfirmation1 = {
3737
_id: mongoose.Types.ObjectId(),
3838
accountType: Constants.HACKER,
39-
email: "abcd@efgh.com"
39+
email: "abcd@efgh.com",
40+
confirmationType: Constants.CONFIRMATION_TYPE_INVITE
4041
};
4142

4243
// Using a real ID which is stored but corresponds to another account
@@ -59,7 +60,7 @@ const AccountConfirmationTokens = [
5960
HackerConfirmation,
6061
HackerConfirmation2,
6162
HackerConfirmation3,
62-
HackerConfirmation4
63+
InvitedConfirmation1
6364
];
6465

6566
function store(attributes) {
@@ -100,6 +101,7 @@ module.exports = {
100101
ConfirmationToken: ConfirmationToken,
101102
FakeToken: FakeToken,
102103
AccountConfirmationTokens: AccountConfirmationTokens,
104+
InvitedConfirmation1: InvitedConfirmation1,
103105
storeAll: storeAll,
104106
dropAll: dropAll
105107
};

0 commit comments

Comments
 (0)