Skip to content

Commit 59122e4

Browse files
committed
fix unit test
1 parent 43af9a7 commit 59122e4

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

cli/src/__tests__/integration/credentials-storage.test.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,37 +155,48 @@ describe('Credentials Storage Integration', () => {
155155
expect(keys[0]).toBe('default')
156156
})
157157

158-
test('should use manicode-dev directory in development environment', () => {
158+
test('should use manicode-test directory in test environment', async () => {
159159
// Restore getConfigDir to use real implementation for this test
160160
mock.restore()
161-
mockModule('@codebuff/common/env', () => {
162-
return {
163-
env: { NEXT_PUBLIC_CB_ENVIRONMENT: 'dev' },
164-
}
165-
})
161+
162+
await mockModule('@codebuff/common/env', () => ({
163+
env: { NEXT_PUBLIC_CB_ENVIRONMENT: 'test' },
164+
}))
166165

167166
// Call real getConfigDir to verify it includes '-dev'
168167
const configDir = authModule.getConfigDir()
169-
expect(configDir).toContain('manicode-dev')
170-
expect(configDir).not.toContain('manicode/')
171-
expect(configDir).not.toBe(path.join(os.homedir(), '.config', 'manicode'))
168+
expect(configDir).toEqual(
169+
path.join(os.homedir(), '.config', 'manicode-test'),
170+
)
172171
})
173172

174-
test('should use manicode directory in production environment', () => {
173+
test('should use manicode-dev directory in development environment', async () => {
174+
// Restore getConfigDir to use real implementation for this test
175+
mock.restore()
176+
177+
await mockModule('@codebuff/common/env', () => ({
178+
env: { NEXT_PUBLIC_CB_ENVIRONMENT: 'dev' },
179+
}))
180+
181+
// Call real getConfigDir to verify it includes '-dev'
182+
const configDir = authModule.getConfigDir()
183+
expect(configDir).toEqual(
184+
path.join(os.homedir(), '.config', 'manicode-dev'),
185+
)
186+
})
187+
188+
test('should use manicode directory in production environment', async () => {
175189
// Restore getConfigDir to use real implementation
176190
mock.restore()
177191

178192
// Set environment to prod (or unset it)
179-
mockModule('@codebuff/common/env', () => {
180-
return {
181-
env: { NEXT_PUBLIC_CB_ENVIRONMENT: 'prod' },
182-
}
183-
})
193+
await mockModule('@codebuff/common/env', () => ({
194+
env: { NEXT_PUBLIC_CB_ENVIRONMENT: 'prod' },
195+
}))
184196

185197
// Call real getConfigDir to verify it doesn't include '-dev'
186198
const configDir = authModule.getConfigDir()
187-
expect(configDir).toBe(path.join(os.homedir(), '.config', 'manicode'))
188-
expect(configDir).not.toContain('manicode-dev')
199+
expect(configDir).toEqual(path.join(os.homedir(), '.config', 'manicode'))
189200
})
190201

191202
test('should allow credentials to persist across simulated CLI restarts', () => {

cli/src/utils/auth.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ export const getConfigDir = (): string => {
3535
'.config',
3636
'manicode' +
3737
// on a development stack?
38-
(env.NEXT_PUBLIC_CB_ENVIRONMENT &&
39-
env.NEXT_PUBLIC_CB_ENVIRONMENT !== 'prod'
38+
(env.NEXT_PUBLIC_CB_ENVIRONMENT !== 'prod'
4039
? `-${env.NEXT_PUBLIC_CB_ENVIRONMENT}`
4140
: ''),
4241
)

0 commit comments

Comments
 (0)