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

fix isSameDay function #453

Merged
merged 2 commits into from
May 14, 2017
Merged

fix isSameDay function #453

merged 2 commits into from
May 14, 2017

Conversation

varungupta85
Copy link

isSameDay method was returning true if we feed a currentMessage which is created today and an empty diffMessage. That is because moment(undefined) call will initialize the moment object to today's date. I think we were using isValid to make sure that there is a valid createdAt for currentMessage and diffMessage but moment(undefined).isValid() will return true.

I have changed the method to make sure that we have a valid createdAt date for diffMessage and remove the isValid() calls as they will always return true.

Copy link
Collaborator

@cooperka cooperka 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 fix makes sense, it should be tested pretty thoroughly before merging though. We really ought to have unit tests for this repo...

src/utils.js Outdated
let currentCreatedAt = moment(currentMessage.createdAt);
let diffCreatedAt = moment(diffMessage.createdAt);

if (!currentCreatedAt.isValid() || !diffCreatedAt.isValid()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why have both of these checks been removed?

Copy link
Author

Choose a reason for hiding this comment

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

I found that isValid returns true for all the cases that this test may be trying to avoid. For e.g. moment(undefined).isValid(), moment(0).isValid(), moment({}).isValid() will all return true. I guess one case where it will return false is for moment(null).isValid(). I will put the check back in.

src/utils.js Outdated
@@ -4,13 +4,13 @@ const DEPRECATION_MESSAGE = 'isSameUser and isSameDay should be imported from th

export function isSameDay(currentMessage = {}, diffMessage = {}) {

if(!diffMessage.createdAt) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: space after if

@varungupta85
Copy link
Author

@cooperka I have made the changes you requested. I am not sure how I can help with the testing. I have tested it on my end but I guess it would be good to know that this change is not breaking anything expected for some other users.

@kfiroo
Copy link
Collaborator

kfiroo commented May 14, 2017

@cooperka Hey, You are absolutely right, we must have some tests here.. I promised myself I'd find time for it but couldn't get to it :(

I think the hardest part is to set it up, from there on we could all just add tests as we add/change functionality.

If anyone has some time to set up some basic tests it would be amazing, otherwise I'll get to it at some point :)

@kfiroo kfiroo merged commit aa53c50 into FaridSafi:master May 14, 2017
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