Skip to content
39 changes: 39 additions & 0 deletions constants/settings.constant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const APP_NOT_YET_OPEN = {
openTime: new Date(Date.now() + 100000000000),
closeTime: new Date(Date.now() + 10000000000000000),
confirmTime: new Date(Date.now() + 100000000000000000)
};

const APP_OPEN = {
openTime: new Date(Date.now() - 100),
closeTime: new Date(Date.now() + 10000000000),
confirmTime: new Date(Date.now() + 100000000000000)
};

const APP_CLOSED = {
openTime: new Date(Date.now() - 100),
closeTime: new Date(Date.now() - 1000),
confirmTime: new Date(Date.now() + 100000000000000)
};

const CONFIRM_CLOSED = {
openTime: new Date(Date.now() - 10000),
closeTime: new Date(Date.now() - 1000),
confirmTime: new Date(Date.now() - 100)
};

const REMOTE_HACKATHON = {
openTime: new Date(Date.now() - 100),
closeTime: new Date(Date.now() + 10000000000),
confirmTime: new Date(Date.now() + 100000000000000),
isRemote: true
};

// Some utility dates that are used in tests and seed script
module.exports = {
APP_NOT_YET_OPEN: APP_NOT_YET_OPEN,
APP_OPEN: APP_OPEN,
APP_CLOSED: APP_CLOSED,
CONFIRM_CLOSED: CONFIRM_CLOSED,
REMOTE_HACKATHON: REMOTE_HACKATHON
};
6 changes: 3 additions & 3 deletions models/settings.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const mongoose = require("mongoose");
const settings = new mongoose.Schema({
openTime: {
type: Date,
default: 0
default: Date.now() + 2628000000 // One month from now.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it'd be a good idea to have it default to a day before Date.now()?
Only time I can think of were we should be using defaults is for local environment and applications open is probably most useful state for that?

Copy link
Member Author

Choose a reason for hiding this comment

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

I set it 1mo from now for production reasons. I wouldn't want the API to be able to accept applications right away.

Copy link
Member Author

Choose a reason for hiding this comment

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

The other time we use defaults is when you create a new DB for production (which may or may not happen, but it could).

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's fair

},
closeTime: {
type: Date,
default: Date.now() + 31104000000 // Add a year from now.
default: Date.now() + 31540000000 + 2628000000 // One year and 1 month from now.
},
confirmTime: {
type: Date,
default: Date.now() + 31104000000 + 2628000000 // 1 year and 1 month from now.
default: Date.now() + 31540000000 + 2628000000 + 2628000000 // 1 year and 2 months from now.
},
isRemote: {
type: Boolean,
Expand Down
18 changes: 16 additions & 2 deletions seed/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
"use strict";
const Constants = {
Role: require("../constants/role.constant")
Role: require("../constants/role.constant"),
Settings: require("../constants/settings.constant")
};

const Seed = {
Roles: require("./roles.seed")
Roles: require("./roles.seed"),
Settings: require("./settings.seed")
};

const Services = {
env: require("../services/env.service")
};
const path = require("path");

const envLoadResult = Services.env.load(path.join(__dirname, "../.env"));
if (envLoadResult.error) {
Services.log.error(envLoadResult.error);
}

const db = require("../services/database.service");
//connect to db
db.connect(undefined, () => {
Expand All @@ -30,8 +42,10 @@ async function onConnected() {

async function dropAll() {
await Seed.Roles.dropAll();
await Seed.Settings.drop();
}

async function storeAll() {
await Seed.Roles.storeAll(Constants.Role.allRolesArray);
await Seed.Settings.store();
}
9 changes: 0 additions & 9 deletions seed/roles.seed.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
"use strict";
const Role = require("../models/role.model");
const Services = {
env: require("../services/env.service")
};
const path = require("path");

const envLoadResult = Services.env.load(path.join(__dirname, "../.env"));
if (envLoadResult.error) {
Services.log.error(envLoadResult.error);
}

/**
* Drops all elements in Role
Expand Down
22 changes: 22 additions & 0 deletions seed/settings.seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";
const Settings = require("../models/settings.model");

/**
* Drops all elements in Role
*/
function drop() {
return Settings.deleteMany({});
}

/**
* Stores all of the roles in the db
* @param {Settings} setting the setting that we want to seed
*/
function store(setting) {
return Settings.collection.insertOne(new Settings(setting));
}

module.exports = {
store: store,
drop: drop
};
10 changes: 4 additions & 6 deletions tests/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ chai.should();
const util = {
account: require("./util/account.test.util"),
auth: require("./util/auth.test.util"),
settings: require("./util/settings.test.util")
};

const Constants = {
Success: require("../constants/success.constant"),
Error: require("../constants/error.constant")
Error: require("../constants/error.constant"),
Settings: require("../constants/settings.constant")
};

const invalidAccount = util.account.hackerAccounts.stored.noTeam[0];
Expand Down Expand Up @@ -85,8 +85,7 @@ describe("PATCH settings", function() {
agent
.patch(`/api/settings/`)
.type("application/json")
.send(util.settings.settingConfirmClosed)
// does not have password because of to stripped json
.send(Constants.Settings.CONFIRM_CLOSED)
.end(function(err, res) {
res.should.have.status(200);
res.should.be.json;
Expand All @@ -109,8 +108,7 @@ describe("PATCH settings", function() {
agent
.patch(`/api/settings/`)
.type("application/json")
.send(util.settings.settingRemoteHackathon)
// does not have password because of to stripped json
.send(Constants.Settings.REMOTE_HACKATHON)
.end(function(err, res) {
res.should.have.status(200);
res.should.be.json;
Expand Down
45 changes: 6 additions & 39 deletions tests/util/settings.test.util.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,23 @@
const Settings = require("../../models/settings.model");
const logger = require("../../services/logger.service");

const settingApplicationNotYetOpen = {
openTime: new Date(Date.now() + 100000000000),
closeTime: new Date(Date.now() + 10000000000000000),
confirmTime: new Date(Date.now() + 100000000000000000)
};

const settingApplicationOpen = {
openTime: new Date(Date.now() - 100),
closeTime: new Date(Date.now() + 10000000000),
confirmTime: new Date(Date.now() + 100000000000000)
};

const settingApplicationClosed = {
openTime: new Date(Date.now() - 100),
closeTime: new Date(Date.now() - 1000),
confirmTime: new Date(Date.now() + 100000000000000)
};

const settingConfirmClosed = {
openTime: new Date(Date.now() - 10000),
closeTime: new Date(Date.now() - 1000),
confirmTime: new Date(Date.now() - 100)
};

const settingRemoteHackathon = {
openTime: new Date(Date.now() - 100),
closeTime: new Date(Date.now() + 10000000000),
confirmTime: new Date(Date.now() + 100000000000000),
isRemote: true
const Constants = {
Settings: require("../../constants/settings.constant")
};

async function storeAll() {
const toStore = new Settings(settingApplicationOpen);
const toStore = new Settings(Constants.Settings.APP_OPEN);
Settings.collection.insertOne(toStore);
}

async function setApplicationClosed() {
await dropAll();
const toStore = new Settings(settingApplicationClosed);
const toStore = new Settings(Constants.Settings.APP_CLOSED);
Settings.collection.insertOne(toStore);
}

async function setApplicationNotYetOpen() {
await dropAll();
const toStore = new Settings(settingApplicationNotYetOpen);
const toStore = new Settings(Constants.Settings.APP_NOT_YET_OPEN);
Settings.collection.insertOne(toStore);
}

Expand All @@ -64,10 +36,5 @@ module.exports = {
storeAll: storeAll,
dropAll: dropAll,
setApplicationClosed: setApplicationClosed,
setApplicationNotYetOpen: setApplicationNotYetOpen,
settingApplicationNotYetOpen: settingApplicationNotYetOpen,
settingApplicationOpen: settingApplicationOpen,
settingApplicationClosed: settingApplicationClosed,
settingConfirmClosed: settingConfirmClosed,
settingRemoteHackathon: settingRemoteHackathon
setApplicationNotYetOpen: setApplicationNotYetOpen
};