Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
TSLarson committed Sep 30, 2024
1 parent e7e2be8 commit 7933229
Showing 1 changed file with 72 additions and 71 deletions.
143 changes: 72 additions & 71 deletions test/captcha_signup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe('captcha on signup', function () {
});

it('should not show the captcha input', function () {
console.log('banana penguin', this.lock);
expect(h.qInput(this.lock, 'captcha', false)).to.not.be.ok();
});

Expand All @@ -124,75 +125,75 @@ describe('captcha on signup', function () {
});
});

describe('recaptcha', () => {
describe('when the api returns a new challenge', function () {
beforeEach(function (done) {
this.stub = h.stubGetSignupChallenge([recaptchav2Response]);
this.lock = h.displayLock('', lockOpts, done);
});

afterEach(function () {
this.lock.hide();
});

it('should load the captcha script and input', function (done) {
h.waitUntilExists(this.lock, '.auth0-lock-recaptchav2', () => {
expect(h.q(this.lock, '.auth0-lock-recaptchav2')).to.be.ok();
done();
});
});

it('should not submit the form if the captcha is not provided', function (done) {
h.waitForEmailAndPasswordInput(this.lock, () => {
h.signUpWithEmailAndPassword(this.lock, () => {
h.waitUntilErrorExists(this.lock, () => {
expect(h.wasSignUpAttemptedWith({})).not.to.be.ok();
expect(h.hasErrorMessage(this.lock, en.error.login.invalid_recaptcha)).to.be.ok();
done();
});
});
});
});
});

describe('when the challenge api returns required: false', function () {
let notRequiredStub;
beforeEach(function (done) {
notRequiredStub = h.stubGetSignupChallenge({
required: false
});
this.lock = h.displayLock('', lockOpts, done);
});

afterEach(function () {
this.lock.hide();
});

it('should not show the captcha input', function () {
expect(h.q(this.lock, '.auth0-lock-recaptchav2')).to.not.be.ok();
});

describe('when the form submission fails and the transaction starts requiring a challenge', function () {
let challengeStub;
beforeEach(function (done) {
h.assertSignUp((lockID, options, cb) => {
cb(new Error('bad request'));
// We wait 250ms to display errors
setTimeout(done, 260);
});

challengeStub = h.stubGetSignupChallenge(recaptchav2Response);
h.fillEmailInput(this.lock, '[email protected]');
h.fillComplexPassword(this.lock);
h.submitForm(this.lock);
});

it('should call the challenge api again and show the input', function () {
expect(notRequiredStub.calledOnce).to.be.true;
expect(challengeStub.calledOnce).to.be.true;
expect(h.q(this.lock, '.auth0-lock-recaptchav2')).to.be.ok();
});
});
});
});
// describe('recaptcha', () => {
// describe('when the api returns a new challenge', function () {
// beforeEach(function (done) {
// this.stub = h.stubGetSignupChallenge([recaptchav2Response]);
// this.lock = h.displayLock('', lockOpts, done);
// });
//
// afterEach(function () {
// this.lock.hide();
// });
//
// it('should load the captcha script and input', function (done) {
// h.waitUntilExists(this.lock, '.auth0-lock-recaptchav2', () => {
// expect(h.q(this.lock, '.auth0-lock-recaptchav2')).to.be.ok();
// done();
// });
// });
//
// it('should not submit the form if the captcha is not provided', function (done) {
// h.waitForEmailAndPasswordInput(this.lock, () => {
// h.signUpWithEmailAndPassword(this.lock, () => {
// h.waitUntilErrorExists(this.lock, () => {
// expect(h.wasSignUpAttemptedWith({})).not.to.be.ok();
// expect(h.hasErrorMessage(this.lock, en.error.login.invalid_recaptcha)).to.be.ok();
// done();
// });
// });
// });
// });
// });
//
// describe('when the challenge api returns required: false', function () {
// let notRequiredStub;
// beforeEach(function (done) {
// notRequiredStub = h.stubGetSignupChallenge({
// required: false
// });
// this.lock = h.displayLock('', lockOpts, done);
// });
//
// afterEach(function () {
// this.lock.hide();
// });
//
// it('should not show the captcha input', function () {
// expect(h.q(this.lock, '.auth0-lock-recaptchav2')).to.not.be.ok();
// });
//
// describe('when the form submission fails and the transaction starts requiring a challenge', function () {
// let challengeStub;
// beforeEach(function (done) {
// h.assertSignUp((lockID, options, cb) => {
// cb(new Error('bad request'));
// // We wait 250ms to display errors
// setTimeout(done, 260);
// });
//
// challengeStub = h.stubGetSignupChallenge(recaptchav2Response);
// h.fillEmailInput(this.lock, '[email protected]');
// h.fillComplexPassword(this.lock);
// h.submitForm(this.lock);
// });
//
// it('should call the challenge api again and show the input', function () {
// expect(notRequiredStub.calledOnce).to.be.true;
// expect(challengeStub.calledOnce).to.be.true;
// expect(h.q(this.lock, '.auth0-lock-recaptchav2')).to.be.ok();
// });
// });
// });
// });
});

0 comments on commit 7933229

Please sign in to comment.