%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
const t = require('tap') let readOpts = null let readResult = null const read = (opts, cb) => { readOpts = opts return cb(null, readResult) } const npmUserValidate = { username: (username) => { if (username === 'invalid') { return new Error('invalid username') } return null }, email: (email) => { if (email.startsWith('invalid')) { return new Error('invalid email') } return null }, } let logMsg = null const readUserInfo = t.mock('../../../lib/utils/read-user-info.js', { read, npmlog: { clearProgress: () => {}, showProgress: () => {}, }, 'proc-log': { warn: (msg) => logMsg = msg, }, 'npm-user-validate': npmUserValidate, }) t.beforeEach(() => { logMsg = null }) t.test('otp', async (t) => { readResult = '1234' t.teardown(() => { readResult = null readOpts = null }) const result = await readUserInfo.otp() t.equal(result, '1234', 'received the otp') }) t.test('password', async (t) => { readResult = 'password' t.teardown(() => { readResult = null readOpts = null }) const result = await readUserInfo.password() t.equal(result, 'password', 'received the password') t.match(readOpts, { silent: true, }, 'got the correct options') }) t.test('username', async (t) => { readResult = 'username' t.teardown(() => { readResult = null readOpts = null }) const result = await readUserInfo.username() t.equal(result, 'username', 'received the username') }) t.test('username - invalid warns and retries', async (t) => { readResult = 'invalid' t.teardown(() => { readResult = null readOpts = null }) const pResult = readUserInfo.username(null, null) // have to swap it to a valid username after execution starts // or it will loop forever readResult = 'valid' const result = await pResult t.equal(result, 'valid', 'received the username') t.equal(logMsg, 'invalid username') }) t.test('email', async (t) => { readResult = 'foo@bar.baz' t.teardown(() => { readResult = null readOpts = null }) const result = await readUserInfo.email() t.equal(result, 'foo@bar.baz', 'received the email') }) t.test('email - invalid warns and retries', async (t) => { readResult = 'invalid@bar.baz' t.teardown(() => { readResult = null readOpts = null }) const pResult = readUserInfo.email(null, null) readResult = 'foo@bar.baz' const result = await pResult t.equal(result, 'foo@bar.baz', 'received the email') t.equal(logMsg, 'invalid email') })