Skip to content

Commit 062471f

Browse files
author
Vladyslav Chygrinov
committed
Success test on ajax password reset
1 parent a9828cc commit 062471f

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

spec/ValidationAndPasswordsReset.spec.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,88 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
910910
});
911911
});
912912

913+
it('should programmatically reset password on ajax request', done => {
914+
const user = new Parse.User();
915+
const emailAdapter = {
916+
sendVerificationEmail: () => Promise.resolve(),
917+
sendPasswordResetEmail: options => {
918+
request({
919+
url: options.link,
920+
followRedirects: false,
921+
}).then(response => {
922+
expect(response.status).toEqual(302);
923+
const re = /http:\/\/localhost:8378\/1\/apps\/choose_password\?token=([a-zA-Z0-9]+)\&id=test\&username=zxcv/;
924+
const match = response.text.match(re);
925+
if (!match) {
926+
fail('should have a token');
927+
done();
928+
return;
929+
}
930+
const token = match[1];
931+
932+
request({
933+
url: 'http://localhost:8378/1/apps/test/request_password_reset',
934+
method: 'POST',
935+
body: { new_password: 'hello', token, username: 'zxcv' },
936+
headers: {
937+
'Content-Type': 'application/x-www-form-urlencoded',
938+
'X-Requested-With': 'XMLHttpRequest',
939+
},
940+
followRedirects: false,
941+
}).then(response => {
942+
console.log('REQUEST RESPONSE');
943+
expect(response.status).toEqual(200);
944+
expect(response.text).toEqual('"Password successfully reset"');
945+
946+
Parse.User.logIn('zxcv', 'hello').then(
947+
function() {
948+
const config = Config.get('test');
949+
config.database.adapter
950+
.find(
951+
'_User',
952+
{ fields: {} },
953+
{ username: 'zxcv' },
954+
{ limit: 1 }
955+
)
956+
.then(results => {
957+
// _perishable_token should be unset after reset password
958+
expect(results.length).toEqual(1);
959+
expect(results[0]['_perishable_token']).toEqual(undefined);
960+
done();
961+
});
962+
},
963+
err => {
964+
jfail(err);
965+
fail('should login with new password');
966+
done();
967+
}
968+
);
969+
});
970+
});
971+
},
972+
sendMail: () => {},
973+
};
974+
reconfigureServer({
975+
appName: 'emailing app',
976+
verifyUserEmails: true,
977+
emailAdapter: emailAdapter,
978+
publicServerURL: 'http://localhost:8378/1',
979+
}).then(() => {
980+
user.setPassword('asdf');
981+
user.setUsername('zxcv');
982+
user.set('email', '[email protected]');
983+
user.signUp().then(() => {
984+
Parse.User.requestPasswordReset('[email protected]', {
985+
error: err => {
986+
jfail(err);
987+
fail('Should not fail');
988+
done();
989+
},
990+
});
991+
});
992+
});
993+
});
994+
913995
it('deletes password reset token on email address change', done => {
914996
reconfigureServer({
915997
appName: 'coolapp',

0 commit comments

Comments
 (0)