Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(testing dbAuth): Add "yes" prompt testing for WebAuthn #10823

Merged
merged 4 commits into from
Jun 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import { getPaths } from '../../../../lib'
import * as dbAuth from '../dbAuth'

vi.mock('listr2', async () => {
const listrImpl = (tasks) => {
const ctx = {}
const listrImpl = (tasks, listrOptions) => {
return {
ctx,
run: async () => {
mockExecutedTaskTitles = []
mockSkippedTaskTitles = []
Expand All @@ -43,12 +45,28 @@ vi.mock('listr2', async () => {
const augmentedTask = {
...task,
newListr: listrImpl,
prompt: () => {},
prompt: async (options) => {
const enquirer = listrOptions?.injectWrapper?.enquirer

if (enquirer) {
if (!Array.isArray(options)) {
options = [{ ...options, name: 'default' }]
} else if (options.length === 1) {
options[0].name = 'default'
}

const response = await enquirer.prompt(options)

if (options.length === 1) {
return response.default
}
}
},
skip: (msg) => {
mockSkippedTaskTitles.push(msg || task.title)
},
}
await task.task({}, augmentedTask)
await task.task(ctx, augmentedTask)

// storing the title after running the task in case the task
// modifies its own title
Expand Down Expand Up @@ -124,10 +142,38 @@ beforeEach(() => {
})

describe('dbAuth handler WebAuthn task title', () => {
it('is correct after prompting', async () => {
it('is correct after prompt answer "Yes"', async () => {
const customEnquirer = new Enquirer({ show: false })
customEnquirer.on('prompt', (prompt) => {
prompt.submit()
if (prompt.state.message.includes('Enable WebAuthn')) {
prompt.on('run', () => {
return prompt.keypress('y')
})
} else {
prompt.submit()
}
})

await dbAuth.handler({
enquirer: customEnquirer,
listr2: { silentRendererCondition: true },
})

expect(mockExecutedTaskTitles[1]).toEqual(
'Querying WebAuthn addition: WebAuthn addition included',
)
})

it('is correct after prompt answer "No"', async () => {
const customEnquirer = new Enquirer({ show: false })
customEnquirer.on('prompt', (prompt) => {
if (prompt.state.message.includes('Enable WebAuthn')) {
prompt.on('run', () => {
return prompt.keypress('N')
})
} else {
prompt.submit()
}
})

await dbAuth.handler({
Expand Down
Loading