-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests that check for behaviors of expertise command
- Loading branch information
1 parent
809a237
commit 1d53aae
Showing
4 changed files
with
213 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { describe, it, expect, vi, beforeEach } from 'vitest' | ||
import { handler } from '../commands/setExpertise.mjs' | ||
import * as utils from '../utils.mjs' | ||
import * as inquirer from '@inquirer/prompts' | ||
import chalk from 'chalk' | ||
|
||
vi.mock('../utils.mjs') | ||
vi.mock('@inquirer/prompts') | ||
vi.mock('chalk', () => ({ | ||
default: { | ||
blue: vi.fn((str) => str), | ||
yellow: vi.fn((str) => str), | ||
green: vi.fn((str) => str), | ||
red: vi.fn((str) => str), | ||
}, | ||
})) | ||
|
||
describe('setExpertise command', () => { | ||
beforeEach(() => { | ||
vi.resetAllMocks() | ||
vi.mocked(utils.readConfig).mockReturnValue({}) | ||
vi.mocked(utils.writeConfig).mockResolvedValue(undefined) | ||
}) | ||
|
||
it('should set expertise levels for languages and frameworks', async () => { | ||
vi.mocked(inquirer.confirm) | ||
.mockResolvedValueOnce(true) // JavaScript | ||
.mockResolvedValueOnce(true) // React | ||
.mockResolvedValueOnce(false) // Angular | ||
.mockResolvedValueOnce(false) // Vue.js | ||
.mockResolvedValueOnce(false) // Express | ||
.mockResolvedValueOnce(false) // Node.js | ||
.mockResolvedValueOnce(false) // Python | ||
|
||
vi.mocked(inquirer.select) | ||
.mockResolvedValueOnce('intermediate') // JavaScript | ||
.mockResolvedValueOnce('expert') // React | ||
|
||
await handler() | ||
|
||
expect(utils.writeConfig).toHaveBeenCalledWith({ | ||
userExpertise: { | ||
JavaScript: 'intermediate', | ||
React: 'expert', | ||
}, | ||
}) | ||
|
||
expect(chalk.green).toHaveBeenCalledWith('Expertise levels have been successfully set and saved!') | ||
}) | ||
|
||
it('should handle when user has no experience in any language', async () => { | ||
vi.mocked(inquirer.confirm).mockResolvedValue(false) | ||
|
||
await handler() | ||
|
||
expect(utils.writeConfig).toHaveBeenCalledWith({ userExpertise: {} }) | ||
expect(chalk.green).toHaveBeenCalledWith('Expertise levels have been successfully set and saved!') | ||
}) | ||
|
||
it('should handle errors during the process', async () => { | ||
const mockError = new Error('Test error') | ||
vi.mocked(utils.readConfig).mockImplementation(() => { throw mockError }) | ||
|
||
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}) | ||
|
||
await handler() | ||
|
||
expect(consoleErrorSpy).toHaveBeenCalledWith( | ||
'Error setting user expertise levels:', | ||
mockError | ||
) | ||
}) | ||
|
||
it('should display welcome messages', async () => { | ||
vi.mocked(inquirer.confirm).mockResolvedValue(false) | ||
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {}) | ||
|
||
await handler() | ||
|
||
expect(consoleLogSpy).toHaveBeenCalledWith('Welcome to the expertise assessment questionnaire!') | ||
expect(consoleLogSpy).toHaveBeenCalledWith('Please answer the following questions about your programming expertise.') | ||
}) | ||
}) |