-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marcel Kalveram
committed
May 5, 2019
1 parent
de1b670
commit dcf7ea5
Showing
8 changed files
with
126 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const mongoose = require("mongoose") | ||
const dotenv = require("dotenv") | ||
|
||
/** | ||
* Load environment variables from .env file, where API keys and passwords are configured. | ||
*/ | ||
dotenv.load({ path: ".env" }) | ||
|
||
const connectToMongo = cb => { | ||
mongoose.Promise = global.Promise | ||
mongoose | ||
.connect(process.env.MONGODB_URI || "mongodb://localhost:27017/vlctechhub", { | ||
user: process.env.MONGODB_USER, | ||
pass: process.env.MONGODB_PASS, | ||
}) | ||
.then(cb, err => { | ||
console.error(err) | ||
console.log("%s MongoDB connection error. Please make sure MongoDB is running.", chalk.red("✗")) | ||
process.exit() | ||
}) | ||
} | ||
|
||
module.exports = { | ||
connectToMongo, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,9 @@ | ||
#!/usr/bin/env node | ||
|
||
const mongoose = require("mongoose"); | ||
const dotenv = require("dotenv"); | ||
const notificationsController = require("../controllers/notifications"); | ||
const bootstrap = require("./bootstrap") | ||
const notificationsController = require("../controllers/notifications") | ||
|
||
/** | ||
* Load environment variables from .env file, where API keys and passwords are configured. | ||
*/ | ||
dotenv.load({ path: ".env" }); | ||
|
||
/** | ||
* Connect to MongoDB. | ||
*/ | ||
mongoose.Promise = global.Promise; | ||
mongoose.connect( | ||
process.env.MONGODB_URI || "mongodb://localhost:27017/vlctechhub", | ||
{ | ||
user: process.env.MONGODB_USER, | ||
pass: process.env.MONGODB_PASS | ||
} | ||
); | ||
mongoose.connection.on("error", err => { | ||
console.error(err); | ||
console.log( | ||
"%s MongoDB connection error. Please make sure MongoDB is running.", | ||
chalk.red("✗") | ||
); | ||
process.exit(); | ||
}); | ||
|
||
notificationsController.sendPushNotificationsForType("events"); | ||
notificationsController.sendPushNotificationsForType("jobs"); | ||
bootstrap.connectToMongo(() => { | ||
notificationsController.sendPushNotificationsForType("events") | ||
notificationsController.sendPushNotificationsForType("jobs") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,8 @@ | ||
#!/usr/bin/env node | ||
|
||
const mongoose = require("mongoose") | ||
const dotenv = require("dotenv") | ||
const bootstrap = require("./bootstrap") | ||
const remindersController = require("../controllers/reminders") | ||
|
||
/** | ||
* Load environment variables from .env file, where API keys and passwords are configured. | ||
*/ | ||
dotenv.load({ path: ".env" }) | ||
|
||
/** | ||
* Connect to MongoDB. | ||
*/ | ||
mongoose.Promise = global.Promise | ||
mongoose.connect(process.env.MONGODB_URI || "mongodb://localhost:27017/vlctechhub", { | ||
user: process.env.MONGODB_USER, | ||
pass: process.env.MONGODB_PASS, | ||
}) | ||
mongoose.connection.on("error", err => { | ||
console.error(err) | ||
console.log("%s MongoDB connection error. Please make sure MongoDB is running.", chalk.red("✗")) | ||
process.exit() | ||
bootstrap.connectToMongo(() => { | ||
remindersController.sendRemindersForEventsOnDate(new Date()) | ||
}) | ||
|
||
remindersController.sendRemindersForEventsOnDate(new Date()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const { expect } = require("chai") | ||
const sinon = require("sinon") | ||
|
||
const notificationsController = require("../../controllers/notifications") | ||
const remoteApi = require("../../services/remoteApi") | ||
const pushNotificationsHelper = require("../../services/pushNotifications") | ||
const User = require("../../models/User") | ||
|
||
describe("Test send reminders functions", () => { | ||
let remoteApiStub | ||
let userStub | ||
let pushSpy | ||
before(() => { | ||
remoteApiStub = sinon | ||
.stub(remoteApi, "fetchLatestItemForType") | ||
.resolves({ id: "123", title: "Latest job offer", company: { name: "Apple" } }) | ||
userStub = sinon.stub(User, "getUsersByType").resolves([{ token: "abc" }, { token: "def" }]) | ||
pushSpy = sinon.spy(pushNotificationsHelper, "sendNotifications") | ||
}) | ||
after(() => { | ||
remoteApiStub.restore() | ||
userStub.restore() | ||
pushSpy.restore() | ||
}) | ||
afterEach(() => { | ||
pushSpy.resetHistory() | ||
}) | ||
it("should test the notifications for jobs", done => { | ||
notificationsController.sendPushNotificationsForType("jobs") | ||
setTimeout(function() { | ||
expect(pushSpy.called).to.eq(true) | ||
expect(pushSpy.firstCall.args[0]).to.eql(["abc", "def"]) | ||
expect(pushSpy.firstCall.args[1].title).to.eql("Hay una nueva oferta de trabajo") | ||
expect(pushSpy.firstCall.args[1].message).to.eql("Latest job offer en Apple") | ||
done() | ||
}, 100) | ||
}) | ||
it("should test the notifications for events", done => { | ||
remoteApiStub.resolves({ id: "123", title: "ValenciaJS" }) | ||
notificationsController.sendPushNotificationsForType("events") | ||
setTimeout(function() { | ||
expect(pushSpy.called).to.eq(true) | ||
expect(pushSpy.firstCall.args[0]).to.eql(["abc", "def"]) | ||
expect(pushSpy.firstCall.args[1].title).to.eql("Hay un nuevo evento") | ||
expect(pushSpy.firstCall.args[1].message).to.eql("ValenciaJS") | ||
done() | ||
}, 100) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters