Skip to content

Commit

Permalink
Add test for new signup challenge endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TSLarson committed Jul 30, 2024
1 parent de5314d commit 9933a70
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions test/authentication/db-connection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,94 @@ describe('auth0.authentication', function () {
});
});
});

context('dbConnection getSignupChallenge', function () {
context('when the client does not have state', function () {
before(function () {
this.auth0 = new Authentication(this.webAuthSpy, {
domain: 'me.auth0.com',
clientID: '...',
redirectUri: 'http://page.com/callback',
responseType: 'code',
_sendTelemetry: false
});
});

it('should return nothing', function (done) {
this.auth0.dbConnection.getSignupChallenge((err, challenge) => {
expect(err).to.not.be.ok();
expect(challenge).to.not.be.ok();
done();
});
});
});

context('when the client has state', function () {
before(function () {
this.auth0 = new Authentication(this.webAuthSpy, {
domain: 'me.auth0.com',
clientID: '...',
redirectUri: 'http://page.com/callback',
responseType: 'code',
_sendTelemetry: false,
state: '123abc'
});
});

afterEach(function () {
request.post.restore();
});

it('should post state and returns the image/type', function (done) {
sinon.stub(request, 'post').callsFake(function (url) {
expect(url).to.be('https://me.auth0.com/dbconnections/signup/challenge');
return new RequestMock({
body: {
state: '123abc'
},
headers: {
'Content-Type': 'application/json'
},
cb: function (cb) {
cb(null, {
body: {
image: 'svg+yadayada',
type: 'code'
}
});
}
});
});

this.auth0.dbConnection.getSignupChallenge((err, challenge) => {
expect(err).to.not.be.ok();
expect(challenge.image).to.be('svg+yadayada');
expect(challenge.type).to.be('code');
done();
});
});

it('should return the error if network fails', function (done) {
sinon.stub(request, 'post').callsFake(function (url) {
expect(url).to.be('https://me.auth0.com/dbconnections/signup/challenge');
return new RequestMock({
body: {
state: '123abc'
},
headers: {
'Content-Type': 'application/json'
},
cb: function (cb) {
cb(new Error('error error error'));
}
});
});

this.auth0.dbConnection.getSignupChallenge((err, challenge) => {
expect(err.original.message).to.equal('error error error');
done();
});
});
});
});
});

0 comments on commit 9933a70

Please sign in to comment.