Skip to content

Commit f27c40f

Browse files
committed
chore: update mock env for failing tests
1 parent 38aab1e commit f27c40f

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

apps/sim/lib/email/unsubscribe.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {
66
verifyUnsubscribeToken,
77
} from './unsubscribe'
88

9-
vi.stubEnv('BETTER_AUTH_SECRET', 'test-secret-key')
9+
vi.mock('../env', () => ({
10+
env: {
11+
BETTER_AUTH_SECRET: 'test-secret-key',
12+
},
13+
}))
1014

1115
describe('unsubscribe utilities', () => {
1216
const testEmail = 'test@example.com'
@@ -75,10 +79,9 @@ describe('unsubscribe utilities', () => {
7579
it.concurrent('should handle legacy tokens (2 parts) and default to marketing', () => {
7680
// Generate a real legacy token using the actual hashing logic to ensure backward compatibility
7781
const salt = 'abc123'
82+
const secret = 'test-secret-key'
7883
const { createHash } = require('crypto')
79-
const hash = createHash('sha256')
80-
.update(`${testEmail}:${salt}:${process.env.BETTER_AUTH_SECRET}`)
81-
.digest('hex')
84+
const hash = createHash('sha256').update(`${testEmail}:${salt}:${secret}`).digest('hex')
8285
const legacyToken = `${salt}:${hash}`
8386

8487
// This should return valid since we're using the actual legacy format properly

apps/sim/lib/subscription/utils.test.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
1+
import { describe, expect, it, vi } from 'vitest'
22
import { calculateUsageLimit, checkEnterprisePlan } from './utils'
33

4-
const ORIGINAL_ENV = { ...process.env }
5-
6-
beforeAll(() => {
7-
process.env.FREE_TIER_COST_LIMIT = '5'
8-
process.env.PRO_TIER_COST_LIMIT = '20'
9-
process.env.TEAM_TIER_COST_LIMIT = '40'
10-
process.env.ENTERPRISE_TIER_COST_LIMIT = '200'
11-
})
12-
13-
afterAll(() => {
14-
process.env = ORIGINAL_ENV
15-
})
4+
vi.mock('../env', () => ({
5+
env: {
6+
FREE_TIER_COST_LIMIT: 5,
7+
PRO_TIER_COST_LIMIT: 20,
8+
TEAM_TIER_COST_LIMIT: 40,
9+
ENTERPRISE_TIER_COST_LIMIT: 200,
10+
},
11+
}))
1612

1713
describe('Subscription Utilities', () => {
1814
describe('checkEnterprisePlan', () => {

0 commit comments

Comments
 (0)