diff options
Diffstat (limited to 'packages/core/src/code_assist/setup.test.ts')
| -rw-r--r-- | packages/core/src/code_assist/setup.test.ts | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/packages/core/src/code_assist/setup.test.ts b/packages/core/src/code_assist/setup.test.ts index cba051dd..61a7431a 100644 --- a/packages/core/src/code_assist/setup.test.ts +++ b/packages/core/src/code_assist/setup.test.ts @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { setupUser, ProjectIdRequiredError } from './setup.js'; import { CodeAssistServer } from '../code_assist/server.js'; import { OAuth2Client } from 'google-auth-library'; @@ -50,8 +50,12 @@ describe('setupUser for existing user', () => { ); }); + afterEach(() => { + vi.unstubAllEnvs(); + }); + it('should use GOOGLE_CLOUD_PROJECT when set and project from server is undefined', async () => { - process.env.GOOGLE_CLOUD_PROJECT = 'test-project'; + vi.stubEnv('GOOGLE_CLOUD_PROJECT', 'test-project'); mockLoad.mockResolvedValue({ currentTier: mockPaidTier, }); @@ -66,7 +70,7 @@ describe('setupUser for existing user', () => { }); it('should ignore GOOGLE_CLOUD_PROJECT when project from server is set', async () => { - process.env.GOOGLE_CLOUD_PROJECT = 'test-project'; + vi.stubEnv('GOOGLE_CLOUD_PROJECT', 'test-project'); mockLoad.mockResolvedValue({ cloudaicompanionProject: 'server-project', currentTier: mockPaidTier, @@ -86,7 +90,7 @@ describe('setupUser for existing user', () => { }); it('should throw ProjectIdRequiredError when no project ID is available', async () => { - delete process.env.GOOGLE_CLOUD_PROJECT; + vi.stubEnv('GOOGLE_CLOUD_PROJECT', ''); // And the server itself requires a project ID internally vi.mocked(CodeAssistServer).mockImplementation(() => { throw new ProjectIdRequiredError(); @@ -122,8 +126,12 @@ describe('setupUser for new user', () => { ); }); + afterEach(() => { + vi.unstubAllEnvs(); + }); + it('should use GOOGLE_CLOUD_PROJECT when set and onboard a new paid user', async () => { - process.env.GOOGLE_CLOUD_PROJECT = 'test-project'; + vi.stubEnv('GOOGLE_CLOUD_PROJECT', 'test-project'); mockLoad.mockResolvedValue({ allowedTiers: [mockPaidTier], }); @@ -153,7 +161,7 @@ describe('setupUser for new user', () => { }); it('should onboard a new free user when GOOGLE_CLOUD_PROJECT is not set', async () => { - delete process.env.GOOGLE_CLOUD_PROJECT; + vi.stubEnv('GOOGLE_CLOUD_PROJECT', ''); mockLoad.mockResolvedValue({ allowedTiers: [mockFreeTier], }); @@ -182,7 +190,7 @@ describe('setupUser for new user', () => { }); it('should use GOOGLE_CLOUD_PROJECT when onboard response has no project ID', async () => { - process.env.GOOGLE_CLOUD_PROJECT = 'test-project'; + vi.stubEnv('GOOGLE_CLOUD_PROJECT', 'test-project'); mockLoad.mockResolvedValue({ allowedTiers: [mockPaidTier], }); @@ -200,7 +208,7 @@ describe('setupUser for new user', () => { }); it('should throw ProjectIdRequiredError when no project ID is available', async () => { - delete process.env.GOOGLE_CLOUD_PROJECT; + vi.stubEnv('GOOGLE_CLOUD_PROJECT', ''); mockLoad.mockResolvedValue({ allowedTiers: [mockPaidTier], }); |
