Skip to content

Commit

Permalink
update shell.openExternal to promisified
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Aug 2, 2019
1 parent 0cbd954 commit 8b6460d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/server/lib/gui/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ const _launchNativeAuth = (loginUrl, sendMessage) => {
openExternalAttempted = true

// wrap openExternal here in case `electron.shell` is not available (during tests)
return Promise.fromCallback((cb) => {
shell.openExternal(loginUrl, {}, cb)
return Promise.try(() => {
return shell.openExternal(loginUrl)
})
.catch((err) => {
debug('Error launching native auth: %o', { err })
Expand Down
12 changes: 7 additions & 5 deletions packages/server/test/unit/gui/auth_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,23 @@ describe('lib/gui/auth', function () {
})

it('returns a promise that is fulfilled when openExternal succeeds', function () {
sinon.stub(electron.shell, 'openExternal').callsArg(2)
sinon.stub(electron.shell, 'openExternal').resolves()
const sendWarning = sinon.stub()

return auth._launchNativeAuth(REDIRECT_URL)
return auth._launchNativeAuth(REDIRECT_URL, sendWarning)
.then(() => {
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL, {}, sinon.match.func)
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL)
expect(sendWarning).to.not.be.called
})
})

it('is still fulfilled when openExternal fails, but sendWarning is called', function () {
sinon.stub(electron.shell, 'openExternal').callsArgWith(2, new Error)
sinon.stub(electron.shell, 'openExternal').rejects(new Error)
const sendWarning = sinon.stub()

return auth._launchNativeAuth(REDIRECT_URL, sendWarning)
.then(() => {
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL, {}, sinon.match.func)
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL)
expect(sendWarning).to.be.calledWithMatch('warning', 'AUTH_COULD_NOT_LAUNCH_BROWSER', REDIRECT_URL)
})
})
Expand Down

0 comments on commit 8b6460d

Please sign in to comment.