-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing with mocha #20
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leaving down my comments so we can discuss my doubts :)
package.json
Outdated
@@ -10,7 +10,7 @@ | |||
"build": "npm run lint && npm run compile", | |||
"prepublish": "npm run build", | |||
"lint": "eslint src", | |||
"test": "echo \"To be implemented\"", | |||
"test": "MONGODB_SERVICE_HOST=localhost MONGODB_DATABASE=notifications MONGODB_USER= MONGODB_PASSWORD= mocha --compilers js:babel-register -b test/spec/*.spec.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok this obviously needs to be changed. Would I be able to do npm run test -- MY_ENVS=something
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or if you prefer you can add this package https://www.npmjs.com/package/better-npm-run that loads for you a .env file without touching source files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent! Thank you
src/index.js
Outdated
@@ -31,8 +21,7 @@ class Notification { | |||
self.io.sockets[user.id] = socket; | |||
self.sendUnread(user.id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should take out this from here and let the user decide what actions should be taken when doing a check-in
.getAllUnread(userId) | ||
.then((notifications) => { | ||
const sentNotifications = notifications.map((notification) => { | ||
const sentNotification = this.send('unread', notification); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a good idea to have a hard-coded event like unread
here? Or maybe pass it like a parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hard-coded should be fine, if it is used more than once then constant-it somewhere :p.
.getAllUnsent(userId) | ||
.then((notifications) => { | ||
const sentNotifications = notifications.map((notification) => { | ||
const sentNotification = this.send('news', notification); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here for the news
event. Also I think that's a wrong name, news sounds like paper news or something. Should be something like unsent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated, but you used events for this right? I think we should be consistent, if we are using promises we should use promises everywhere (even for tests although in there you should test for promises and callbacks to work)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean socket.io
events?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the only way to handle things in socket.io
then ignore my comment :).
src/index.js
Outdated
data.forEach((notification) => { | ||
self.send('unread', notification); | ||
}); | ||
const notificatonsSent = new Promise((resolve, reject) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added promises but I don't know if this will be the default approach. If I recall correctly we wanted to support both promises
and callbacks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll read the whole code later because there are some things that I understand and I guess that's because of lack of context.
@@ -0,0 +1,20 @@ | |||
const chance = require('chance').Chance(); // eslint-disable-line import/no-extraneous-dependencies | |||
|
|||
const notificationTypes = ['web', 'mobile']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any ideas on any other type of notification?
|
||
const notificationDatabase = new MongoNotificationDatabase(); | ||
databaseConnection.connect({ | ||
host: process.env.MONGODB_SERVICE_HOST, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default values maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say no if you ask me :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this task was related to unit tests (not integration test with a real database), Don't get me wrong, this is good either way we can discuss later about this in our meeting.
Edit: Seeing the issue is not specifying whether is integration tests or unit test, however this issue exist #4
src/index.js
Outdated
constructor(database) { | ||
this.notificationController = new NotificationController(database); | ||
|
||
this.getAllUnread = this.notificationController.getAllUnread.bind(this.notificationController); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why you need to do this, can you explain? Also it seems that is not being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it seems to me that is it not being used either. This had to do when I tried to use the class MongoNotificationDatabase
that had a connection to mongo on the constructor. But that's not there anymore so I should remove this, thank you!
And in fact all of these methods seems unused to me
@@ -4,12 +4,16 @@ import NotificationDatabaseContract from './database'; | |||
import Notification from './mongo-model-example'; | |||
|
|||
class MongoNotificationDatabase extends NotificationDatabaseContract { | |||
constructor() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed, NotificationDatabaseContract
works as an interface, it's only needed if you need to do something in the constructor (which you aren't) so adding the constructor with super doesn't make sense in here IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup you're right. Same comment as before, we were passing the connection parameters on the constructor of this class to open the connection to mongo right away. But that is not being used that way right know
2c2a568
to
4e7e6cc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @evasquez26 just a minor comment for you to remember, let's merge this as we agreed and do the changes for SQLite later.
"compile": "babel src --out-dir dist" | ||
}, | ||
"betterScripts": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a reminder, we won't need this after you change everything to use SQLite @evasquez26
this.notificationController | ||
.update(notification._id, { sent: true }) //eslint-disable-line | ||
.then(updatedNotification => resolve(updatedNotification)) | ||
.catch((err) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.catch(reject)
…stgreSQL Integrated better-npm-run, CR corrections Added .env to ignored files
54a30f6
to
0130dfa
Compare
@evasquez26 I fixed the conflicts here and I'm merging this branch because we need mocha library integration to continue with other tasks. |
Story / Task
#4
What this PR does?
Adds the first set of testing using mocha
Before
We did not have tests
After
We have our first tests now 🎉
How to test / reproduce
.env
file on the root folder of this project with the following contentnpm run test
Related PRs
N/A
TODOs
Migrations
No
Thank you!