Tests for reset password flow

This commit is contained in:
Avital Oliver
2012-08-07 20:23:05 -07:00
parent d46a4d7a76
commit 6a3124becb
5 changed files with 93 additions and 2 deletions

View File

@@ -0,0 +1,56 @@
(function () {
var email = Meteor.uuid() + "-intercept@example.com";
var resetPasswordToken;
testAsyncMulti("accounts emails - reset password flow", [
function (test, expect) {
Meteor.createUser({email: email, password: 'foobar'},
expect(function (error) {
test.equal(error, undefined);
}));
},
function (test, expect) {
Meteor.forgotPassword({email: email}, expect(function (error) {
test.equal(error, undefined);
}));
},
function (test, expect) {
Meteor.call("getInterceptedEmails", email, expect(function (error, result) {
test.notEqual(result, undefined);
test.equal(result.length, 1);
var content = result[0];
var match = content.match(
new RegExp(window.location.protocol + "//" +
window.location.host + "/#\\?reset-password/(\\S*)"));
test.isTrue(match);
resetPasswordToken = match[1];
console.log(resetPasswordToken);
}));
},
function (test, expect) {
Meteor.resetPassword(resetPasswordToken, "newPassword", expect(function(error) {
test.isFalse(error);
}));
},
function (test, expect) {
Meteor.logout(expect(function (error) {
test.equal(error, undefined);
test.equal(Meteor.user(), null);
}));
},
function (test, expect) {
Meteor.loginWithPassword(
{email: email}, "newPassword",
expect(function (error) {
test.isFalse(error);
}));
},
function (test, expect) {
Meteor.logout(expect(function (error) {
test.equal(error, undefined);
test.equal(Meteor.user(), null);
}));
}
]);
}) ();

View File

@@ -0,0 +1,26 @@
(function () {
//
// a mechanism to intercept emails sent to addressing including
// the string "intercept", storing them in an array that can then
// be retrieved using the getInterceptedEmails method
//
var oldMeteorMailSend = Meteor.mail.send;
var interceptedEmails = {}; // (email address) -> (array of contents)
Meteor.mail.send = function (email, content) {
if (email.indexOf('intercept') === -1) {
oldMeteorMailSend(email, content);
} else {
if (!interceptedEmails[email])
interceptedEmails[email] = [];
interceptedEmails[email].push(content);
}
};
Meteor.methods({
getInterceptedEmails: function (email) {
return interceptedEmails[email];
}
});
}) ();

View File

@@ -15,4 +15,6 @@ Package.on_test(function(api) {
api.use(['accounts-passwords', 'tinytest', 'test-helpers']);
api.add_files('passwords_tests_setup.js', 'server');
api.add_files('passwords_tests.js', 'client');
api.add_files('email_tests_setup.js', 'server');
api.add_files('email_tests.js', 'client');
});

View File

@@ -131,7 +131,7 @@
// @param options {Object}
// - email: (email)
// @param callback (optional) {Function(error|undefined)}
Meteor.forgotPassword = function(options) {
Meteor.forgotPassword = function(options, callback) {
if (!options.email)
throw new Error("Must pass options.email");
options.baseUrl = window.location.protocol + "//"

View File

@@ -1 +1,8 @@
Meteor.accounts.passwords = {};
Meteor.accounts.passwords = {};
// internal email validation tokens collection. Never published.
Meteor.accounts._emailValidationTokens = new Meteor.Collection(
"accounts._emailValidationTokens",
null /*manager*/,
null /*driver*/,
true /*preventAutopublish*/);