-
Notifications
You must be signed in to change notification settings - Fork 2k
User CRUD API tests #959
User CRUD API tests #959
Conversation
Yay we're almost 10% higher in code coverage!!! :) |
Awesome! We're getting there! :) Great job! |
res.body.message.should.equal('Username field must not be blank'); | ||
}); | ||
|
||
agent.post('/api/auth/forgot') |
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.
What's this extra block?
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.
Good catch, probably a left over from all the tests, I removed it.
a9c4816
to
975fb3b
Compare
@ilanbiala - useful comments as always, thanks for the code review. |
}); | ||
}); | ||
|
||
it('should be able to update own user details', function (done) { |
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.
Try to group functionality/features and use beforeEach
to DRY the user.save code.
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.
the user.save()
part don't need to apply to all tests so we can't just throw that in beforeEach
, and there's no sense to wrap it with any other function as it's anyway just going to get a callback.
I was thinking maybe wrapping the user signing-in in a function but it looks more readable and extensible as is.
@lirantal What specifically doesn't work locally when you test it? |
@ilanbiala the forgot functionality fails due to not being able to send e-mail, so it responds with a 400 error, specifically here: https://github.com/meanjs/mean/blob/master/modules/users/server/controllers/users/users.password.server.controller.js#L87 The tests are written in a way that validates that even after we get a 400 response the database is inspected to confirm there is indeed the reset token etc. When it's failing with that 404, it is failing for not being able to send the email, which if you look at the above controller code then otherwise it just sends the e-mail ok. I think testing the e-mail being sent is beyond the scope of the tests so I don't want to introduce testing emails sent out. |
@lirantal I'm pretty sure it errors because the API keys aren't even set. Have you looked at the error message from it, because Nodemailer doesn't throw an error for not being able to actually send an email, it just follows send and forget if I remember correctly. |
Good to know, I'll try it. |
@ilanbiala even when I comment the |
@lirantal what do you mean comment? You need to provide that is what I'm saying for Nodemailer not to error. What is the specific error you get? |
@ilanbiala ok I understand the confusion now. |
@lirantal that's fine, but we can make sure we don't get an error because of Nodemailer, whether it actually sends or not. What is the specific error you see when you assert those 400s? |
A little hint for email testing, the following is our implementation. We use sinon to mock the function that actually sends the email and verify a callcount for each recipient. Maybe it's useful to you:
|
@ilanbiala "Failure sending email" is the exact error that is being returned, specifically here, by this call: https://github.com/meanjs/mean/blob/master/modules/users/server/controllers/users/users.password.server.controller.js#L87 I believe this assertion is just fine because it tests our API and that everything is ok, the other way the if statement can end there is with success. |
@lirantal I'm referring to this |
@ilanbiala it throws err:
|
@ilanbiala I can workaround the email problem by adding the following options to nodemailer transport: tls: {
rejectUnauthorized: false
} Do you suggest I add it as the default options in |
@lirantal yeah that sounds fine, unless we can get a free certificate and still keep it secure somehow. |
bc21113
to
26b1ee3
Compare
26b1ee3
to
d0e117e
Compare
@ilanbiala even though with the tls config it works fine locally on my machine (probably because I have some mail server configured there), on travis it fails due to:
returned by nodemailer itself. |
c3fcad2
to
af150e1
Compare
@ilanbiala per my previous comment - I'm going to refactor the tests back to assert for a 400 "failed sending tests" issue as it seems that nodemailer is not environment-agnostic and will require some kind of email environment setup to be able to return 200 for tests. Since it is not the purpose of the test to check an email was sent I don't see it as a problem. |
af150e1
to
37db3d3
Compare
37db3d3
to
0017886
Compare
@ilanbiala I reverted back the changes so that we still assert a 400 due to unable to reliably being able to test an email sending option end-to-end. Since we worked out all other issues I'll go ahead and merge this PR once the build is complete so we can have a broader safety net of code coverage for tests. |
Hi guys I am using MEAN stack in my application with AngularJS as my front-end.....my problem is if i forget the password i were enter the user name and submitted, but i got error like "Failure sending email" is there any solution to solve this....I'M new to meanjs... so please help to solve this issue....forgot password page is not working.....thanks... |
@Maniselvam006 You probably did not set up your email preferences: Next time please open an issue, or ask on Gitter. Good luck with meanjs, I hope you will like it ! |
No description provided.