Skip to content
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

Merged
merged 1 commit into from
Mar 31, 2017
Merged

Testing with mocha #20

merged 1 commit into from
Mar 31, 2017

Conversation

ghost
Copy link

@ghost ghost commented Mar 16, 2017

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

  • Create a .env file on the root folder of this project with the following content
MONGODB_SERVICE_HOST=
MONGODB_TEST_DATABASE=
MONGODB_USER=
MONGODB_PASSWORD=
  • Fill the corresponding values
  • Execute npm run test
  • All tests should pass

Related PRs

N/A

TODOs

  • Review

Migrations

No

Thank you!

@ghost ghost requested review from EddSuarez, jac1013 and handmilkingsoftware March 16, 2017 22:11
Copy link
Author

@ghost ghost left a 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",
Copy link
Author

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 ?

Copy link
Member

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

Copy link
Author

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);
Copy link
Author

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);
Copy link
Author

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

Copy link
Member

@jac1013 jac1013 Mar 16, 2017

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);
Copy link
Author

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

Copy link
Member

@jac1013 jac1013 Mar 16, 2017

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)

Copy link
Author

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?

Copy link
Member

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) => {
Copy link
Author

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

Copy link
Member

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'];
Copy link
Author

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,
Copy link
Author

Choose a reason for hiding this comment

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

Default values maybe?

Copy link
Member

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 :)

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good :)

Copy link
Member

@jac1013 jac1013 left a 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);
Copy link
Member

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.

Copy link
Author

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() {
Copy link
Member

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.

Copy link
Author

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

@ghost ghost force-pushed the issue-#1-testing-is-missing branch from 2c2a568 to 4e7e6cc Compare March 16, 2017 23:51
Copy link
Member

@jac1013 jac1013 left a 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": {
Copy link
Member

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) => {
Copy link
Member

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
@jac1013 jac1013 force-pushed the issue-#1-testing-is-missing branch from 54a30f6 to 0130dfa Compare March 31, 2017 20:04
@jac1013
Copy link
Member

jac1013 commented Mar 31, 2017

@evasquez26 I fixed the conflicts here and I'm merging this branch because we need mocha library integration to continue with other tasks.

@jac1013 jac1013 merged commit 78396e9 into master Mar 31, 2017
@jac1013 jac1013 deleted the issue-#1-testing-is-missing branch March 31, 2017 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants