Skip to content

Commit

Permalink
Updated some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PrashamTrivedi committed Sep 13, 2024
1 parent f1abbf8 commit 9ade56d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
6 changes: 4 additions & 2 deletions _tests_/setup.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ describe("Setup Command Tests", () => {

it("writes config file with provided values", () => {
const parser = yargsSetup.command({command, describe: commandDescribe, builder, handler})
parser.parse("setup --apiKey test-key --model gpt-4 --analysisDir /custom/dir")
parser.parse("setup --apiKey test-key --model gpt-4 --analysisDir /custom/dir --anthropicApiKey anthropic-key --geminiApiKey gemini-key")

expect(fs.writeFileSync).toHaveBeenCalledWith(
mockConfigFile,
JSON.stringify({
OPENAI_API_KEY: 'test-key',
DEFAULT_OPENAI_MODEL: 'gpt-4',
ANALYSIS_DIR: '/custom/dir'
ANALYSIS_DIR: '/custom/dir',
ANTHROPIC_API_KEY: 'anthropic-key',
GEMINI_API_KEY: 'gemini-key'
})
)
})
Expand Down
42 changes: 37 additions & 5 deletions _tests_/updateConfig.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ describe('updateConfig', () => {
const mockConfigData = {
OPENAI_API_KEY: 'old-api-key',
DEFAULT_OPENAI_MODEL: 'old-model',
ANALYSIS_DIR: 'old-analysis-dir'
ANALYSIS_DIR: 'old-analysis-dir',
ANTHROPIC_API_KEY: 'old-anthropic-key',
GEMINI_API_KEY: 'old-gemini-key'
}

beforeEach(() => {
Expand All @@ -28,7 +30,7 @@ describe('updateConfig', () => {
vi.clearAllMocks()
})

it('should update API key when provided', () => {
it('should update OpenAI API key when provided', () => {
const argv = { apiKey: 'new-api-key', _: [], $0: '' }
handler(argv)

Expand All @@ -38,7 +40,7 @@ describe('updateConfig', () => {
)
})

it('should update model when provided', () => {
it('should update OpenAI model when provided', () => {
const argv = { model: 'new-model', _: [], $0: '' }
handler(argv)

Expand All @@ -58,16 +60,46 @@ describe('updateConfig', () => {
)
})

it('should update Anthropic API key when provided', () => {
const argv = { anthropicApiKey: 'new-anthropic-key', _: [], $0: '' }
handler(argv)

expect(fs.writeFileSync).toHaveBeenCalledWith(
mockConfigPath,
JSON.stringify({ ...mockConfigData, ANTHROPIC_API_KEY: 'new-anthropic-key' })
)
})

it('should update Gemini API key when provided', () => {
const argv = { geminiApiKey: 'new-gemini-key', _: [], $0: '' }
handler(argv)

expect(fs.writeFileSync).toHaveBeenCalledWith(
mockConfigPath,
JSON.stringify({ ...mockConfigData, GEMINI_API_KEY: 'new-gemini-key' })
)
})

it('should update multiple settings when provided', () => {
const argv = { apiKey: 'new-api-key', model: 'new-model', analysisDir: 'new-analysis-dir', _: [], $0: '' }
const argv = {
apiKey: 'new-api-key',
model: 'new-model',
analysisDir: 'new-analysis-dir',
anthropicApiKey: 'new-anthropic-key',
geminiApiKey: 'new-gemini-key',
_: [],
$0: ''
}
handler(argv)

expect(fs.writeFileSync).toHaveBeenCalledWith(
mockConfigPath,
JSON.stringify({
OPENAI_API_KEY: 'new-api-key',
DEFAULT_OPENAI_MODEL: 'new-model',
ANALYSIS_DIR: 'new-analysis-dir'
ANALYSIS_DIR: 'new-analysis-dir',
ANTHROPIC_API_KEY: 'new-anthropic-key',
GEMINI_API_KEY: 'new-gemini-key'
})
)
})
Expand Down

0 comments on commit 9ade56d

Please sign in to comment.