Skip to content

Commit b233de5

Browse files
committed
Fix lint error in privacy policy unit test
1 parent 5f2aed5 commit b233de5

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/integrations/PrivacyPolicyVersion/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { execSync } from 'node:child_process'
1818
import type { AstroIntegration } from 'astro'
19+
import { getOptionalEnv } from '../../lib/config/environmentServer'
1920

2021
const PRIVACY_POLICY_PATH = 'src/pages/privacy/index.astro'
2122

@@ -54,7 +55,8 @@ function getPrivacyPolicyVersionFromGit(filePath: string): string | null {
5455
* Resolve privacy policy version using env, git metadata, or current date fallback.
5556
*/
5657
export function resolvePrivacyPolicyVersion(): string {
57-
const envVersion = process.env.PRIVACY_POLICY_VERSION?.trim()
58+
const rawEnvVersion = getOptionalEnv('PRIVACY_POLICY_VERSION')
59+
const envVersion = typeof rawEnvVersion === 'string' ? rawEnvVersion.trim() : ''
5860
if (envVersion) {
5961
console.log(`✅ Privacy policy version sourced from env: ${envVersion}`)
6062
return envVersion

src/lib/config/environmentServer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ export function getSentryAuthToken(): string {
6666
}
6767
return token
6868
}
69+
70+
export const getOptionalEnv = (key: string): string | undefined => {
71+
return process.env[key]
72+
}

test/unit/integrations/privacy-policy-version.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,32 @@ vi.mock('node:child_process', () => ({
44
execSync: vi.fn(),
55
}))
66

7+
vi.mock('../../../src/lib/config/environmentServer', () => ({
8+
getOptionalEnv: vi.fn(),
9+
}))
10+
711
import { execSync } from 'node:child_process'
812

13+
import { getOptionalEnv } from '../../../src/lib/config/environmentServer'
914
import { resolvePrivacyPolicyVersion } from '../../../src/integrations/PrivacyPolicyVersion/index'
1015

1116
describe('resolvePrivacyPolicyVersion', () => {
1217
afterEach(() => {
1318
vi.restoreAllMocks()
14-
vi.unstubAllEnvs()
19+
vi.clearAllMocks()
1520
vi.useRealTimers()
1621
})
1722

1823
it('returns PRIVACY_POLICY_VERSION when provided', () => {
19-
vi.stubEnv('PRIVACY_POLICY_VERSION', '2024-01-02')
24+
vi.mocked(getOptionalEnv).mockReturnValueOnce('2024-01-02')
2025
const version = resolvePrivacyPolicyVersion()
2126

2227
expect(version).toBe('2024-01-02')
2328
expect(execSync).not.toHaveBeenCalled()
2429
})
2530

2631
it('falls back to git metadata when env var is absent', () => {
32+
vi.mocked(getOptionalEnv).mockReturnValueOnce(undefined)
2733
vi.mocked(execSync).mockReturnValue('2023-05-05\n' as never)
2834

2935
const version = resolvePrivacyPolicyVersion()
@@ -32,6 +38,7 @@ describe('resolvePrivacyPolicyVersion', () => {
3238
})
3339

3440
it('falls back to the current date when git is unavailable', () => {
41+
vi.mocked(getOptionalEnv).mockReturnValueOnce(undefined)
3542
vi.useFakeTimers()
3643
vi.setSystemTime(new Date('2025-12-06T12:00:00Z'))
3744
vi.mocked(execSync).mockImplementation(() => {

0 commit comments

Comments
 (0)