11cb0ef41Sopenharmony_ciconst t = require('tap') 21cb0ef41Sopenharmony_ciconst tmock = require('../../fixtures/tmock') 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst webAuthCheckLogin = async () => { 51cb0ef41Sopenharmony_ci return { token: 'otp-token' } 61cb0ef41Sopenharmony_ci} 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst webauth = tmock(t, '{LIB}/utils/web-auth.js', { 91cb0ef41Sopenharmony_ci 'npm-profile': { webAuthCheckLogin }, 101cb0ef41Sopenharmony_ci}) 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst initialUrl = 'https://example.com/auth' 131cb0ef41Sopenharmony_ciconst doneUrl = 'https://example.com/done' 141cb0ef41Sopenharmony_ciconst opts = {} 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_cit.test('returns token on success', async (t) => { 171cb0ef41Sopenharmony_ci const opener = async () => {} 181cb0ef41Sopenharmony_ci const result = await webauth(opener, initialUrl, doneUrl, opts) 191cb0ef41Sopenharmony_ci t.equal(result, 'otp-token') 201cb0ef41Sopenharmony_ci}) 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_cit.test('closes opener when auth check finishes', async (t) => { 231cb0ef41Sopenharmony_ci const opener = (_url, emitter) => { 241cb0ef41Sopenharmony_ci return new Promise((resolve, reject) => { 251cb0ef41Sopenharmony_ci // the only way to finish this promise is to emit aboter on the emitter 261cb0ef41Sopenharmony_ci emitter.addListener('abort', () => { 271cb0ef41Sopenharmony_ci resolve() 281cb0ef41Sopenharmony_ci }) 291cb0ef41Sopenharmony_ci }) 301cb0ef41Sopenharmony_ci } 311cb0ef41Sopenharmony_ci const result = await webauth(opener, initialUrl, doneUrl, opts) 321cb0ef41Sopenharmony_ci t.equal(result, 'otp-token') 331cb0ef41Sopenharmony_ci}) 34