Skip to content

Commit 29bfcc5

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(quickbooks): require explicit API environment
1 parent 33d9afb commit 29bfcc5

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

apps/sim/.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ API_ENCRYPTION_KEY=your_api_encryption_key # Use `openssl rand -hex 32` to gener
112112
# TIKTOK_CLIENT_ID=
113113
# TIKTOK_CLIENT_SECRET=
114114

115+
# QuickBooks Online OAuth (Optional - credentials from the Intuit Developer Portal)
116+
# QUICKBOOKS_CLIENT_ID=
117+
# QUICKBOOKS_CLIENT_SECRET=
118+
# QUICKBOOKS_ENV=sandbox # Required when QuickBooks is configured: sandbox or production
119+
115120
# Azure Blob Storage takes precedence over S3 if both are configured
116121
# AZURE_ACCOUNT_NAME= # Azure storage account name
117122
# AZURE_ACCOUNT_KEY= # Azure storage account key

apps/sim/lib/oauth/quickbooks.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { afterEach, describe, expect, it, vi } from 'vitest'
1+
import { resetEnvMock, setEnv } from '@sim/testing'
2+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
23
import {
34
createQuickBooksAccountId,
45
fetchQuickBooksConnectionProfile,
@@ -12,8 +13,13 @@ import { QUICKBOOKS_MAX_USER_INFO_BYTES } from '@/lib/quickbooks/client'
1213
const TEST_UUID = '01234567-89ab-4def-8abc-0123456789ab'
1314
const originalFetch = global.fetch
1415

16+
beforeEach(() => {
17+
setEnv({ QUICKBOOKS_ENV: 'sandbox' })
18+
})
19+
1520
afterEach(() => {
1621
global.fetch = originalFetch
22+
resetEnvMock()
1723
})
1824

1925
describe('QuickBooks account identity', () => {

apps/sim/lib/quickbooks/client.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ export const QUICKBOOKS_MAX_USER_INFO_BYTES = 1024 * 1024
1212
export type QuickBooksEnvironment = 'sandbox' | 'production'
1313

1414
export function getQuickBooksEnvironment(): QuickBooksEnvironment {
15-
const value = env.QUICKBOOKS_ENV ?? 'sandbox'
15+
const value = env.QUICKBOOKS_ENV
16+
if (!value) {
17+
throw new Error(
18+
'QUICKBOOKS_ENV must be explicitly configured as either "sandbox" or "production"'
19+
)
20+
}
1621
if (value !== 'sandbox' && value !== 'production') {
1722
throw new Error('QUICKBOOKS_ENV must be either "sandbox" or "production"')
1823
}

apps/sim/tools/quickbooks/quickbooks.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ describe('QuickBooks request construction', () => {
4141
)
4242
})
4343

44-
it('defaults to sandbox and rejects an invalid environment at the API boundary', () => {
44+
it('requires an explicit valid environment at the API boundary', () => {
4545
setEnv({ QUICKBOOKS_ENV: undefined })
46-
expect(getQuickBooksEnvironment()).toBe('sandbox')
46+
expect(() => getQuickBooksEnvironment()).toThrow(
47+
'QUICKBOOKS_ENV must be explicitly configured as either "sandbox" or "production"'
48+
)
4749

4850
setEnv({ QUICKBOOKS_ENV: 'staging' })
4951
expect(() => getQuickBooksEnvironment()).toThrow(

0 commit comments

Comments
 (0)